Created
November 4, 2021 14:46
-
-
Save enjoy-digital/c32c679a9ee4429d7f38a5ca5016a45a to your computer and use it in GitHub Desktop.
WS2812/NeoPixel LiteX core test over Bridge.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import time | |
from litex import RemoteClient | |
bus = RemoteClient() | |
bus.open() | |
# # # | |
class NeoPixelLed: | |
def __init__(self, n): | |
self.n = n | |
def write(self, r, g, b): | |
bus.write(bus.mems.ws2812.base + 4*self.n, (g << 16) | (r << 8) | (b << 0)) | |
leds = [NeoPixelLed(i) for i in range(64)] | |
import random | |
prng = random.Random(42) | |
while True: | |
for n in range(64): | |
rand = prng.randrange(100) | |
# Blue Flashes. | |
if rand > 98: | |
leds[n].write(r=0, g=0, b=prng.randrange(2**8)) | |
# Blue Randomness. | |
elif rand > 40: | |
leds[n].write(r=0, g=0, b=prng.randrange(2**2)) | |
else: | |
leds[n].write(r=0, g=0, b=0) | |
time.sleep(0.001) | |
# # # | |
bus.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment