(Exercise) Code Homework no.01
Homework Questions
Make sure that you upload each code example to the respective area in the spreadsheet. Create a separate .py for each exercise. Please make the files are named clearly, they need at least, your name, the #, and the exercise number so something like “SantiagoBenjamin__WU01__E01.py” would be something I might name my files, but you’re not obligated to use this exact syntax.
-
Make all neopixels light up red.
-
Make all neopixels light up green.
-
Make all neopixels light up blue.
-
Make neopixels #7 and #1 light up a color that looks like purple or pink. (note that this is not a trick question that I am assuming the first neopixel is #0 and the last one would be #9)
-
Write a piece of code that does the following:
- Make all the neopixels light up a color of your choice
- wait a little bit
- turn all the lights off
- wait a little bit
- light up all the neopixels another arbitrary color
- wait a little bit
- then turn them off again
- and then wait.
-
The code below doesn’t work properly, make it work correctly (note that all the neopixels should light up in sequence). Add a comment (# in front of the line to write a human language comment) about what line was causing the issue and another comment identifying what you did to fix it.
from adafruit_circuitplayground import cp
import time
while True:
cp.pixels[1] = (255,255,255)
time.sleep(0.1)
cp.pixels.fill((0,0,0))
cp.pixels[2] = (255,255,255)
time.sleep(0.1)
cp.pixels.fill((0,0,0))
cp.pixels[3] = (255,255,255)
time.sleep(0.1)
cp.pixels.fill((0,0,0))
cp.pixels[4] = (255,255,255)
time.sleep(0.1)
cp.pixels.fill((0,0,0))
cp.pixels[5] = (255,255,255)
time.sleep(0.1)
cp.pixels.fill((0,0,0))
cp.pixels[6] = (255,255,255)
time.sleep(0.1)
cp.pixels.fill((0,0,0))
cp.pixels[7] = (255,255,255)
time.sleep(0.1)
cp.pixels.fill((0,0,0))
cp.pixels[8] = (255,255,255)
time.sleep(0.1)
cp.pixels.fill((0,0,0))
cp.pixels[9] = (255,255,255)
time.sleep(0.1)
cp.pixels.fill((0,0,0))
cp.pixels[10] = (255,255,255)
time.sleep(0.1)
cp.pixels.fill((0,0,0))
-
Write code that does the following:
- Make neopixel #0 light up a color that looks like yellow or orange
- wait
- turn neopixel #0 off
- wait
- light up neopixel #4 a color that looks like sky blue
- wait
- turn neopixel #4 off
- wait
- and then light up neopixel #9 a color that looks like pink
- wait
- then turn neopixel #9 off
- wait
-
Make each neopixel light up in sequence (0 -9) any color you want and then turn off in reverse sequence. (note that this is also not a trick question, you are welcome to use for loops, but not expected to)