A big red pulsating emergency stop button: actually a USB keyboard in disguise.
Dependencies: Pulsator USBDevice mbed Debouncer
main.cpp
- Committer:
- huliyang
- Date:
- 2015-04-27
- Revision:
- 1:6d520aa1463b
- Child:
- 2:617c7d2f754d
File content as of revision 1:6d520aa1463b:
#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); } }