'F' → Fullscreen
Create a new MicroPython program named 2-6-led-array.
Pin objects in one list named leds.for loop, to prove all five are wired correctly.The two new pins sit immediately to the left of 30 in the same block on the top header, so the five you need run 32, 31, 30, 29, 28 reading left to right:
Plug them in physically left to right in list order. The order the LEDs sit in your breadboard is the order the animation appears to move. If your chase looks like it is jumping around instead of sweeping, the wiring order does not match the list order — the code is probably fine.
from machine import Pinimport time
leds = [ Pin(28, Pin.OUT), Pin(29, Pin.OUT), Pin(30, Pin.OUT), Pin(31, Pin.OUT), Pin(32, Pin.OUT),]
for led in leds: led.value(1)from machine import Pinimport time
leds = [ Pin(28, Pin.OUT), Pin(29, Pin.OUT), Pin(30, Pin.OUT), Pin(31, Pin.OUT), Pin(32, Pin.OUT),]
for led in leds: led.value(1) time.sleep(0.1) led.value(0)all_off(leds), which turns every LED off.chase(leds, wait).fill(leds, wait), where each LED stays lit as the next joins — then clears.from machine import Pinimport time
leds = [ Pin(28, Pin.OUT), Pin(29, Pin.OUT), Pin(30, Pin.OUT), Pin(31, Pin.OUT), Pin(32, Pin.OUT),]
def all_off(leds): for led in leds: led.value(0)
def chase(leds, wait): for led in leds: led.value(1) time.sleep(wait) led.value(0)
def fill(leds, wait): for led in leds: led.value(1) time.sleep(wait) all_off(leds)
chase(leds, 0.1)fill(leds, 0.2)all_on(leds) to match all_off(leds).blink_all(leds, wait, times) that flashes the whole row a given number of times — by calling all_on() and all_off(), not by touching pins directly.from machine import Pinimport time
leds = [ Pin(28, Pin.OUT), Pin(29, Pin.OUT), Pin(30, Pin.OUT), Pin(31, Pin.OUT), Pin(32, Pin.OUT),]
def all_on(leds): for led in leds: led.value(1)
def all_off(leds): for led in leds: led.value(0)
def chase(leds, wait): for led in leds: led.value(1) time.sleep(wait) led.value(0)
def fill(leds, wait): for led in leds: led.value(1) time.sleep(wait) all_off(leds)
def blink_all(leds, wait, times): for i in range(times): all_on(leds) time.sleep(wait) all_off(leds) time.sleep(wait)
chase(leds, 0.1)fill(leds, 0.2)blink_all(leds, 0.2, 5)while pattern you used for the task-list app in Activity 1.20.q, turning every LED off on the way out.from machine import Pinimport time
leds = [ Pin(28, Pin.OUT), Pin(29, Pin.OUT), Pin(30, Pin.OUT), Pin(31, Pin.OUT), Pin(32, Pin.OUT),]
def all_on(leds): for led in leds: led.value(1)
def all_off(leds): for led in leds: led.value(0)
def chase(leds, wait): for led in leds: led.value(1) time.sleep(wait) led.value(0)
def fill(leds, wait): for led in leds: led.value(1) time.sleep(wait) all_off(leds)
def blink_all(leds, wait, times): for i in range(times): all_on(leds) time.sleep(wait) all_off(leds) time.sleep(wait)
all_off(leds)
running = Truewhile running: print() print("1 - Chase") print("2 - Fill") print("3 - Blink All") print("q - Quit") choice = input("Pick an animation: ")
if choice == "1": chase(leds, 0.1) elif choice == "2": fill(leds, 0.2) elif choice == "3": blink_all(leds, 0.2, 5) elif choice == "q": running = False else: print("Not an option.")
all_off(leds)print("Goodbye.")for led in leds: — look at leds[0] and leds[4] on the circuit diagram above.When you run your script:
q should turn every LED off and end the programAnswer the following questions before submitting your work.
Pin objects in a list let you do that five separate variables would not?blink_all() never calls .value() itself. Explain what it does instead, and why that is easier to read than turning five pins on and off inside it.chase() and fill() functions contain almost the same loop. What single difference makes one look like a moving light and the other look like a bar filling up?Submit the required files to the appropriate dropbox.