Type the only important words you will ever need with this simple keyboard. Input key presses by touching the capacitive slider and watch as the words show up on your screen. Requires the FRDM to be connected to a computer using the USB port.
Dependencies: USBDevice mbed tsi_sensor
Diff: main.cpp
- Revision:
- 1:d8b92f4c7e03
- Parent:
- 0:fb74ddc7b758
diff -r fb74ddc7b758 -r d8b92f4c7e03 main.cpp --- a/main.cpp Fri Aug 22 02:12:30 2014 +0000 +++ b/main.cpp Fri Aug 22 17:09:48 2014 +0000 @@ -3,7 +3,14 @@ Automatic keyboard app You are viewing the code for the future of keyboards. You might as well -smash your current keyboard, because once you use your KL25Z as +smash your current keyboard, because once you use your KL25Z as a keyboard +you will never look back. + +The Keyboard uses the touch slider and splits it in to two buttons, a left and a right button. +The left Button types Pirates! and the right button types ROBOTS! + +The two USB ports on the board are labeled SDA and USB. Use the port called USB to type. +The LED will light on when pressed as well. */ @@ -11,7 +18,7 @@ #include "tsi_sensor.h" #include "USBKeyboard.h" -/* These defines will be replaced by PinNames soon */ +/* A couple of boards have different pins connected */ #if defined (TARGET_KL25Z) || defined (TARGET_KL46Z) #define ELEC0 9 #define ELEC1 10 @@ -22,21 +29,20 @@ #error TARGET NOT DEFINED #endif -Serial pc(USBTX, USBRX); +Serial pc(USBTX, USBRX);//begins a serial console named pc USBKeyboard keyboard; -bool justpressed = false; -float lastpressed = 0.0; int main(void) { + bool justpressed = false;//variable used to + float lastpressed = 0.0; pc.baud(115200);//I apparently have to do this in the main loop - PwmOut led(LED2);//also called LED_GREEN + DigitalOut led(LED2);//also called LED_GREEN TSIAnalogSlider tsi(ELEC0, ELEC1, 40); - pc.printf("\nSerial port activated!\n\r"); float i=0.0; while (true) { - i=1.0 - tsi.readPercentage(); - led = i; + i=1.0 - tsi.readPercentage();//i=1.0000 when not pressed and will be between 0 and 1 when touched + 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 if (justpressed && (abs(lastpressed-i)>0.1)){ justpressed=false; } @@ -51,9 +57,6 @@ justpressed = true; pc.printf(" ROBOTS!- Trigger number=%f\n\r",i); } - - wait(0.1);//this is to not overload the PWM output (writing multiple times to the LED) //pc.printf("Reading:%f\tlastpressed:%f Justpressed:%d\n\r", i,lastpressed, justpressed);//debug code - } }