Arrch:
while (buttonState1 == HIGH){
go = HIGH;
}
Once the buttonState1 goes HIGH, this will get stuck in an infinite loop as buttonState1 will never change. I doubt that is your intention.
if((currentMillis - previousMillis > interval) && (go = HIGH)){
go = HIGH assigns the value of HIGH to go and return HIGH, which would evaluate to true
go == HIGH will return true if go is HIGH, otherwise, it will return false.
Here is my new code after referring to your comment.
const int ledPin = 13; // the number of the LED pin
int input1 = 2; //INPUT PINS
// Variables will change:
int ledState = LOW; // ledState used to set the LED
int buttonState1 = input1; // variable for reading the rotary switch status
boolean go = LOW;
long previousMillis = 0; // will store last time LED was updated
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 1000; // interval at which to blink (milliseconds)
void setup() {
// set the digital pin as output:
pinMode(ledPin, OUTPUT);
pinMode(input1, INPUT);
}
void loop()
{
buttonState1 = digitalRead(input1); // blink frequency 1000 if on
while (buttonState1 == HIGH){
go = HIGH;
// check to see if it's time to blink the LED; that is, if the
// difference between the current time and last time you blinked
// the LED is bigger than the interval at which you want to
// blink the LED.
unsigned long currentMillis = millis();
if((currentMillis - previousMillis > interval) && (go == HIGH)){
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
}
}
}
At the beginning, when I press and hold down the button, the LED starts blinking as I wanted, but when I release the button, it still blinks.
What could be the problem ?