The LED Display
There are 2 RGB LEDs on the mCore. RGB stands for Red-Green-Blue and LED stands for Light-Emitting Diode. Each LED can be assigned a level of red light, a level of green light and a level of blue light from 0 (light turned off) to 255 (light turned on full power). By combining these lights, you can make a wide range of different colors:
To get playing with the on-board LEDs, I need to drag and drop this block:
The first drop-down menu gives me a choice of which on-board LED I want to control. On the mBot, I have 3 choices:
I want to control all the LEDs so I am going to select “all”. The other 3 drop-downs allow you to control how bright the LED displays the relevant color. It gives you options of 0, 20, 60, 150 and 255, but if none of those are good for you, you can also type in the value you want. I am going to set my LED’s red value to 35 and click the block to see the LEDs light up.
It might be fun to have the robot flashing light like a police car, going from red to blue and back again. I would like this to go on forever. Fortunately, there is a “Forever” block in the “Control” Scripts:
As you can see, the shape of this block is different to the shape of the other blocks we have seen so far. That is because this is a control block that allows the program to enter a loop. In programming, a loop is a feature that allows a part of code to be repeated. In this example, the loop is going to repeat forever, repeating all the blocks that are inside the “forever loop”:
The LEDs will be set to red, then blue. Then the program will go back to the top of the loop, and the LEDs will be set to red again, then blue, then loop, etc, etc, forever. That is good…. But the lights change color far too quick. I am going to slow them down by adding a “Wait” block:
Notice that I need 2 wait blocks – one after the red LED is turned on, and one at the bottom of the loop, where the blue LED is turned on.
- Play with different settings of the LEDS. What different colors can you make? What settings of the RGB LED creates these colors?
- Can you write a program that sets the left LED and the right LED at different times to your favorite color? So if the right LED is on the left LED is off, and vice-versa.
- Can you write a program that gives a light show that is accompanied with music? Remember to add comments
Construct Your Dreams!