Hello,
I'm new to Flowcode programming and trying to make a little menu for my Arduino Mega and EBM001 lcd display. So far the menu works but with push buttons. You can find my program under attachments.
Now I'm trying to make it work with the encoder. Every attempt at making it work with the encoder and decision icons has failed so far. I can't seem to find any examples about the encoder either.
Does anyone have an idea on how to determine the direction of the encoder in Flowcode? (I know the incremental/quadrature encoder principle)
Encoder for menu selection?
Moderator: Benj
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Encoder for menu selection?
Hello,
I've used the quadrature encoder component and added the code for it to function to your program.
A more reliable way is to use an interrupt to sample the encoder, either a timer interrupt to periodically check for changes or an interrupt on change to trigger as the signals change state.
There are some examples here.
https://www.matrixtsl.com/wikiv7/index. ... afda8467dc
I've used the quadrature encoder component and added the code for it to function to your program.
A more reliable way is to use an interrupt to sample the encoder, either a timer interrupt to periodically check for changes or an interrupt on change to trigger as the signals change state.
There are some examples here.
https://www.matrixtsl.com/wikiv7/index. ... afda8467dc
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Encoder for menu selection?
Hey Benj,
Thanks for your quick answer, this made things a lot easier to understand. Is it normal that the encoder never simulates in FlowCode yet it does something when i test it in Arduino?
Whichever direction i turn the encoder, the block just goes down one line then stops doing anything. Shouldn't I be checking both channels bitwise of the encoder to determine the direction?
Thanks for your quick answer, this made things a lot easier to understand. Is it normal that the encoder never simulates in FlowCode yet it does something when i test it in Arduino?
Whichever direction i turn the encoder, the block just goes down one line then stops doing anything. Shouldn't I be checking both channels bitwise of the encoder to determine the direction?
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Encoder for menu selection?
Hello,
Glad to be of help.
The encoder should simulate, I'm checking this now.
The Encoder component macros should do the following.
CheckForChanges - Monitors the encoder input pins checking for state changes, returns 0 for no change, 1 for valid change and 255 for invalid change. e.g. more than one pin has changed state since last called.
Calling this macro via a timer interrupt or IOC interrupt helps to ensure you stay on top of the changes and never miss a pulse.
ReadCounter - Reads the value of the count variable which is modified by the check for changes. This should return positive or negative value for a valid change based on the way the encoder is turned, after the change is detected we reset the count to 0.
I've re-done the example this time using a timer interrupt which should help keep things working.
Glad to be of help.
The encoder should simulate, I'm checking this now.
The Encoder component macros should do the following.
CheckForChanges - Monitors the encoder input pins checking for state changes, returns 0 for no change, 1 for valid change and 255 for invalid change. e.g. more than one pin has changed state since last called.
Calling this macro via a timer interrupt or IOC interrupt helps to ensure you stay on top of the changes and never miss a pulse.
ReadCounter - Reads the value of the count variable which is modified by the check for changes. This should return positive or negative value for a valid change based on the way the encoder is turned, after the change is detected we reset the count to 0.
I've re-done the example this time using a timer interrupt which should help keep things working.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Encoder for menu selection?
Yes it seems to be simulating OK in the latest example.The encoder should simulate, I'm checking this now.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel