(Exercise) Code Homework no.02
Intstructions
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 sure that each of your code examples has comments!
Questions
- Make all neopixels “glow” white (smoothly turn on and then off, showing all values from 0 - 255, then 255 - 0)
- Turn each EVEN pixel on and off in sequence (zero is even), then turn each ODD pixel on and off in sequence. It should look like this:
- Make all the neopixels “glow” blue and then “glow” red. This again, means the colors must smoothly traverse all values. So you'd want to see the values change in this way:
- (0,0,0) ← off
- smooth transition
- (0,0,255) ← on, blue
- smooth transition
- (0,0,0) ← back to off
- smooth transition
- (255,0,0) ← on, red
- smooth transition
- (0,0,0) off again
- The following code will break, fix it so that it will loop continually.▼
# our imports
# -----------------------------------------
from adafruit_circuitplayground import cp
import time
# -----------------------------------------
# MAIN LOOP
# -----------------------------------------
while True:
# go upward through EACH of the neopixels
for i in range(0, 9, 1):
cp.pixels[i] = (255, 255, 255)
time.sleep(0.1)
cp.pixels[i] = (0, 0, 0)
# go down through EACH of the neopixels
for i in range(9, 0, 1):
cp.pixels[i] = (255, 255, 255)
time.sleep(0.1)
cp.pixels[i] = (0, 0, 0)
# -----------------------------------------
- Make each neopixel quickly “glow” white in sequence. To be clear each individual neopixel will go:
- (0,0,0)
- smooth transition
- (255,255,255)
- smooth transition
- (0,0,0)
It should look like this:
BONUS CHALLENGE!
Make the CPX do the following, light up each pixel in sequence such that starts “pink” (255, 10, 255) and then gradually becomes “teal” (0, 255, 10) and then turns off. Then lights each pixel in sequence but starts “teal” and becomes “pink”. It should look like this: