Close

Add Button

A project log for Holiday 8-bit ^2 LED Ornament

An 8x8 LED matrix animated ornament powered by an ATtiny85

toddTodd 12/18/2017 at 19:520 Comments

Adding a multi-purpose button started with needing a "pull" so the button input pin didn't float. I decided to use the internal Pull-up capability of the tiny (so the button is wired to GND).

Next came debounce, see Arduino example code but I tweaked a bit. Originally I combined the debounce and the button control logic, but when things got a bit more complex it got messy, plus I was violating the Single Responsibility Principle. So I moved the button code to it's own extensible state machine function. I tend to use SM's everywhere in MCU's (when I'm not being lazy).

Now I was able to cycle through different designs with the push of the button, and eventually added "long press" and even "very long press" to control it further.

I don't know about you but I always wire buttons wrong the first time - I want to go "straight through", but notice how the correct wiring uses pins on a diagonal.

Discussions