Go Down

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

EminB

When I try to check my code I get that error please help me .


Code: [Select]
 

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

int 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)

 
}



}











CrossRoads

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 11


int 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

I remade my code :::::

#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

You to be able to say AND, written as && e.g.

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

Steve

EminB

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 am Last 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

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