bruce chan
/
send_online_version_2
keyboard
Revision 0:3309d940c502, committed 2017-11-14
- Comitter:
- bruce_0205
- Date:
- Tue Nov 14 15:09:40 2017 +0000
- Commit message:
- hi
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/USBDevice.lib Tue Nov 14 15:09:40 2017 +0000 @@ -0,0 +1,1 @@ +http://os.mbed.com/users/mbed_official/code/USBDevice/#53949e6131f6
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Nov 14 15:09:40 2017 +0000 @@ -0,0 +1,75 @@ +#include "mbed.h" +#include "USBKeyboard.h" + +//LED1: NUM_LOCK, LED2: CAPS_LOCK, LED3: SCROLL_LOCK +BusOut leds(LED1, LED2, LED3); //keyboard on/off set +DigitalIn start(PTC1); // Configure SW2 pin as input function is start +DigitalIn stop(PTB17); // Configure SW3 pin as input function is stop +USBKeyboard keyboard; + +//user input key +#define user_button_key_1 'S' +#define user_button_key_2 'D' +#define user_button_key_3 'F' +#define user_button_key_4 'E' +#define user_button_key_5 'B' +#define user_button_key_6 'C' + +//user input key delay time +#define user_button_delay_1 5 +#define user_button_delay_2 3 +#define user_button_delay_3 4 +#define user_button_delay_4 2 +#define user_button_delay_5 8 +#define user_button_delay_6 3 + +char user_button_key[]={ + user_button_key_1, + user_button_key_2, + user_button_key_3, + user_button_key_4, + user_button_key_5, + user_button_key_6 +}; + +int user_button_delay[]={ + user_button_delay_1, + user_button_delay_2, + user_button_delay_3, + user_button_delay_4, + user_button_delay_5, + user_button_delay_6 +}; + +void user_button_content(char [],int []); + +long int timer = 0; + +int main() { + + while (!keyboard.configured()) { // wait until keyboard is configured + } + + while (1) { + leds = keyboard.lockStatus(); //open keyboard + + if(start.read() == 0){ //wait SW2 button press + while(stop.read() != 0){ //wait SW3 button press + user_button_content(user_button_key,user_button_delay); + timer++; + for(double i=0;i<1;i=i+0.1){ //count 1 second time and wait SW3 button press + if(stop.read() == 0) break; + wait(0.1); + } + } + timer = 0; + } + } +} + +void user_button_content(char key[],int delay[]){ + for(int i=0;i<strlen(key);i++){ + if((timer%delay[i]) == 0) + keyboard._putc(key[i]); + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Nov 14 15:09:40 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/b484a57bc302 \ No newline at end of file