09 Random APA Pixel Color

Random Color LED Pixels

// Turn the rainbow LED pixels a different random color each time you press a button #include "LEDStrip.h" //The LEDStrip.h library gives your code access to special functions exclusive to the LED Pixels LEDStrip pixels = LEDStrip(4, 13, 12); //Set up the pixels by defining how many pixels and which pins of the microchip are used (always 13 and 12 on a Transformer) void setup() { pinMode(6,INPUT_PULLUP); //button } void loop() { if(digitalRead(6)==LOW){ //if button 6 is pressed... pixels.setPixel(pixels.ALL,random(0,300)); //Set all of the pixels to a random color including 0-299 pixels.draw(); //send the setPixel data to be displayed delay(250); //delay 250 milliseconds so the 'if' statement isn't checked again before you release the button } } // (c) 2024 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
 

Walkthrough Video

Watch the video for a line-by-line explanation of how the example program works. Then you'll be ready to make some changes of your own!

 

LED Pixel Color Spectrum


Use this spectrum to estimate the color values you'll need for your 'setPixel' arguments to achieve your favorite color!


Challenges

Can you complete the challenges? Change the code in your code editor above. Upload your code to see the effect when you're finished. Complete a challenge? Check it off the list!


TRANSFORMERS and HASBRO and all related trademarks and logos are trademarks of Hasbro, Inc. ©2024 Hasbro.