1. Engineering
  2. Computer Science
  3. hi i want to add another pushbutton to control the...

Question: hi i want to add another pushbutton to control the...

Question details
Hi, I want to add another pushbutton to control the speed of the motor to make it go faster on pin 4 how can i do that? This is arduino on tinkercad

int pinButton = 8;
int LED = 2;
int stateLED = LOW;
int stateButton;
int previous = LOW;
long time = 0;
long debounce = 200;

void setup() {
  pinMode(pinButton, INPUT);
  pinMode(LED, OUTPUT);
}

void loop() {
  stateButton = digitalRead(pinButton);  
  if(stateButton == HIGH && previous == LOW && millis() - time > debounce) {
    if(stateLED == HIGH){
      stateLED = LOW; 
    } else {
       stateLED = HIGH; 
    }
    time = millis();
  }
  digitalWrite(LED, stateLED);
  previous == stateButton;
}
Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution