A big red pulsating emergency stop button: actually a USB keyboard in disguise.
Dependencies: Pulsator USBDevice mbed Debouncer
Diff: main.cpp
- Revision:
- 3:e69a72de6877
- Parent:
- 2:617c7d2f754d
--- a/main.cpp Wed Apr 29 01:54:25 2015 +0000 +++ b/main.cpp Mon May 18 14:24:51 2015 +0000 @@ -1,10 +1,10 @@ #include <mbed.h> -#include <DigitalIn.h> +#include <Debouncer.h> #include <Pulsator.h> #include <USBKeyboard.h> // ACTIVE LOW -#define PI_BUTTON P0_7 +#define PI_BUTTON P0_1 #define PO_LED P1_15 #define BUTT_DN_KEY '1' @@ -15,26 +15,31 @@ #define LED_PERIOD_DN 0.25f #define LED_PERIOD_UP 2.0f -DigitalIn butt(PI_BUTTON, PullUp); -USBKeyboard kbd; -Pulsator led(PO_LED); +static Debouncer butt(PI_BUTTON, PullUp); +static USBKeyboard kbd; +static Pulsator led(PO_LED); + +static void butt_fall(void) +{ + kbd.keyCode(BUTT_DN_KEY, BUTT_DN_MOD); + led.period(LED_PERIOD_DN); +} + +static void butt_rise(void) +{ + kbd.keyCode(BUTT_UP_KEY, BUTT_UP_MOD); + led.period(LED_PERIOD_UP); +} static float flashing(float x) - { return x < 0.125f || x >= 0.25f && x < 0.375f ? 1.0f : 0.0f; } +{ 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); + while(!kbd.configured()) wait(0.125f); led.fun(NULL); + butt.attach_fall(&butt_fall).attach_rise(&butt_rise); - 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); - } + while(1) wait(1.0f); }