Hello me, a fellow student, and a teacher are making a robot, but one of our wheels keep glitching out whenever add delays to the code. we've also been trying to use a switch but it wont read it when we press the switch.
Thank you to anyone who answers this...
Heres the code...
int BUTTON2 = 0;
const int BUTTON=2;
boolean lastButton = LOW;
boolean currentButton = LOW;
boolean ledOn = false;void setup() {
//Setup Channel A
pinMode(12, OUTPUT); //Initiates Motor Channel A pin
pinMode(9, OUTPUT); //Initiates Brake Channel A pin
pinMode(13, OUTPUT);
pinMode(8, OUTPUT);
pinMode(2, INPUT);
}
boolean debounce (boolean last)
{
boolean current = digitalRead(BUTTON);
if (last != current)
{
delay(5);
current = digitalRead(BUTTON);
}
return current;
}
void loop(){
currentButton = debounce (lastButton);
if (lastButton == LOW && currentButton == HIGH)
//forward @ full speed
digitalWrite(12, HIGH); //Establishes forward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
analogWrite(3, 255); //Spins the motor on Channel A at full speed
delay(200);
digitalWrite(13, HIGH);
digitalWrite(8, LOW);
analogWrite(11, 255);
delay(200);
if (BUTTON2 = HIGH){
digitalWrite(12, LOW);
digitalWrite(9, LOW);
analogWrite(11, 255);
delay(200);
digitalWrite(13, LOW);
digitalWrite(8, LOW);
analogWrite(11, 255);
delay(200);
}
else (BUTTON2 = LOW); {
digitalWrite(12, HIGH);
digitalWrite(9, LOW);
analogWrite(11, 255);
delay(200);
digitalWrite(13, HIGH);
digitalWrite(8, LOW);
analogWrite(11, 255);
delay(200);
}
}