Best way to trigger a function from running analog input?
I should start by saying I don't have the strongest programming background. My project involves a rotating wheel with an attached encoder. The goal is to trigger an event when the wheel reaches a certain angle.
Currently I have this set up with a simple if statement stating if (the wheel == angle) {trigger event}. I am hoping to find a more robust solution to this issue. Some potential sources of error could be, if the wheel stops at the exact angle and continuously triggers the event. Another issue could be if the encoder skips over 30 and misses the trigger.
I understand that I could patch these issues individually, but was wondering if there was a standard way of performing such a task.
Thank you
Posted Mar 12, 2018, 1:04 PM UTC
you have a good start. add a global variable, then change it to
if (wheel >= angle && !isTriggered) {isTriggered=true; rest of trigger event}then add another condition to set isTriggered=false when the wheel is less than the angle.This is exactly what I was looking for! Thank you, it works great!