Jomelo / LCDMenuLib2

Create a tree menu. Use it with different lcd types / console output / ssh console.
MIT License
249 stars 47 forks source link

use volatile for input reading to avoid erronenous compiler optimizations #8

Closed AndiRuss closed 6 years ago

AndiRuss commented 6 years ago

in LCDML_041_u8g2lib line 229fff:

unsigned char a = digitalRead(_LCDML_CONTROL_encoder_pin_a); unsigned char b = digitalRead(_LCDML_CONTROL_encoder_pin_b); unsigned char t = digitalRead(_LCDML_CONTROL_encoder_pin_button);

It is more robust to used volatile in front of unsigned char for variables which are changing by hardware.

Compiler may do optimizations leading to really strange program behaviour. This happened in my case when using your code in an own application.

I did not check the rest of your software.

Jomelo commented 6 years ago

The code is optimized for the arduino platform.