# PassingColors
# Reference: https://wokwi.com/projects/384675870918916097
# by xfpd: https://wokwi.com/makers/xfpd
import time
from neopixel import Neopixel
import led_transform
PIN = 13
NUMPIXELS = 28 # NeoPixel ring size
pixDELAY = 10 # Delay for pixel persistence
pixels = Neopixel(64, 0, PIN, "GRB")
GRN_Base = (NUMPIXELS // 4)
BLU_Base = (NUMPIXELS // 2)
YEL_Base = ((NUMPIXELS * 3) // 4)
def collide():
global i
# RED pixel follows the counter (at the bottom of this function)
RED = i
# GREEN pixel starts at 1/4 (.25) position on the ring
GRN = GRN_Base - i
if (GRN < 0) :
GRN = NUMPIXELS + GRN
# BLUE pixels starts at 1/2 (.5) position on the ring
BLU = BLU_Base + i
if (BLU > NUMPIXELS - 1):
BLU = BLU - NUMPIXELS
# YELLOW pixel starts at 3/4 (.75) position on the ring
YEL = YEL_Base - i
if (YEL < 0):
YEL = abs(NUMPIXELS + YEL)
print("RED %5d | GRN %5d | BLU %5d | YEL %5d" %(RED, GRN, BLU, YEL))
pixels.set_pixel((led_transform.display1(RED+1))-1, (255, 0, 0))
pixels.set_pixel((led_transform.display1(GRN+1))-1, (0, 255, 0))
pixels.set_pixel((led_transform.display1(BLU+1))-1, (0, 0, 255))
pixels.set_pixel((led_transform.display1(YEL+1))-1, (255, 255, 0))
pixels.show()
time.sleep_ms(pixDELAY)
# BLACK-out the trailing colored pixel
pixels.fill((0, 0, 0))
pixels.show() # show the black-out
if (i < (NUMPIXELS-1)):
i = i + 1
else:
i = 0
# Start Function
if __name__ == '__main__':
i=0 # counter
while True:
collide()