08 Tune LED Eye Color

Tune Optimus Prime's Eye Color

/* Change the color of the rainbow pixels with the turn knob */ #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(A0,INPUT); //set the turn knob as an INPUT. Its range is 0-1023 } void loop() { if(analogRead(A0)>700){ //if the turn knob is turned higher than 700... pixels.setPixel(pixels.All,299); //set all of the LED pixels to 299 color (blue) } else if(analogRead(A0)>350){ //otherwise, if the turn knob is turned between 350 and 700... pixels.setPixel(pixels.All,200); //set all of the LED pixels to 200 (green) } else{ //otherwise, if the turn knob is turned somewhere below 350 pixels.setPixel(pixels.All,100); //set all of the LED pixels to 100 (red) } pixels.draw(); //send the color value to the LED pixels, depending on which statement is true } //(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.