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: USBDevice mbed tsi_sensor
main.cpp
00001 /* Created by Mark Oehlberg 8/21/14 00002 00003 Automatic keyboard app 00004 00005 You are viewing the code for the future of keyboards. You might as well 00006 smash your current keyboard, because once you use your KL25Z as a keyboard 00007 you will never look back. 00008 00009 The Keyboard uses the touch slider and splits it in to two buttons, a left and a right button. 00010 The left Button types Pirates! and the right button types ROBOTS! 00011 00012 The two USB ports on the board are labeled SDA and USB. Use the port called USB to type. 00013 The LED will light on when pressed as well. 00014 00015 */ 00016 00017 #include "mbed.h" 00018 #include "tsi_sensor.h" 00019 #include "USBKeyboard.h" 00020 00021 /* A couple of boards have different pins connected */ 00022 #if defined (TARGET_KL25Z) || defined (TARGET_KL46Z) 00023 #define ELEC0 9 00024 #define ELEC1 10 00025 #elif defined (TARGET_KL05Z) 00026 #define ELEC0 9 00027 #define ELEC1 8 00028 #else 00029 #error TARGET NOT DEFINED 00030 #endif 00031 00032 Serial pc(USBTX, USBRX);//begins a serial console named pc 00033 USBKeyboard keyboard; 00034 00035 00036 int main(void) { 00037 bool justpressed = false;//variable used to 00038 float lastpressed = 0.0; 00039 pc.baud(115200);//I apparently have to do this in the main loop 00040 DigitalOut led(LED2);//also called LED_GREEN 00041 TSIAnalogSlider tsi(ELEC0, ELEC1, 40); 00042 float i=0.0; 00043 while (true) { 00044 i=1.0 - tsi.readPercentage();//i=1.0000 when not pressed and will be between 0 and 1 when touched 00045 led = (i == 1.0) ? 1 : 0;//turn the light on if the slider is pressed. Outputting Zero on this pin connects the cathode to ground. The annode is connected to 3.3V 00046 if (justpressed && (abs(lastpressed-i)>0.1)){ 00047 justpressed=false; 00048 } 00049 if ( 0.5 < i && i < 1.0 && not justpressed ){ 00050 keyboard.printf("Pirates!\r\n"); 00051 lastpressed = i; 00052 justpressed = true; 00053 pc.printf(" Pirates - Trigger number=%f\n\r",i); 00054 }else if (0.0 < i && i <= 0.5 && not justpressed ){ 00055 keyboard.printf("ROBOTS!\r\n"); 00056 lastpressed = i; 00057 justpressed = true; 00058 pc.printf(" ROBOTS!- Trigger number=%f\n\r",i); 00059 } 00060 //pc.printf("Reading:%f\tlastpressed:%f Justpressed:%d\n\r", i,lastpressed, justpressed);//debug code 00061 } 00062 }
Generated on Wed Jul 13 2022 11:19:51 by
1.7.2