Pages: [1]   Go Down
Author Topic: sensing the floor?  (Read 280 times)
0 Members and 1 Guest are viewing this topic.
Miami,FL
Offline Offline
Newbie
*
Karma: 0
Posts: 30
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8856
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
   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'.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Miami,FL
Offline Offline
Newbie
*
Karma: 0
Posts: 30
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

WOW! thank man
Logged

Pages: [1]   Go Up
Jump to: