A big red pulsating emergency stop button: actually a USB keyboard in disguise.

Dependencies:   Pulsator USBDevice mbed Debouncer

https://igcdn-photos-f-a.akamaihd.net/hphotos-ak-xaf1/t51.2885-15/11208187_762945727138101_782976670_n.jpg

Committer:
huliyang
Date:
Wed Apr 29 01:54:25 2015 +0000
Revision:
2:617c7d2f754d
Parent:
1:6d520aa1463b
Child:
3:e69a72de6877
Separate DN and UP keys, as well as modifiers.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
huliyang 1:6d520aa1463b 1 #include <mbed.h>
huliyang 1:6d520aa1463b 2 #include <DigitalIn.h>
huliyang 1:6d520aa1463b 3 #include <Pulsator.h>
huliyang 1:6d520aa1463b 4 #include <USBKeyboard.h>
huliyang 1:6d520aa1463b 5
huliyang 1:6d520aa1463b 6 // ACTIVE LOW
huliyang 1:6d520aa1463b 7 #define PI_BUTTON P0_7
huliyang 1:6d520aa1463b 8 #define PO_LED P1_15
huliyang 1:6d520aa1463b 9
huliyang 2:617c7d2f754d 10 #define BUTT_DN_KEY '1'
huliyang 2:617c7d2f754d 11 #define BUTT_DN_MOD KEY_CTRL | KEY_ALT
huliyang 2:617c7d2f754d 12 #define BUTT_UP_KEY '1'
huliyang 2:617c7d2f754d 13 #define BUTT_UP_MOD KEY_CTRL | KEY_ALT | KEY_SHIFT
huliyang 1:6d520aa1463b 14
huliyang 2:617c7d2f754d 15 #define LED_PERIOD_DN 0.25f
huliyang 2:617c7d2f754d 16 #define LED_PERIOD_UP 2.0f
huliyang 1:6d520aa1463b 17
huliyang 1:6d520aa1463b 18 DigitalIn butt(PI_BUTTON, PullUp);
huliyang 1:6d520aa1463b 19 USBKeyboard kbd;
huliyang 1:6d520aa1463b 20 Pulsator led(PO_LED);
huliyang 1:6d520aa1463b 21
huliyang 1:6d520aa1463b 22 static float flashing(float x)
huliyang 1:6d520aa1463b 23 { return x < 0.125f || x >= 0.25f && x < 0.375f ? 1.0f : 0.0f; }
huliyang 1:6d520aa1463b 24
huliyang 1:6d520aa1463b 25 #define BRIEFLY 0.125f
huliyang 1:6d520aa1463b 26 int main(void)
huliyang 1:6d520aa1463b 27 {
huliyang 2:617c7d2f754d 28 led.active_high(false).fun(&flashing).period(LED_PERIOD_UP) = true;
huliyang 1:6d520aa1463b 29 while(!kbd.configured()) wait(BRIEFLY);
huliyang 1:6d520aa1463b 30 led.fun(NULL);
huliyang 1:6d520aa1463b 31
huliyang 1:6d520aa1463b 32 for(bool now = butt; ; wait(BRIEFLY))
huliyang 1:6d520aa1463b 33 {
huliyang 1:6d520aa1463b 34 if(now == butt) continue;
huliyang 1:6d520aa1463b 35 now = !now;
huliyang 2:617c7d2f754d 36 now ? kbd.keyCode(BUTT_UP_KEY, BUTT_UP_MOD)
huliyang 2:617c7d2f754d 37 : kbd.keyCode(BUTT_DN_KEY, BUTT_DN_MOD);
huliyang 2:617c7d2f754d 38 led.period(now ? LED_PERIOD_UP : LED_PERIOD_DN);
huliyang 1:6d520aa1463b 39 }
huliyang 1:6d520aa1463b 40 }