Skip to main content

Flowcode - M5 Stack Dial Workshop - 4. The bezel encoder

·2 mins·
Table of Contents

The bezel encoder feeds into two inputs - GPIO 40 and 41. When you rotate the bezel the inputs go high - first one then the other. The direction of rotation dictates which of the two inputs goes high first. The Quadrature encoder component in Flowcode takes care of the details for you and increments or decrements a counter in the component itself. You need to detect when a change has been made using an interrupt and then read the counter value.

Start with the previous program where you learned how to use the bezel switch and the Input Output pins. Add an Encoder and connect it to B.9 (GPIO41) and B.8 (GPIO40). Alter the properties as you can see in the image here.

Your panel should look like this:

This program sets up interrupts for the GPIO pins 40 and 41 - the internal Bezel connections. The interrupts call the Encoderint macro which just checks for changes on the Encoder.

Alter your program so that it looks like the flow chart here.

Note that you will need to set up an Interrupt Macro with just one command in it.

Over to you
#

Combine the functionality of the Bezel encoder, the switch and the display by altering the encoder counter to reset when the Bezel switch is pressed. You can use the Encoder hardware macro ‘Resetcounter’ for this.

Video and example file
#

A Flowcode example file accompanies this tutorial:

Further reading: Flowcode Wiki.

Next step
#

Assignment 5: I2C Expansion

Related

Flowcode - M5 Stack Dial Workshop - 2. Using the Display
2 mins
Flowcode - M5 Stack Dial Workshop - 3. Switch and I/O Pins
2 mins
Flowcode - M5 Stack Dial Workshop - 5. I2C Expansion
2 mins