LED Strip Brightness & Color Tuner
Step 1 - Build the Project
Use button A5 to update the color value of the LED strip. Use button 2 to update the brightness of the LED strip.
Step 2 - Upload the Code
Step 3 - Read the Walkthrough
The LED Strip library is a separate file of code. It contains functions and methods that are specific to controlling a strip of LEDs. To use the library, you use the #include statement. Then, you have to give the library some information, similar to setting pinMode() for components.
First, create an integer variable called numPixels. Its value should be equal to the number of LEDs on your strip.
To tell the LED Strip library (already included in your program) the name & attributes of your LED Strip, you create an object. In this case, the object is called ‘strip’ and it has ‘numPixel’ pixels, the data pin is number 13, and the clock pin is number 12 on your carrier board.
The variable called color refers to a value -1 to 300.
Your other variable is brightness. It’s the percentage brightness for the strip.
In the setup() of the code, set both the color tuning button and the brightness tuning button to INPUT_PULLUP pin modes. When you are pressing the button down, it will send a LOW signal to that pin.
In the loop, use the first if statement so check if the A5 button is pressed. If it is, update the color value. This looks tricky, but it’s actually a useful tool called modulo. You know that the value of color can only reach 300. Imagine color is equal to 300. 300+1 = 301. 301/300 is 1 with a remainder of 1. So in this case, the color value now updates to 1. Next time through the loop, color will update to 2. 2/300 is 0 with a remainder of 2, so that color is not modified by the modulo.
Next, check the status of the brightness button. If it is pressed, update brightness using the same modulo method you used for color.
This loop is repeating very quickly. Each time through the loop, the color value can only update by 1. But the amount of time it takes to complete the color cycle is under 10 seconds.