Go Down

Topic: sensing the floor? (Read 341 times) previous topic - next topic

Marduk

Im working on a robot that i added a 2 IR sensor that put out a HIGH when there is no floor and a LOW when there is a floor. now i been trying to work out a way to write  this code so that when one of the sensor go HIGH
i want to send out a halt to stop the robot from falling over the edge.

Quote

int Floorsen_a = 12;
int Floorsen_b = 13;

void setup()
{
 pinMode(Floorsen_a, INPUT);
 pinMode(Floorsen_b, INPUT);
}

void loop ()
// rember that floor is safe when input = low
{
 int right = digitalRead(Floorsen_a);
 int left  = digitalRead(Floorsen_b);
 int Floor_Safe = right + left;
 Floor_Safe != 1
}
 


But that as far as i can get. right now im working this as if it is on its own but in the end out come it will be ruining as a function

any help would be great or idea. thank you.

johnwasser

So if there is no floor (HIGH) on either the left or the right you want to stop.

Code: [Select]

   if (digitalRead(Floorsen_a) || digitalRead(Floorsen_b)) {
       // Stop!
   }


The '||' is a logical OR operator. 
If either read returns a non-zero value (like HIGH which is 1) the OR results in 'true'.
If both reads return zero (like LOW which is 0) the OR results in 'false'.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Marduk


Go Up