const int buttonR = 2; // Pin for the "R" limit switch
const int buttonL = 4; // Pin for the "L" limit switch
const int m_R = 8; // Pin for the "M_R" motor
const int m_L = 7; // Pin for the "M_L" motor
int stateMR = LOW; // Variable to store the state of "M_R" motor
int stateML = LOW; // Variable to store the state of "M_L" motor
int buttonRState = 0; // Variable to store the state of the "R" button
int buttonLState = 0; // Variable to store the state of the "L" button
int lastButtonRState = 0; // Variable to store the previous state of the "R" button
int lastButtonLState = 0; // Variable to store the previous state of the "L" button
void setup() {
pinMode(buttonR, INPUT);
pinMode(buttonL, INPUT);
pinMode(m_R, OUTPUT);
pinMode(m_L, OUTPUT);
}
void loop() {
buttonRState = digitalRead(buttonR);
buttonLState = digitalRead(buttonL);
// Check if the "R" button is pressed and released
if (buttonRState == HIGH && lastButtonRState == LOW) {
// Toggle the state of "M_L" motor
stateML = !stateML;
// Turn off "M_R" motor
digitalWrite(m_R, LOW);
delay(1000);
// Set the state of "M_L" motor
digitalWrite(m_L, stateML);
}
// Check if the "L" button is pressed and released
if (buttonLState == HIGH && lastButtonLState == LOW) {
// Toggle the state of "M_R" motor
stateMR = !stateMR;
// Turn off "M_L" motor
digitalWrite(m_L, LOW);
delay(1000);
// Set the state of "M_R" motor
digitalWrite(m_R, stateMR);
}
lastButtonRState = buttonRState;
lastButtonLState = buttonLState;
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
btn1:1.l
btn1:2.l
btn1:1.r
btn1:2.r
btn2:1.l
btn2:2.l
btn2:1.r
btn2:2.r
led1:A
led1:C
led2:A
led2:C