Go Down

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


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.


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.


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


Go Up

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.

shortcuts: alt+s submit/post or alt+p preview