Page 1 of 1

Encoder for menu selection?

Posted: Thu Mar 16, 2017 9:48 am
by Coensk
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)

Re: Encoder for menu selection?

Posted: Thu Mar 16, 2017 12:07 pm
by Benj
Hello,

I've used the quadrature encoder component and added the code for it to function to your program.
MENU.fcfx
(30.88 KiB) Downloaded 374 times
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.flowcode.co.uk/wikiv7/index. ... afda8467dc

Re: Encoder for menu selection?

Posted: Thu Mar 16, 2017 2:11 pm
by Coensk
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?

Re: Encoder for menu selection?

Posted: Thu Mar 16, 2017 3:54 pm
by Benj
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.
MENU.fcfx
(30.61 KiB) Downloaded 439 times

Re: Encoder for menu selection?

Posted: Thu Mar 16, 2017 4:25 pm
by Benj
The encoder should simulate, I'm checking this now.
Yes it seems to be simulating OK in the latest example.