I have a lot of trouble with this message...what s wrong with this code...I received this error "expected unqualified-id before numeric constant" in sixth line of below code..when it comes to definition PB2
L298_Part2.ino (1.23 KB)
I have a lot of trouble with this message...what s wrong with this code...I received this error "expected unqualified-id before numeric constant" in sixth line of below code..when it comes to definition PB2
L298_Part2.ino (1.23 KB)
Please insert your code in the post using code tags; it's small enough.
This is OP's code
//L298 Channel A
int IN1 = 7; // IN1 L298 ==> pin 7 Arduino
int IN2 = 8; // IN2 ==> Pin8
int ENA = 9; // Enable A ==> Pin9 PWM
int PB1 = 11; // Push button 1 ==> Pin 11 Arduino
const int PB2 = 12; // Push button 2 ==> pin 12
int MotorSpeed = 0;
void setup(){
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(ENA, OUTPUT);
pinMode(PB1, INPUT_PULLUP); // Default = HIGH
pinMode(PB2, INPUT_PULLUP);
analogWrite(ENA, 0);
}
void loop(){
while ( (digitalRead(PB1) == HIGH) && (digitalRead(PB2) == HIGH) ){
MotorSpeed = 0;
}
boolean PB1P = digitalRead(PB1); // PB1P = Push button 1 Pressed
boolean PB2P = digitalRead(PB2);
if( PB1P == LOW){
// Forward
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
if( MotorSpeed < 255){
MotorSpeed +=5;
analogWrite(ENA,MotorSpeed);
delay(100);
}
else {
MotorSpeed = 255;
analogWrite(ENA, MotorSpeed);
}
}
else if( PB2P == LOW){
// Reverse
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
if( MotorSpeed < 255){
MotorSpeed +=5;
analogWrite(ENA,MotorSpeed);
delay(100);
}
else {
MotorSpeed = 255;
analogWrite(ENA, MotorSpeed);
}
}
}
PB1 and PB2 are names that are used by Arduino so you can't 'redefine' them. Renaming them to e.g. PBx1 and PBx2 will solve your issue.
PS
This is not an installation and troubleshooting question; I will suggest to the moderator sto move it to a more appropriate section.
Thanks a lot..the program shows no syntax error...but in hardware this program cannot run...I am sure that connectors and wires has been linked correctly...what do u suggest?
what do u suggest?
Posting the circuit diagram and details of the hardware for a start
aria2a:
Thanks a lot..the program shows no syntax error...but in hardware this program cannot run...I am sure that connectors and wires has been linked correctly...what do u suggest?
I suggest that you tell us what your serial print statements are telling you is happening.
OK. Why don't you?