USBKeyboard test.

Committer:
hudakz
Date:
Fri May 01 20:26:42 2020 +0000
Revision:
2:59bd031a5687
Parent:
1:92ba159b850f
USBKeyboard test.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hudakz 0:be4449b9ccca 1 /*
hudakz 0:be4449b9ccca 2 * -------
hudakz 0:be4449b9ccca 3 * |
hudakz 0:be4449b9ccca 4 * KL25Z |
hudakz 0:be4449b9ccca 5 * |
hudakz 0:be4449b9ccca 6 * |
hudakz 1:92ba159b850f 7 * PTD3 |-------
hudakz 0:be4449b9ccca 8 * | |
hudakz 0:be4449b9ccca 9 * ------- |
hudakz 0:be4449b9ccca 10 * o
hudakz 0:be4449b9ccca 11 * /
hudakz 0:be4449b9ccca 12 * o
hudakz 0:be4449b9ccca 13 * |
hudakz 0:be4449b9ccca 14 * ---
hudakz 0:be4449b9ccca 15 * GND
hudakz 0:be4449b9ccca 16 */
hudakz 0:be4449b9ccca 17
hudakz 0:be4449b9ccca 18 #include "mbed.h"
hudakz 0:be4449b9ccca 19 #include "USBKeyboard.h"
hudakz 0:be4449b9ccca 20
hudakz 0:be4449b9ccca 21 #define BOUNCING_TIME 300*1000 // 300 ms
hudakz 0:be4449b9ccca 22
hudakz 0:be4449b9ccca 23 USBKeyboard key;
hudakz 0:be4449b9ccca 24 InterruptIn startMP3Player(PTD3, PullUp);
hudakz 0:be4449b9ccca 25 Thread t;
hudakz 0:be4449b9ccca 26 EventQueue queue;
hudakz 0:be4449b9ccca 27 Timeout btnDebouncer;
hudakz 0:be4449b9ccca 28 bool btnIsBouncing = false;
hudakz 0:be4449b9ccca 29
hudakz 0:be4449b9ccca 30 void bouncingOver(void)
hudakz 0:be4449b9ccca 31 {
hudakz 0:be4449b9ccca 32 btnIsBouncing = false;
hudakz 0:be4449b9ccca 33 }
hudakz 0:be4449b9ccca 34
hudakz 0:be4449b9ccca 35 void startMP3Player_handler(void)
hudakz 0:be4449b9ccca 36 {
hudakz 0:be4449b9ccca 37 if (btnIsBouncing == false) {
hudakz 2:59bd031a5687 38 key.printf("vlc windofchange.mp3\n"); // replace this text with the command to play an MP3 file (but keep \n)
hudakz 0:be4449b9ccca 39 btnDebouncer.attach_us(bouncingOver, BOUNCING_TIME);
hudakz 0:be4449b9ccca 40 btnIsBouncing = true;
hudakz 0:be4449b9ccca 41 }
hudakz 0:be4449b9ccca 42 }
hudakz 0:be4449b9ccca 43
hudakz 0:be4449b9ccca 44 int main(void)
hudakz 0:be4449b9ccca 45 {
hudakz 0:be4449b9ccca 46 t.start(callback(&queue, &EventQueue::dispatch_forever));
hudakz 0:be4449b9ccca 47 startMP3Player.fall(queue.event(startMP3Player_handler));
hudakz 0:be4449b9ccca 48 }