Could you please explain for the next code segment, how is that the counter variable is initialized to zero, and later incremented. Shouldn’t this result in a counter value always equals to one?
(Page 102 of the book).
Thanks.
if(code == LV_EVENT_CLICKED) {
static uint8_t counter = 0;
counter++;
lv_label_set_text_fmt(label, “Counter: %d”, counter);
LV_LOG_USER(“Counter: %d”, counter);
}
3 Answers
Hi.
It is because the counter variable is initialized as static.
Learn more about the features of static variables here: https://www.arduino.cc/reference/es/language/variables/variable-scope-qualifiers/static/
I hope this helps.
Regards,
Sara