Me and my 11 year old built a little project with an rgb led and a button. We're looking for a sketch to run it that will fade through all the colors and when it's at a color my son likes, he can press the button and freeze it on that color (its a night light).
Has anyone seen one out there? Trying to jump start his interest in learning how to code with something cool like this.
Thanks, looks like this needs MOFSETS. I've gotten the fading to work without them but i'm looking for a sketch that'll stop on a certain color with a button press. I'm surprised there's not an existing sketch out there. Thanks again!
You are welcome; I agree with you. Your project is simple, and a wonderful idea that I don't know why there isnt a sketch out there!
I will try to work on writing one, but I am only 13 and new to arduino, so I might run into some problems...I will try my best! Good luck on your project.
Reading the state of a switch is pretty simple - digitalRead(). Wiring a switch is pretty simple - connect one leg to ground and one leg to a digital pin, and enable the pullup resistor (digitalWrite(somePin, HIGH);).
Fading until the switch state changes to LOW is simple. Fade inside a if block:
if(fade)
{
// Do the fading stuff
}
Defining fade as a boolean is trivial. Setting it to true initially is easy. Setting it to false when the switch is pressed is easy.