control rgb with momenary switch

Hello,
I have been searching on the forums and I cant find how to go about programming an rgb led to control it with a momentary switch.. The momentary switch is normally open and I am thinking I want to power on the led by holding the button for 3 seconds, power off the led by holding button for 3 seconds and switch between colors by pressing the button twice.

Alright, what have you tried so far? Do you know how to read a switch? Do you know how to drive the led (which you don't give any info on). Best approach, baby steps!

The led is rgb with each a positive and negative wire and I have programmed the led to blink and change colors. I'm not sure how the switch works.. I know I will have to debounce the switch and use 3000 milliseconds to count for the press and hold for 3 seconds for the led to turn on and do the same to turn it off. The 2 button press in a time limit will also to used to change the color. So in all the coding of the button press is what I'll need help on.

Then start by looking examples for that :slight_smile:

Three tips though

  1. Make life easy and grab a library like Bounce2*
  2. Understand the difference between a button that IS pressed and one that BECAME pressed (state change, Bounce2 has it build in)
  3. Use millis() to keep track of the time. See "Blink without delay" and "Several things at the same time"
  • Yes, learning what it does is even better but you can do that in the process :wink: