Hi
Thanks for taking a look.
I have an Arduino 2560, two L298N boards and two momentary switches all connected up, I think I have just made some kind of simple error in the code.
Basically when I push the first button, I want all four motor connected to the two L298N boards to move the motors in the open louvres direction for 15 seconds. When I push the second button close the louvres.
When I push the buttons nothing happens.
Buttons are connected to 5v and one to digital pin 50 the other digital pin 51, no external resistor is being used just INPUT_PULLUP.
5v-----switch-----switch
\ --------pin 51
-------pin 50
I wired both switches from a single 5v pin because I have run out of 5v pins.
I did basic testing before adding in the buttons and the Arduino was sending the right signals to the L298N boards, as I could see the LEDs lighting properly and measure the voltage on the motor outputs.
The sketch verifies and uploads.
Thanks again.
Richard
// motor A
int AIN1=30;
int AIN2=31;
int AENA=42;
// motor B
int BIN1=32;
int BIN2=33;
int BENA=43;
// motor C
int CIN1=34;
int CIN2=35;
int CENA=44;
// motor D
int DIN1=36;
int DIN2=37;
int DENA=45;
// switches
int OPEN=50;
int CLOSE=51;
void setup()
{
// set all pins
pinMode(AIN1,OUTPUT);
pinMode(AIN2,OUTPUT);
pinMode(AENA,OUTPUT);
pinMode(BIN1,OUTPUT);
pinMode(BIN2,OUTPUT);
pinMode(BENA,OUTPUT);
pinMode(CIN1,OUTPUT);
pinMode(CIN2,OUTPUT);
pinMode(CENA,OUTPUT);
pinMode(DIN1,OUTPUT);
pinMode(DIN2,OUTPUT);
pinMode(DENA,OUTPUT);
pinMode(OPEN,INPUT_PULLUP);
pinMode(CLOSE,INPUT_PULLUP);
}
void louvre_command(int mode) {
switch(mode) {
case 1:
// close louvre
digitalWrite(AENA,HIGH);// motor A enable
digitalWrite(AIN1,LOW);// rotate back
digitalWrite(AIN2,HIGH);
digitalWrite(BENA,HIGH);// motor B enable
digitalWrite(BIN1,LOW);// rotate back
digitalWrite(BIN2,HIGH);
digitalWrite(CENA,HIGH);// motor C enable
digitalWrite(CIN1,LOW);// rotate back
digitalWrite(CIN2,HIGH);
digitalWrite(DENA,HIGH);// motor D enable
digitalWrite(DIN1,LOW);// rotate back
digitalWrite(DIN2,HIGH);
delay(15000);
break;
case 2:
// open louvre
digitalWrite(AENA,HIGH);// motor A enable
digitalWrite(AIN1,HIGH);// rotate forward
digitalWrite(AIN2,LOW);
digitalWrite(BENA,HIGH);// motor B enable
digitalWrite(BIN1,HIGH);// rotate forward
digitalWrite(BIN2,LOW);
digitalWrite(CENA,HIGH);// motor C enable
digitalWrite(CIN1,HIGH);// rotate forward
digitalWrite(CIN2,LOW);
digitalWrite(DENA,HIGH);// motor D enable
digitalWrite(DIN1,HIGH);// rotate forward
digitalWrite(DIN2,LOW);
delay(15000);
break;
}
}
void loop() {
// Getting data from the buttons
int open_press = digitalRead(OPEN);
int close_press = digitalRead(CLOSE);
// the logic
if(open_press == LOW && close_press == HIGH) {
louvre_command(2);
}
if(open_press == HIGH && close_press == LOW) {
louvre_command(1);
}
if(open_press == LOW && close_press == LOW) {
// Do nothing....
// louvre_command(0);
}
if(open_press == HIGH && close_press == HIGH) {
// Do nothing....
// louvre_command(0);
}
delay(500);
}