'F' → Fullscreen
Create a new MicroPython program named 2-6-led-array.
With the USB cable unplugged, keep Activity 2.4's three channels and build two more the same way, continuing the row to the right:
| Part | Red LED (pin 31) | Yellow LED (pin 32) |
|---|---|---|
| Wire from the RedBoard | GPIO 31 → a25 | GPIO 32 → a28 |
| LED (long leg first) | e25, e26 | e28, e29 |
| Resistor | a26 → top − rail | a29 → top − rail |
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:
The order on the board has to match the order in the list. Every animation walks the list from leds[0] to leds[4], so that is the path the light appears to travel: left to right along the row, 28 to 32. The header runs the other way, so the wires cross over each other on their way to the board. If your chase looks like it is jumping around instead of traveling, the wiring order does not match the list order — the code is probably fine.
Pin objects in one list named leds.for loop, to prove all five are wired correctly. All five should light. If one doesn't, fix its channel before you go on.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)Each LED is the only one lit for 0.1 s, in list order, so one light travels the whole path in half a second:
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.