EXP9

Dependencies:   TextLCD mbed tsi_sensor

Committer:
rx5
Date:
Wed Apr 13 05:40:30 2016 +0000
Revision:
0:bea9780d269a
EXP9

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rx5 0:bea9780d269a 1 #include "mbed.h"
rx5 0:bea9780d269a 2 #include "tsi_sensor.h"
rx5 0:bea9780d269a 3 #include "TextLCD.h"
rx5 0:bea9780d269a 4 #define ELEC0 9 // Constant for KL25Z tsi
rx5 0:bea9780d269a 5 #define ELEC1 10 // Constant for KL25Z tsi
rx5 0:bea9780d269a 6 TextLCD lcd(D2, D3, D4, D5, D6, D7); // Initlize LCD PIN => RS, EN, Data4, Data5, Data6, Data7
rx5 0:bea9780d269a 7 PwmOut led(LED_GREEN); // Initlize Green LED Pin as PWM Output
rx5 0:bea9780d269a 8 TSIAnalogSlider tsi(ELEC0, ELEC1, 40); // Initlize tsi Slider
rx5 0:bea9780d269a 9
rx5 0:bea9780d269a 10 int main(void) {
rx5 0:bea9780d269a 11
rx5 0:bea9780d269a 12 lcd.cls(); // Clear LCD
rx5 0:bea9780d269a 13 lcd.locate(0,0); // cursor on Col=0, Raw=0
rx5 0:bea9780d269a 14 lcd.printf("Experiment - 9"); // print startup message on LCD first Raw
rx5 0:bea9780d269a 15 lcd.locate(0,1); // cursor on Col=0, Raw=1
rx5 0:bea9780d269a 16 lcd.printf("TSI LCD & PWM"); // print startup message on LCD second Raw
rx5 0:bea9780d269a 17 wait(3.0); // wait 3 second to show startup message
rx5 0:bea9780d269a 18 while (true) {
rx5 0:bea9780d269a 19 float slider_pos,f;
rx5 0:bea9780d269a 20 slider_pos = tsi.readPercentage(); // Read TSI Slider Position i.e 0.00 to 1.00
rx5 0:bea9780d269a 21 led = 1.0f - slider_pos; // Update PWN on LED
rx5 0:bea9780d269a 22 lcd.cls(); // Clear LCD
rx5 0:bea9780d269a 23 lcd.locate(0,0); // cursor on Col=0, Raw=0
rx5 0:bea9780d269a 24 lcd.printf("TSI Value = %0.2f",tsi.readPercentage()); //Print Slider TSI Value on LCD first line
rx5 0:bea9780d269a 25 lcd.locate(0,1); // cursor on Col=0, Raw=1
rx5 0:bea9780d269a 26 for(f=0.000f;f<slider_pos;f=f+0.063f) // Loop draw H-Bar on Second line of LCD
rx5 0:bea9780d269a 27 {
rx5 0:bea9780d269a 28 lcd.printf("#");
rx5 0:bea9780d269a 29 }
rx5 0:bea9780d269a 30 wait(0.1);
rx5 0:bea9780d269a 31 }
rx5 0:bea9780d269a 32 }