Skip to content

Instantly share code, notes, and snippets.

@krdln
Last active December 25, 2015 17:29
Show Gist options
  • Save krdln/7013239 to your computer and use it in GitHub Desktop.
Save krdln/7013239 to your computer and use it in GitHub Desktop.
Blinking K6: example of AVR C++IO library.
#define F_CPU 12000000UL
#include <krdln/port.h>
int main() {
Output<A::Pin<0>> led;
Output<A::Pin<2>, false> err; // false: "on" level is 0V
Button<C::Pin<3>> but; // automagic pullup, yay!
int const T = 300;
while (true) {
while (!but);
dms(100); // debounce (wait for 100ms)
if (!but) {
// warn if too short
hold(err), dms(T); // light up diode for T milliseconds
// Comma postpones destruction of object returned by hold,
// which does =1 in c-tor and =0 on d-tor.
continue;
}
unsigned random = 0;
while (but) ++random;
int score = random % 6 + 1;
while (score--) {
hold(led), dms(T);
dms(T);
}
dms(2*T);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment