Hi, Everyone I am B.S.S.SRIKAR
recently I was making a project
which will move backward when we will move close to it, just like a runner or don't come near me robot:grinning:
So here my problem is saying expected primary-expression before token
My Code:
int M1a = 5;
int M2a = 6;
int sensor1 = 7;
int sensor2 = 8;
void setup()
{
// put your setup code here, to run once:
}
void loop()
{
// put your main code here, to run repeatedly:
if (digitalRead(sensor1) = HIGH)
digitalWrite(M1a,HIGH);
if (digitalRead(sensor2) = HIGH))
digitalWrite(M2a,HIGH);
This compiles. See comments. I fixed errors and omissions pointed out previously by the other members plus the original error (extra parenthesis).
int M1a = 5;
int M2a = 6;
int sensor1 = 7;
int sensor2 = 8;
void setup()
{
// put your setup code here, to run once:
pinMode(M1a, OUTPUT); // *************** added
pinMode(M2a, OUTPUT); // *************** added
}
void loop()
{
// put your main code here, to run repeatedly:
if (digitalRead(sensor1) == HIGH) // ***** ==
digitalWrite(M1a, HIGH);
if (digitalRead(sensor2) == HIGH) // ***** == and remove extra )
digitalWrite(M2a, HIGH);
else
{ // *************** added
digitalWrite(M1a, LOW);
digitalWrite(M2a, LOW);
}
} // ****** added
Read the forum guidelines. Post your test code in code tags. Use the IDE autoformat tool (ctrl-t or Tools, Auto Format) to indent the code for readability before posting code.
@er_name_not_found Yes I tried it too before creating a topic on Arduino Forum,
int M1a = 5;
int M2a = 6;
int sensor1 = 7;
int sensor2 = 8;
pinMode(M1a,OUTPUT);
pinMode(M2a,OUTPUT);
pinMode(sensor1,INPUT);
pinMode(sensor2,INPUT);
void setup()
{
// put your setup code here, to run once:
}
void loop()
{
// put your main code here, to run repeatedly:
if (digitalRead(sensor1) == HIGH)
digitalWrite(M1a,HIGH);
if (digitalRead(sensor2) == HIGH))
digitalWrite(M2a,HIGH);
else
digitalWrite(M1a,LOW);
digitalWrite(M2a,LOW);
}
but it said
'Expected Constructor, Destructor or type conversion before '(' token'
so I removed it