I want to increase the TimeOff variable with the push of a button (Plus), but it doesnt seem to work. I think it has to do with storing the new value of the variable but i'm not sure.
const int Start = 8;
const int Stop = 9;
const int Relais = 7;
const int Plus = 6;
int Startstate = 0;
int Stopstate = 0;
int Plusstate = 0;
unsigned long previousMillis = 0; // will store last time LED was updated
long OnTime = 250; // milliseconds of on-time
long OffTime = 1000; // milliseconds of off-time
boolean Blinkstate = false;
int ledState = LOW;
unsigned long currentTime = 0;
// Integers and Booleans. (don't mind Button 3, it's for a future expansion.
void setup() {
// Set inputs & outputs.
pinMode(Start, INPUT);
pinMode(Stop, INPUT);
pinMode(Relais, OUTPUT);
pinMode(Plus, INPUT);
}
void loop() {
// Read the state of the pushbutton values:
Startstate = digitalRead(Start);
Stopstate = digitalRead(Stop);
Plusstate = digitalRead(Plus);
digitalWrite(Relais, LOW);
// check if the start button is pressed. If it is, the startstate is HIGH:
if (Plusstate == HIGH) {
OffTime = OffTime + 5000;//when this button is pressed,
}
if (Startstate == HIGH && Stopstate == LOW ) {
Blinkstate = true;
} // set blinkstate active
while (Blinkstate == true)
knipper(); // when Blinkstate is true, perform the blinkFunction.
}
void knipper() {
unsigned long currentMillis = millis();
if ((ledState == HIGH) && (currentMillis - previousMillis >= OnTime))
{
ledState = LOW; // Turn it off
previousMillis = currentMillis; // Remember the time
digitalWrite(Relais, ledState); // Update the actual LED
}
else if ((ledState == LOW) && (currentMillis - previousMillis >= OffTime))
{
ledState = HIGH; // turn it on
previousMillis = currentMillis; // Remember the time
digitalWrite(Relais, ledState); // Update the actual LED
}
Stopstate = digitalRead(Stop);
if (Stopstate == HIGH) {
loop();
}
}