Skip to main content

Background: I have a uni assignment which requires an autonomous robot to do a number of tasks and then finish in a set spot after being triggered to start by an outside physical interaction. I've set up a light limit switch to detect this interaction.

My approach would normaly be to look for the switch in the loop to go high and then run through my code and put a really long delay at the end. e.g. switchState = digitalRead(switch) if (switchState == HIGH){ //do my routine which is a function defined outside of the loop }

switchState = digitalRead(switch);
 if (switchState == HIGH){
 //do my routine which is a function defined outside of the loop
}

Would this be an appropriate use for an interupt instead of the method above. I'm still trying to understand the best practice usage.

Background: I have a uni assignment which requires an autonomous robot to do a number of tasks and then finish in a set spot after being triggered to start by an outside physical interaction. I've set up a light limit switch to detect this interaction

My approach would normaly be to look for the switch in the loop to go high and then run through my code and put a really long delay at the end. e.g. switchState = digitalRead(switch) if (switchState == HIGH){ //do my routine which is a function defined outside of the loop }

Would this be an appropriate use for an interupt instead of the method above. I'm still trying to understand the best practice usage.

Background: I have a uni assignment which requires an autonomous robot to do a number of tasks and then finish in a set spot after being triggered to start by an outside physical interaction. I've set up a light limit switch to detect this interaction.

My approach would normaly be to look for the switch in the loop to go high and then run through my code and put a really long delay at the end. e.g.

switchState = digitalRead(switch);
 if (switchState == HIGH){
 //do my routine which is a function defined outside of the loop
}

Would this be an appropriate use for an interupt instead of the method above. I'm still trying to understand the best practice usage.

Source Link
James
  • 113
  • 3

Correct use of interrupt vs monitoring switch

Background: I have a uni assignment which requires an autonomous robot to do a number of tasks and then finish in a set spot after being triggered to start by an outside physical interaction. I've set up a light limit switch to detect this interaction

My approach would normaly be to look for the switch in the loop to go high and then run through my code and put a really long delay at the end. e.g. switchState = digitalRead(switch) if (switchState == HIGH){ //do my routine which is a function defined outside of the loop }

Would this be an appropriate use for an interupt instead of the method above. I'm still trying to understand the best practice usage.