A big red pulsating emergency stop button: actually a USB keyboard in disguise.
Dependencies: Pulsator USBDevice mbed Debouncer
main.cpp@1:6d520aa1463b, 2015-04-27 (annotated)
- Committer:
- huliyang
- Date:
- Mon Apr 27 14:38:25 2015 +0000
- Revision:
- 1:6d520aa1463b
- Child:
- 2:617c7d2f754d
How do I interrupted pin? ?\(?_o)/?
Who changed what in which revision?
User | Revision | Line number | New 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 | 1:6d520aa1463b | 10 | #define BUTT_KEY '1' |
huliyang | 1:6d520aa1463b | 11 | #define BUTT_DN KEY_CTRL | KEY_ALT |
huliyang | 1:6d520aa1463b | 12 | #define BUTT_UP KEY_CTRL | KEY_ALT | KEY_SHIFT |
huliyang | 1:6d520aa1463b | 13 | |
huliyang | 1:6d520aa1463b | 14 | #define PERIOD_DN 0.25f |
huliyang | 1:6d520aa1463b | 15 | #define PERIOD_UP 2.0f |
huliyang | 1:6d520aa1463b | 16 | |
huliyang | 1:6d520aa1463b | 17 | DigitalIn butt(PI_BUTTON, PullUp); |
huliyang | 1:6d520aa1463b | 18 | USBKeyboard kbd; |
huliyang | 1:6d520aa1463b | 19 | Pulsator led(PO_LED); |
huliyang | 1:6d520aa1463b | 20 | |
huliyang | 1:6d520aa1463b | 21 | static float flashing(float x) |
huliyang | 1:6d520aa1463b | 22 | { return x < 0.125f || x >= 0.25f && x < 0.375f ? 1.0f : 0.0f; } |
huliyang | 1:6d520aa1463b | 23 | |
huliyang | 1:6d520aa1463b | 24 | #define BRIEFLY 0.125f |
huliyang | 1:6d520aa1463b | 25 | int main(void) |
huliyang | 1:6d520aa1463b | 26 | { |
huliyang | 1:6d520aa1463b | 27 | led.active_high(false).fun(&flashing).period(PERIOD_UP) = true; |
huliyang | 1:6d520aa1463b | 28 | while(!kbd.configured()) wait(BRIEFLY); |
huliyang | 1:6d520aa1463b | 29 | led.fun(NULL); |
huliyang | 1:6d520aa1463b | 30 | |
huliyang | 1:6d520aa1463b | 31 | for(bool now = butt; ; wait(BRIEFLY)) |
huliyang | 1:6d520aa1463b | 32 | { |
huliyang | 1:6d520aa1463b | 33 | if(now == butt) continue; |
huliyang | 1:6d520aa1463b | 34 | now = !now; |
huliyang | 1:6d520aa1463b | 35 | kbd.keyCode(BUTT_KEY, now ? BUTT_UP : BUTT_DN); |
huliyang | 1:6d520aa1463b | 36 | led.period(now ? PERIOD_UP : PERIOD_DN); |
huliyang | 1:6d520aa1463b | 37 | } |
huliyang | 1:6d520aa1463b | 38 | } |