Hello,
I'm a new user and wanted to know the best methods for advancing my project using encoders and buttons.
OBJECTIVE:
The objective is to be able to LEARN a set value (position of rotary encoder) via a LEARN button and then use that to compare future readings. The future readings will be taken as a maximum value read while the second button is depressed.
APPARATUS DETAILS:
Measuring a height using a linear gear which engages the rotary encoder. When the apparatus is in the up position it will depress the READ button. Given that a button will have minor height changes itself I thought it would be best to simply take the maximum value and then compare that with the referenced learn button.
The learn button is used to record the reference height +/- a tolerance variable when the apparatus is in the up position reading.
Apparatus use would be: place the reference object in, raise it to the up position. The learn button would would be pressed record the value to be used thereafter. The test objects would be raised up, engage the read button, report the maximum value before lowering. If they are out of tolerance, engage buzzer
HELP AREA
The speed of the encoder will be relatively slow, should its readings be taken in the loop statement or via interrupts for accuracy? The program itself I would think is brief enough and the encoder slow enough not to cause issues.
My basic understanding of coding parameters would be:
place the learn button as an interupt
in the loop statement
While Read button is depressed, read the values and once the values reduce note the maximum as MAXVALUE, as the apparatus moves down the read button is released and MAXVALUE is compared to the LEARNEDVALUE
OR:
keep the encoder pinA&B set to read via interupts as their position is most critical and have the loop statement like this:
If LEARN Button is depressed record value
IF read button is depressed record MAXVALUE and compare with LEARNEDVALUE
IF outside of tolerance ring a buzzer
Forgive my lack of code, I am just figuring out the best way to lay this out prior to getting into the thick of things