Hey. Have been searching for the answers but cannot find it...
The thing i want to make is to blink a led that is on digital 10 and it needs to be in diffrent speeds blinking where for example...
A 30 min program where the first 10 minutes it is blinking on x speed and 10 minutes that it is blinking z speed. The thing is that i need a program thats going to run if a button on lets say d2 is HIGH. I think what i am after is "while" but cannot really get this.
const int trigger = 2;
const int ledPin = 10;
boolean ledState = LOW;
boolean previousButtonState = HIGH;
boolean buttonState = LOW;
boolean serialCheck = LOW;
long duration = 0;
unsigned long previousMillis = 0;
// constants won't change :
const long interval = 4000;
void setup()
{
Serial.begin(9600);
// set the digital pin as output:
pinMode(ledPin, OUTPUT);
pinMode(trigger,INPUT);
}
void loop()
{
unsigned long currentMillis = millis();
if(currentMillis - previousMillis >= interval && buttonState == HIGH )
{
previousMillis = currentMillis;
// Serial.println(buttonState);
// if(buttonState == HIGH)
// {
if (ledState == LOW)
{
ledState = HIGH;
Serial.println("led set high");
}
else
{
ledState = LOW;
}
// }
if (millis() >= duration)
{
Serial.println("duration completed");
previousButtonState = buttonState;
buttonState = LOW;
ledState = LOW;
}
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
}
if(digitalRead(trigger) == HIGH)
{
if(previousButtonState == HIGH)
{
Serial.println("pressed");
// Serial.println(currentMillis);
buttonState = HIGH;
}
else
{
buttonState = LOW;
}
delay(150); //debouncing
duration = millis() + 180000; //Tiden Blinket kör
}
}[