I assume you still want the flashing to happen but the STEADY state for 5 seconds should be based on the button press? That is how I interpret your code.
Can you explain what you are seeing with the current software? It’s always a good idea to post what is happening rather than a “it doesn’t work” post.
It could be that the button is generating multiple signals to the interrupt as they bounce. You may need a delay of around 10-50ms where you don’t read any other changes on the pin. A timer is the ideal way to handle this. Don’t put any delay in the interrupt handler itself.
i’ve created a new one, but this time the button (with press and hold) now works but the LED is not blinking. It just turn on all the way and one thing, how can i reduce the brightness of the LED because its too bright.
byte SWITCHPIN= D0; //Set Pin 2 as Switch
byte LEDPIN = A0; //Set Pin 6 as LED
//If you want to go higher than 255 you must change from "byte" to "int"
boolean buttonstate; //Create a Integer variable named buttonstate
pinMode(SWITCHPIN, INPUT); //Set Pin 2 as Input
pinMode(LEDPIN, OUTPUT); //Set Pin 6 as Output
buttonstate = digitalRead(SWITCHPIN); //Continually look at the switch to see if its pressed
if (buttonstate == HIGH) //If the switch goes HIGH, act on it
this does not work
//Once the switch is pressed again we break out of the loop above and then break out of the function completely and go back to our main loop
buttonstate = LOW; //First we tell the micro the switch is now LOW
analogWrite(LEDPIN, 0); //We turn the LED off before leaving our custom function
This does not make sense. digitalWrite() takes LOW (0) or HIGH (anything else but 0) and not OUTPUT.
Additionally how should anything blink, when you set the LED to the same value on all three occasions? So I guess the code works as you have written it, you just expect it to do something you have NOT told it to do.
Have you had a look at your own code before you posted this?!?
This does not achieve anything, since the next time round loop() you’ll read the actual buttonstate - no matter what story you try to tell the micro.
Please read the docs, do some research, search the forum and apply what you find out properly.