Jewelbots Tutorials Lesson 5: Turning all the LEDs on and off

Laura & Louisa
2 min readJan 23, 2017

--

In the last lesson we learned how to blink a single LED using the LED class’ turn_off_single function and the Timer class’ pause function. Now let’s see how to turn all of the LEDs on and off at once!

Luckily for us, there are functions for this. They are appropriately named turn_on_all and turn_off_all. When you use these functions, you don’t have to specify an LED position, because you’re turning on (or turning off) all the LEDs on the Jewelbot.

In order to turn on all of the lights on your Jewelbot in a particular color, simply run

led.turn_on_all(COLOR_OF_LED);

Just like with turn_on_single, you don’t actually write COLOR_OF_LED — you replace that with the color (“RED”, “GREEN”, “BLUE”, “YELLOW”, “MAGENTA”, “CYAN”, or “WHITE”) you want the LEDs to turn on in. To turn off all LEDs, run

led.turn_off_all();

Notice that the turn_off_all function doesn’t take in a position or a color! This makes sense — we’re turning off all the LEDs so there’s no need to specify a position, and we don’t need a color specified to turn off an LED.

Putting it all together, if we want to turn on all of the LEDs in green, turn off all the LEDs one second later, pause for another second, and continue through this cycle, our code would look something like this:

void setup() {
// put your setup code here, to run once:
}void loop() {
// put your main code here, to run repeatedly:
LED led;
Timer timer;
led.turn_on_all(GREEN);
timer.pause(1000);
led.turn_off_all();
timer.pause(1000);
}

We can also use turn_off_all if just one, two or three of the four lights are turned on.

Great! In the next lesson we’ll talk about flash_single and flash_all, functions that make an LED turn on and off once for a brief amount of time.

--

--