Boolean Problem

Hi guys,

I’m having problems with my program at the moment.
I’m building a robot, and I’ll try to make clear what the function of the robot must be, otherwise you won’t understand my problem.

You can see it as the following. I have 2 sensors on both side of a box, and the robot will move alongside the box. The program of my robot must begin working after it has passed the second sensor, because when it’s next to the box it will destroy itself when working.

So when the robot starts, it passes the first sensor(SensorValue2), and it must not work.
Therefore, I put in a boolean ‘veilig’ as we call safe in dutch.
When it passes SensorValue2, the boolean has to be set ‘false’, it must not work.

Then it passes the second sensor (Sensorvalue3) and as you can see, when the boolean is set ‘false’ and it passes the second sensor, the programm knows the robot was next to the box, but right now it isn’'t. Because it can see that the robot is moving from sensor 2 to 3.

Therefore, I want to put the boolean 'veilig ’ true.
That’s because there is an possibilty the robot will go back to the zone where the box is.
Cause when it goes back, Sensorvalue3 will give an signal AGAIN. But right now it’s moving to the zone where the box is, so it mustn’t work.
Therefore if Sensorvalue3 is HIGH and 'veilig ’ is true, ist mustn’t work.

But when I pass sensorvalue3 for the first time, the boolean doesnt switch to TRUE.
I dont know why,

Sorry for the complicated question, I hope you guys can help me.

sketch_pwsforum2.ino (1.63 KB)

You can just attached your sketch to your post, use the <> Code icon.

   boolean veilig = false;

Why are you creating a local variable with the same name as a global variable?

  boolean veilig = true

And another one?

Why did you post code that won't even compile?

You only need to use the word boolean (or any other data type) when you first define the variable. If you use it later, it will create a second variable with the same name and completely confuse you and the program.

Get rid of the unwanted booleans and see what happens

If you still have a problem post your revised code - and don't overwrite the first version or you will confuse us.

...R

Hi guys,

I removed the word boolean when I wanted to set the boolean to true or false, as you guys said.
And it worked, sorry i'm kinda dumb but I'm not really into this language yet, but I like it.
Next time I will post my code directly to the question.

Thanks a lot