Module 10: Create Your Badge

The Knob on the Y-Badge

The knob is a device known as a potentiometer. We send a voltage through it and measure how much of that voltage is allowed to pass through, based on the position of the knob. This allows us to return a value based on the current position of the knob using the Yboard.get_knob() function.

Functions

We can use the value returned from the Yboard.get_knob() function to change the brightness of the LEDs on our board. This is the code:

while(true) {
    int brightness = 255 * Yboard.get_knob() / 100;
    Yboard.set_led_brightness(brightness);

    // Then use Yboard.set_led_color() as normal inside this loop.
}
More Details

You’ll notice that we’ve multiplied the value of Yboard.get_knob() by 255 and divided it by 100. The reason is because Yboard.set_led_brightness() needs a brightness between 0 and 255, but Yboard.get_knob() gives us a value between 0 and 100. We can scale our value from Yboard.get_knob() to a value that Yboard.set_led_brightness() will understand by multiplying it by the maximum value of our brightness function and dividing by the maximum value of our knob function.

Notice also that we are monitoring the value of Yboard.get_knob() continuously by placing it inside an infinite while loop.

There are other things you can try to control with Yboard.get_knob() (for example, you could use it to change the color of LEDs rather than brightness) but brightness is the easiest. Feel free to experiment with it!

Design Your Own Y-Badge

Now it’s your turn to customize your badge. Write code to make it your own. You could make it into a three-key piano, display a spectacular light show, or anything else. The possibilities are endless! Just be sure to put all the skills you’ve learned to good use!

Remember to change main.cpp before continuing…

📝 NOTE: You will need to go to main.cpp and change the comments to call the correct activity function:

// conditionals_activity();
badge_activity();