#include <EButton.h>
#include <Encoder.h>
#include <ezLED.h>
static EButton button(4);
static Encoder dial(2, 3);
static ezLED led(12);
static long const code[] = {-5, 3, -1}; // Get this from EEPROM.
template <class T, size_t N> size_t arraySize(T const (&)[N]) {
return N;
}
static void click(EButton& btn) {
static size_t index = 0;
if (dial.read() / 4 == code[index]) {
index++;
if (index == arraySize(code)) {
led.turnON();
}
return;
}
index = 0;
}
static void turn() {
static long oldValue = 0;
long value = dial.read() / 4;
if (value != oldValue) {
Serial.println(value);
oldValue = value;
}
}
void setup() {
Serial.begin(9600);
button.attachSingleClick(click);
led.turnOFF();
}
void loop() {
button.tick();
turn();
}