I want to make program with two push buttons a“gas” and “brake”button. The“gas”button should speed up the blinking rate of the LED, and the “brake” button should slow it down. Why my program doesn`t work.
This is my code:
const int kPinButtonGas = 5;
const int kPinButtonBreak = 3;
const int kPinLed=9;
void setup() {
pinMode(kPinButtonGas, INPUT);
pinMode(kPinButtonBreak, INPUT);
pinMode(kPinLed, OUTPUT);
digitalWrite(kPinButtonGas, HIGH);
digitalWrite(kPinButtonBreak, HIGH);
}
int delayTime=1000;
long lastTime =0;
int ledState = LOW;
void loop() {
if(digitalRead(kPinButtonGas) == LOW){
delayTime=delayTime --;
}
else if(digitalRead(kPinButtonBreak)==LOW){
delayTime=delayTime ++;
}
delayTime = constrain(delayTime, 10, 5000);
if((lastTime + delayTime)<millis()){
if(ledState ==LOW){
ledState =HIGH;
}
else{
ledState=LOW;
}
digitalWrite(kPinLed, ledState);
lastTime = millis();
}
delay(100);
}