How to make a priority on pins

Hi guys,

i have i small problem here with my project and need your help. Im moving a step motor forward and back with buttons and an end stop is an inductive proximity sensor. So now if the inductive sensor is triggered i would like the start button to be lets say disabled until the sensor switches to high state again. But for some reason even if the sensor is covered arduino always gives priority to the button instead of sensor.

To be honest im a beginer at all this, but it doesnt make much sense to me that if something is triggered before something else, why would something triggered after have priority.

So the question is how can i make arduino ignore the data from the button pin or some other solution during the sensor is covered?

Thanks

and your code is...? (basically you need to check all the pins that matter and then decide based on the full information gathered what you want to do. if you just check one pin regardless of the others, then that pin will have "priority" against the others)

You can do it by setting a flag. Say you reach one end. You set a flag showing you reach there,
then don’t allow any more travel in that direction until the flag is cleared:

if (end1flag == 0 && digitalRead (sensor1Pin ==0) { // not to end  yet
// allow motor 1 direction
}
else {
end1flag = 1; // end has been reached
// stop motor 1 travel
// clear flag to go to the other end
end2flag = 0;
// and start motor 2 travel
}
if (end2flag == 0 && digitalRead (sensor2Pin) == 0){ // not to end yet
// allow motor 2 direction
}
else {
end2flag = 1;
// stop motor 2 travel
// clear flag to go to the other direction
end1flag = 0;
// and start motor 1 travel
}

J-M-L:
and your code is…? (basically you need to check all the pins that matter and then decide based on the full information gathered what you want to do. if you just check one pin regardless of the others, then that pin will have “priority” against the others)

Beginner yes, but not that fresh :slight_smile: Thanks anyway

CrossRoads: You can do it by setting a flag. Say you reach one end. You set a flag showing you reach there, then don't allow any more travel in that direction until the flag is cleared:

CrossRoads, It works!!! I had to make some adjustments to fuse your idea with my program, but i does the trick :sweat_smile:

Thank you so much! You have a couple of beers on me, when you come to Croatia for vacation.