Encoder for menu selection?

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 7.

Moderator: Benj

Post Reply
Coensk
Posts: 10
Joined: Tue Mar 14, 2017 10:38 am
Has thanked: 4 times

Encoder for menu selection?

Post 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)
Attachments
MENU.fcfx
(28.43 KiB) Downloaded 338 times

User avatar
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?

Post 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 358 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.matrixtsl.com/wikiv7/index. ... afda8467dc

Coensk
Posts: 10
Joined: Tue Mar 14, 2017 10:38 am
Has thanked: 4 times

Re: Encoder for menu selection?

Post 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?

User avatar
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?

Post 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 425 times

User avatar
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?

Post by Benj »

The encoder should simulate, I'm checking this now.
Yes it seems to be simulating OK in the latest example.

Post Reply