Go Down

### Topic: expected primary-expression before ">" token (Read 132 times)previous topic - next topic

#### EminB

##### Aug 21, 2019, 09:43 pm

Code: [Select]
`  #define echoPin 7#define trigPin 4#define red 8#define green 11int maximumRange = 50;int minimumRange = 0;void setup() {  pinMode(trigPin, OUTPUT);  pinMode(echoPin, INPUT);  pinMode(green, OUTPUT);   pinMode(red, OUTPUT);}void loop() {}int mesafe(int maxrange, int minrange){  long duration, distance;  digitalWrite(trigPin,LOW);  delayMicroseconds(2);  digitalWrite(trigPin, HIGH);  delayMicroseconds(10);  digitalWrite(trigPin, LOW);  duration = pulseIn(echoPin, HIGH);  distance = (duration/2) / 29.1;  delay(50);  if(distance <= 70  || distance => 40 )    [b]// THATS THE ERROR LINE [/b]  digitalWrite(red, HIGH)}    else{digitalWrite(red, LOW)   }if(distance <= 40  || distance => 10)  digitalWrite(green, HIGH)else{digitalWrite(green, LOW)  }}`

#1
##### Aug 21, 2019, 10:28 pm
You have => vs >=
Also missing some ;s
and { } with the if () statements

Code: [Select]
`#define echoPin 7#define trigPin 4#define red 8#define green 11int maximumRange = 50;int minimumRange = 0;void setup() {  pinMode(trigPin, OUTPUT);  pinMode(echoPin, INPUT);  pinMode(green, OUTPUT);  pinMode(red, OUTPUT);}void loop() {}int mesafe(int maxrange, int minrange){  long duration, distance;  digitalWrite(trigPin, LOW);  delayMicroseconds(2);  digitalWrite(trigPin, HIGH);  delayMicroseconds(10);  digitalWrite(trigPin, LOW);  duration = pulseIn(echoPin, HIGH);  distance = (duration / 2) / 29.1;  delay(50);  if  (distance <= 70  || distance >= 40 ) {  // THATS THE ERROR LINE    digitalWrite(red, HIGH);  }  else {    digitalWrite(red, LOW);  }  if (distance <= 40  || distance >= 10) {    digitalWrite(green, HIGH);  }  else {    digitalWrite(green, LOW);  }}`
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

#### EminB

#2
##### Aug 22, 2019, 01:24 pm

#define echoPin 7
#define trigPin 4
#define red 8
#define green 11

void setup() {
Serial.begin (9600);

pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(green, OUTPUT);
pinMode(red, OUTPUT);

}

void loop() {

long duration, distance;

digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);
distance = (duration/2) /29.1;

if  (distance <= 70   ) {
digitalWrite(red, HIGH);
}

else {
digitalWrite(red, LOW);
}

if (distance <= 40  ) {
digitalWrite(green, HIGH);
}
else {
digitalWrite(green, LOW);
}
}

but I want to do that  :::          red led active when distance between 70 and 40

green led active when distance between 40 and 5

How can I do that  ?

#### slipstick

#3
##### Aug 22, 2019, 02:25 pm
You to be able to say AND, written as && e.g.

if (distance >=5 && distance <= 40) {set green on} etc

Steve

#### EminB

#4
##### Aug 22, 2019, 09:22 pm
thanks but I see tht like if ( distance <=70 || distance >= 40)

It didnt give any syntax error but It doesn't worked . Do you know thats why ?

#### sterretje

#5
##### Aug 23, 2019, 08:00 amLast Edit: Aug 23, 2019, 08:02 am by sterretje
thanks but I see tht like if ( distance <=70 || distance >= 40)

It didnt give any syntax error but It doesn't worked . Do you know thats why ?
That condition will always be true; distance 0 .. 70 or distance 40 .. inf

PS. This is not an Installation and troubleshooting question; I will ask a moderator to move it.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

#### slipstick

#6
##### Aug 23, 2019, 10:37 am
thanks but I see tht like if ( distance <=70 || distance >= 40)

It didnt give any syntax error but It doesn't worked . Do you know thats why ?
Because when I said AND && I didn't mean OR ||. The distance is always less than 70 OR greater than 40. But it's not always greater than 40 AND less than 70.

Steve

Go Up