Difference between revisions of "Random for loop"

From Interaction Station Wiki
Jump to navigation Jump to search
(Created page with "======'''Neopixels for loops'''====== <syntaxhighlight lang="Python" > import time import random from adafruit_circuitplayground import cp cp.pixels.brightness=0.3 while Tru...")
 
 
Line 1: Line 1:
======'''Neopixels for loops'''======
+
 
  
 
<syntaxhighlight lang="Python" >
 
<syntaxhighlight lang="Python" >

Latest revision as of 12:22, 3 September 2024


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)