Lights & Colors 2 & 3

Lesson (25 mins):

Classroom Code / Project:  Light LED Pattern

Equipment:  (1 for each Trainee) 

Skills

Keywords

In Game Application

Part 1: 

Flashing LED Strip

One of the neat things about addressable LEDs is we can “animate” them. In other words, by changing the colors of the LEDs or turning them off and on really fast, we give the impression that the lights are moving.

Some examples:

https://learn.adafruit.com/cheerlights-led-animations

https://learn.adafruit.com/circuitpython-feather-ble-neopixel-hat


We’re going to start by making the LED strip flash for our first animation.


Facilitator guides the students through “Flash LED Strip” Project:


Explanation of the code:


You can put whatever you want in the “Forever” block, and it will keep repeating that. Try changing the colors and the length of the pauses to get different flashing patterns. You can even make it change more than just on and off!

Student Activity

Students should try modifying the code to show their own flashing patterns. Note that they can change the timing, the color, and always add more blocks to cycle between more colors, as in the example below.

Part 2

Controlling individual LEDs as Ranges

One of the great things about addressable LEDs is that every LED in the strip can be controlled independently. That means we can light up the LED strip in different designs by telling it what color each LED should be, and whether it should be on or off.


Neopixels let you define a range of LEDs and set those however you want. In the example below, I’ve set the first 5 LEDs to red. (Note that when you count the LEDs on the strip, it starts from 0, which is why it says to start the range from 0. Then it’ll count 5 LEDs from zero and define that as the range).

“Set range” doesn’t actually turn the LEDs on yet -- it just gives the instructions for what color that range of LEDs will need to be. To actually show those colors, you have to include a “show” block at the end.

What happens if you want to define two ranges? Say you want the first 5 pixels to be red, but the second 5 to be yellow? 


We can create two ranges -- “Range1” and “Range2”. That way, we can tell the micro:bit what colors we want each range to show.

Student Activity

Students should try modifying the code to make their own patterns. They should try to add as many ranges and colors as they want, and they can even combine it with Part 1 to make their patterns flash.

Lesson (25 mins):

Demonstration Code: (For Part 2) : Flash LED Strip 2

Classroom Code/Project: Flash LED Strip

Equipment:  (1 for each Trainee) 

Skills

Keywords

In Game Application

Flashing LED Strip

We’re going to start by making the LED strip flash for our first animation.

Facilitator guides the students through “Flash LED Strip” Project: Flash LED Strip


Explanation of the code:

Other animations:

You can put whatever you want in the “Forever” block, and it will keep repeating that. Try changing the colors and the length of the pauses to get different flashing patterns. You can even make it change more than just on and off. For instance, what happens if I try the code below?

You can also combine it with what we learned previously about lighting up individual LEDs and ranges, like in the example below: https://makecode.microbit.org/_UhfJMk14wAKJ