// TAMEGA328 CI 1 const int M1L = 0; // Input Motor 1, LEFT const int M1R = 1; // Input Motor 1, RIGHT const int M2L = 2; // Input Motor 2, LEFT const int M2R = 3; // Input Motor 2, RIGHT const int M3L = 4; // Input Motor 3, LEFT const int M3R = 5; // Input Motor 3, RIGHT // // TAMEGA328 CI 2 // //const int M4L = 0; // Input Motor 4, LEFT //const int M4R = 1; // Input Motor 4, RIGHT // //const int M5L = 2; // Input Motor 5, LEFT //const int M5R = 3; // Input Motor 5, RIGHT // //const int M6L = 4; // Input Motor 6, LEFT //const int M6R = 5; // Input Motor 6, RIGHT // TAMEGA328 CI 1 const int Ea = 10; // Enable A for L298 CI 1 const int Eb = 9; // Enable B for L298 CI 1 const int Ea2 = 11; // Enable A for L298 CI 2 int BUFFER; int POT = A0; // Input speed motor set in the code to be from 50% to 100% int PWM = 0; int MAX = 256; // Input speed motor set to 100% int DELAY = 1;// Input delay low speed motor void setup() { pinMode(M1L, INPUT); pinMode(M1R, INPUT); pinMode(M2L, INPUT); pinMode(M2R, INPUT); pinMode(M3L, INPUT); pinMode(M3R, INPUT); pinMode(Ea, OUTPUT); pinMode(Eb, OUTPUT); pinMode(POT, INPUT); } void loop() { int buttonState_M1L = 0; // current state of the INPUT int buttonState_M1R = 0; // current state of the INPUT int buttonState_M2L = 0; // current state of the INPUT int buttonState_M2R = 0; // current state of the INPUT int buttonState_M3L = 0; // current state of the INPUT int buttonState_M3R = 0; // current state of the INPUT buttonState_M1L = digitalRead(M1L); // read the pushbutton input M1L buttonState_M1R = digitalRead(M1R); // read the pushbutton input M1R buttonState_M2L = digitalRead(M2L); // read the pushbutton input M2L buttonState_M2R = digitalRead(M2R); // read the pushbutton input M2R buttonState_M3L = digitalRead(M3L); // read the pushbutton input M3L buttonState_M3R = digitalRead(M3R); // read the pushbutton input M3R BUFFER = analogRead(POT); PWM = 256-(BUFFER/8); // speed motor set to be from 50% to 100% // 1 TAMEGA328 CI 1 for M1L if (buttonState_M1L == HIGH) { analogWrite(Ea, PWM); delay (DELAY); analogWrite(MAX, PWM); } else { analogWrite(M1L, 0); } // 2 TAMEGA328 CI 1 for M1R if (buttonState_M1R == HIGH) { analogWrite(Ea, PWM); delay (DELAY); analogWrite(MAX, PWM); } else { analogWrite(M1R, 0); } // 3 TAMEGA328 CI 1 for M2L if (buttonState_M2L == HIGH) { analogWrite(Eb, PWM); delay (DELAY); analogWrite(MAX, PWM); } else { analogWrite(M2L, 0); } // 4 TAMEGA328 CI 1 for M2R if (buttonState_M1L == HIGH) { analogWrite(Eb, PWM); delay (DELAY); analogWrite(MAX, PWM); } else { analogWrite(M2R, 0); } // 5 TAMEGA328 CI 1 for M3L if (buttonState_M3L == HIGH) { analogWrite(Ea2, PWM); delay (DELAY); analogWrite(MAX, PWM); } else { analogWrite(M3L, 0); } // 6 TAMEGA328 CI 1 for M3R if (buttonState_M3R == HIGH) { analogWrite(Ea2, PWM); delay (DELAY); analogWrite(MAX, PWM); } else { analogWrite(M3R, 0); } // Delay a little bit to avoid bouncing delay(50); }