#pragma once #include "gpio.h" template class Encoder { private: Input pina; Input pinb; char state; public: value_t value; Encoder() : state(0), value(0) { pina.pull_up(); pinb.pull_up(); } bool update() { char new_state = (pina ? 1 : 0) + (pinb ? 2 : 0); if (state == new_state) return false; // 3 1 0 2 // 3 2 0 1 if (state == 2 && new_state == 3) value++; else if (state == 1 && new_state == 3) value--; state = new_state; return true; } };