Touch Pad example with USB Serial function.

Dependencies:   mbed tsi_sensor

Committer:
TheFella
Date:
Sun Mar 01 21:13:00 2015 +0000
Revision:
2:5709201019b5
Parent:
1:dd12cd8c2fab

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
TheFella 0:1831ea7044ec 1 /******************************************************************
TheFella 0:1831ea7044ec 2 Program: MyFirstMbed
TheFella 0:1831ea7044ec 3 Author: CTalbot
TheFella 0:1831ea7044ec 4 Date: 19 Feb, 2015
TheFella 0:1831ea7044ec 5 (c) Fanshawe College, 2015
TheFella 0:1831ea7044ec 6 Modified: Xxxxxxx Xxxxxx
TheFella 0:1831ea7044ec 7
TheFella 0:1831ea7044ec 8 Description: This program introduces the touch pad of the FRDM-KL25Z,
TheFella 0:1831ea7044ec 9 and USB serial function. Hello World.
TheFella 0:1831ea7044ec 10 ********************************************************************/
TheFella 0:1831ea7044ec 11
TheFella 0:1831ea7044ec 12 // Preprocessor Statements
TheFella 0:1831ea7044ec 13 #include "mbed.h"
TheFella 0:1831ea7044ec 14 #include "tsi_sensor.h"
TheFella 0:1831ea7044ec 15
TheFella 0:1831ea7044ec 16 // Constants
TheFella 0:1831ea7044ec 17
TheFella 0:1831ea7044ec 18
TheFella 0:1831ea7044ec 19
TheFella 0:1831ea7044ec 20 // Global Variables
TheFella 0:1831ea7044ec 21
TheFella 2:5709201019b5 22 Serial pc(USBTX, USBRX); // USB Serial Port
TheFella 0:1831ea7044ec 23
TheFella 0:1831ea7044ec 24
TheFella 0:1831ea7044ec 25 /*** MAIN *************************************************************/
TheFella 0:1831ea7044ec 26 int main()
TheFella 0:1831ea7044ec 27 {
TheFella 0:1831ea7044ec 28 PwmOut Grn(LED_GREEN); // PWM output, named Grn, tied to LED_GREEN Pin
TheFella 0:1831ea7044ec 29 PwmOut Red(LED_RED);
TheFella 0:1831ea7044ec 30 PwmOut Blue(LED_BLUE);
TheFella 0:1831ea7044ec 31
TheFella 0:1831ea7044ec 32 TSIAnalogSlider tsi(PTB16, PTB17, 25); // Touch pad slider tied to touch pad pins, named tsi
TheFella 0:1831ea7044ec 33
TheFella 0:1831ea7044ec 34 while(1)
TheFella 0:1831ea7044ec 35 {
TheFella 0:1831ea7044ec 36 Grn = 1.0 - tsi.readPercentage(); // Assign the read value taken away from 1 to Grn.
TheFella 0:1831ea7044ec 37 Red = tsi.readPercentage();
TheFella 0:1831ea7044ec 38 Blue = tsi.readPercentage() / 2;
TheFella 0:1831ea7044ec 39
TheFella 0:1831ea7044ec 40 pc.printf("\033[2J"); // clears the entire terminal screen.
TheFella 0:1831ea7044ec 41 pc.printf("\033[H"); // Sends cursor to home position, 0,0
TheFella 0:1831ea7044ec 42
TheFella 0:1831ea7044ec 43 pc.printf("\n\rHello World");
TheFella 0:1831ea7044ec 44 pc.printf("\n\rName: CTalbot");
TheFella 0:1831ea7044ec 45 pc.printf("\n\rTouch Pad Value: %.2f", tsi.readPercentage() );
TheFella 0:1831ea7044ec 46
TheFella 0:1831ea7044ec 47 wait(0.2);
TheFella 0:1831ea7044ec 48
TheFella 1:dd12cd8c2fab 49 }//eo while loop
TheFella 1:dd12cd8c2fab 50 }//eo main