# PassingColors
# Reference: https://wokwi.com/projects/384675870918916097
# by xfpd: https://wokwi.com/makers/xfpd
from machine import Pin
import time
import neopixel
import led_transform
ws_pin = 13
NUMPIXELS = 28 # NeoPixel ring size
pixDELAY = 100 # Delay for pixel persistence
GRN_Base = (NUMPIXELS // 4)
BLU_Base = (NUMPIXELS // 2)
YEL_Base = ((NUMPIXELS * 3) // 4)
def collide_8x8():
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[(led_transform.display1(RED+1))-1]= (255, 0, 0)
pixels[(led_transform.display1(GRN+1))-1]= (0, 255, 0)
pixels[(led_transform.display1(BLU+1))-1]= (0, 0, 255)
pixels[(led_transform.display1(YEL+1))-1]= (255, 255, 0)
pixels.write()
time.sleep_ms(pixDELAY)
# BLACK-out the trailing colored pixel
pixels.fill((0, 0, 0))
pixels.write() # show the black-out
if (i < (NUMPIXELS-1)):
i = i + 1
else:
i = 0
# Start Function
if __name__ == '__main__':
pixels = neopixel.NeoPixel(Pin(ws_pin), 64)
i=0 # counter
while True:
collide_8x8()