There are 20 LEDs on the Y-Badge circuit board.
- Each LED is labeled LED1 to LED20.
- Each of these LEDs are RGB (red-green-blue) LEDs, meaning that they are actually three smaller red, green, and blue lights packaged together. For each LED, you can set the brightness of the red, green, and blue lights individually, making the LED appear to be any color you like.
Functions
To make things happen on the Y-badge, you will need to call functions from your code. A function is a set of instructions that a computer can follow to perform a specific task. Functions are very useful because they allow programmers to write code that can be reused multiple times in a program.
The function to set an LED color looks like this:
Yboard.set_led_color(<LED number>, <red>, <green>, <blue>);
- The
<LED number>
can be any value from 1 to 20. - The
red
,green
, andblue
values represent the brightness of that color and can be any value from 0 to 255.
Examples
To make LED3 display bright red, you should use this statement in your code (don’t forget to add the semicolon):
Yboard.set_led_color(3, 255, 0, 0);
To make LED15 display bright yellow, you should turn on the red and green pixels to max brightness:
Yboard.set_led_color(15, 255, 255, 0);
Add the example code to your own to test it out. Don’t forget to click “upload” in the top right corner dropdown to program your board with new code!
Exploration
-
Pick an LED of your choice and turn it on.
-
What happens if you use 255, 255, 255 for your RGB values?
-
What happens if you use 0, 0, 0 for your RGB values?
-
Figure out the RGB value for your favorite color by using the
Yboard.set_led_color
.
Challenges
Remember to comment out the led_exploration();
call in the led_activity
function and uncomment the correct challenge function:
// led_exploration();
led_challenge1();
// led_challenge2();
// led_challenge3();
Challenge 1: Turn on LEDs 1, 13, and 17. Make them 3 different colors.
Challenge 2: Make one of the LEDs orange.
Challenge 3: Turn on all of the LEDs with a progression between colors, starting with pure red and going to pure blue.