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-29
- Revision:
- 2:617c7d2f754d
- Parent:
- 1:6d520aa1463b
- Child:
- 3:e69a72de6877
File content as of revision 2:617c7d2f754d:
#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_DN_KEY '1' #define BUTT_DN_MOD KEY_CTRL | KEY_ALT #define BUTT_UP_KEY '1' #define BUTT_UP_MOD KEY_CTRL | KEY_ALT | KEY_SHIFT #define LED_PERIOD_DN 0.25f #define LED_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(LED_PERIOD_UP) = true; while(!kbd.configured()) wait(BRIEFLY); led.fun(NULL); for(bool now = butt; ; wait(BRIEFLY)) { if(now == butt) continue; now = !now; now ? kbd.keyCode(BUTT_UP_KEY, BUTT_UP_MOD) : kbd.keyCode(BUTT_DN_KEY, BUTT_DN_MOD); led.period(now ? LED_PERIOD_UP : LED_PERIOD_DN); } }