Is there a way to estimate (or measure) how long each section of a larger program takes to run through so that I can program millis() delays correctly?
Is my r3 UNO fast enough that I should be using micros() instead even if I'm measuring at 100 or even 250 microsecs a pass?
I've got two sensors, two pots controlling a servo each, and two LED arrays (one responds to time, the other from inputs from both sensors, code for either has been omitted from the sample below). I'm still trying to build the hardware side, but I'm already thinking software side. I'm wanting to know how long to set my tokens before expiring them to allow the sensors to be read again, the pots to be consulted then if necessary update the servos, and the LEDs to be adjusted.
Below is the working prototype of the structure I'm working on, advise on this as well is gratefully accepted.
Sample PseudoCode:
void loop();
int LONG heartbeat;
heartbeat = milis();
if (SensorA) { // A photocell
See if the token set from the last time the sensor was measured has expired
if (TokenExpired) {
Its been long enough, do something
Set Token for [x] millis()
} else {
Its not been long enough
Token--
}
}
if (SensorB) { // An electret mic
See if the token set from the last time the sensor was measured has expired
if (TokenExpired) {
Its been long enough, do something
Set Token for [x] millis()
} else {
Its not been long enough
Token--
}
}
if (PotA) { // controls ServoA
See if the token set from the last time the pot was measured has expired
if (TokenExpired) {
Its been long enough
if (PotA has a different value) {
move servoA to new value
Set Token for [x] millis()
}
} else {
Its not been long enough
Token--
}
}
if (PotB) { // controls ServoB
See when PotB was last checked
if (TokenExpired) {
Its been long enough
if (PotB has a different value) {
move servoB to new value
Set Token for [x] millis()
}
} else {
Its not been long enough
Token--
}
}