Random for loop

From Interaction Station Wiki
Revision as of 12:22, 3 September 2024 by WangN (talk | contribs) (→‎Neopixels for loops)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


import time
import random
from adafruit_circuitplayground import cp
cp.pixels.brightness=0.3

while True:

    for x in range (0,12):
      
        for j in range (0,10,1):
            print(j)
            cp.pixels[j]=(255,j*20,0)
            time.sleep(0.2)
            cp.pixels[j]=(0,0,0)
        for j in range (9,-1,-1):
            print(j)
            cp.pixels[j]=(random.randint(0,255),random.randint(0,255),random.randint(0,255))
            time.sleep(0.5)
            #cp.pixels[j]=(0,0,0)
        time.sleep(0.5)