Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: DebounceIn PinDetect_KL25Z USBDevice mbed
Fork of idd_fall15_hw2_chiller_morse by
main.cpp
00001 #include "mbed.h" 00002 #include "USBKeyboard.h" 00003 #include "PinDetect.h" 00004 00005 USBKeyboard keyboard; 00006 00007 PinDetect button1(D4); // Left 00008 PinDetect button2(D5); // Right 00009 PinDetect button3(D6); // Space 00010 PinDetect button4(D7); // Shift 00011 00012 DigitalOut myled(LED1); 00013 00014 int state[4]; 00015 00016 void button1_pressed() { 00017 state[0] = 1; 00018 } 00019 void button2_pressed() { 00020 state[1] = 1; 00021 } 00022 void button3_pressed() { 00023 state[2] = 1; 00024 } 00025 void button4_pressed() { 00026 state[3] = 1; 00027 } 00028 00029 void button1_released() { 00030 state[0] = 0; 00031 } 00032 void button2_released() { 00033 state[1] = 0; 00034 } 00035 void button3_released() { 00036 state[2] = 0; 00037 } 00038 void button4_released() { 00039 state[3] = 0; 00040 } 00041 00042 void exec_keycode(int state[], USBKeyboard keyboard) { 00043 if (state[0] == 1) { 00044 keyboard.keyCode('a'); 00045 } 00046 if (state[1] == 1) { 00047 keyboard.keyCode('d'); 00048 } 00049 if (state[2] == 1) { 00050 keyboard.keyCode(32); 00051 } 00052 if (state[3] == 1) { 00053 keyboard.keyCode(16); 00054 } 00055 } 00056 00057 int main() { 00058 00059 /*Add callback functions for events when buttons are pressed. */ 00060 button1.attach_asserted(&button1_pressed); 00061 button2.attach_asserted(&button2_pressed); 00062 button3.attach_asserted(&button3_pressed); 00063 button4.attach_asserted(&button4_pressed); 00064 00065 /*Add callback functions for events when buttons are released. */ 00066 button1.attach_deasserted(&button1_released); 00067 button2.attach_deasserted(&button2_released); 00068 button3.attach_deasserted(&button3_released); 00069 button4.attach_deasserted(&button4_released); 00070 00071 button1.setAssertValue(0); 00072 button2.setAssertValue(0); 00073 button3.setAssertValue(0); 00074 button4.setAssertValue(0); 00075 00076 button1.setSampleFrequency(); 00077 button2.setSampleFrequency(); 00078 button3.setSampleFrequency(); 00079 button4.setSampleFrequency(); 00080 00081 for (;;) { 00082 if (state[0] == 1) { 00083 keyboard.keyCode('a'); 00084 } 00085 if (state[1] == 1) { 00086 keyboard.keyCode('d'); 00087 } 00088 if (state[2] == 1) { 00089 keyboard.keyCode(32); 00090 } 00091 if (state[3] == 1) { 00092 keyboard.keyCode(16); 00093 } 00094 wait(0.1); 00095 } 00096 }
Generated on Sun Aug 21 2022 08:03:48 by
1.7.2
