A big red pulsating emergency stop button: actually a USB keyboard in disguise.
Dependencies: Pulsator USBDevice mbed Debouncer
Diff: main.cpp
- Revision:
- 1:6d520aa1463b
- Child:
- 2:617c7d2f754d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Apr 27 14:38:25 2015 +0000 @@ -0,0 +1,38 @@ +#include <mbed.h> +#include <DigitalIn.h> +#include <Pulsator.h> +#include <USBKeyboard.h> + +// ACTIVE LOW +#define PI_BUTTON P0_7 +#define PO_LED P1_15 + +#define BUTT_KEY '1' +#define BUTT_DN KEY_CTRL | KEY_ALT +#define BUTT_UP KEY_CTRL | KEY_ALT | KEY_SHIFT + +#define PERIOD_DN 0.25f +#define PERIOD_UP 2.0f + +DigitalIn butt(PI_BUTTON, PullUp); +USBKeyboard kbd; +Pulsator led(PO_LED); + +static float flashing(float x) + { return x < 0.125f || x >= 0.25f && x < 0.375f ? 1.0f : 0.0f; } + +#define BRIEFLY 0.125f +int main(void) +{ + led.active_high(false).fun(&flashing).period(PERIOD_UP) = true; + while(!kbd.configured()) wait(BRIEFLY); + led.fun(NULL); + + for(bool now = butt; ; wait(BRIEFLY)) + { + if(now == butt) continue; + now = !now; + kbd.keyCode(BUTT_KEY, now ? BUTT_UP : BUTT_DN); + led.period(now ? PERIOD_UP : PERIOD_DN); + } +}