I am trying to get something to work so that an RGB LED fades through the color spectrum, and when a button is pressed some music plays. That is not the problem. Assume I am using any loop that functions can be called at any time in. I am trying to make it so that if the button is not pressed for a certain amount of time, say 30 seconds, the light stops fading through the color spectrum and when the button is pressed in this 'sleep mode', first the light starts fading, and then the next press plays the music. I am aware this could be done somehow with millis();, but how would I approach this? I am using an Arduino Uno.

  • 1
    If it is working now as you want it. Please consider accepting the answer that helped you in order to indicate to others that this issue has been resolved. Thank you for your cooperation to make this forum better.
    – Dat Ha
    Jun 15 '17 at 19:40

Here is a little snippet of logic that you can implement in your code :

if(millis() - getOutOfSleepTime >= 30000) {
    getOutOfSleepTime = millis();


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.