Homework 5.1 timer class

Dependencies:   SLCD TSI mbed

Fork of kl46z_slider_v1 by Stanley Cohen

Committer:
annalou
Date:
Tue Sep 13 22:02:31 2016 +0000
Revision:
1:47e9195ab653
Parent:
0:04499bc54bee
AMartSSD341_hw5.1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
scohennm 0:04499bc54bee 1 #include "mbed.h"
scohennm 0:04499bc54bee 2 #include "TSISensor.h"
scohennm 0:04499bc54bee 3 #include "SLCD.h"
annalou 1:47e9195ab653 4 #include "Timer.h"
scohennm 0:04499bc54bee 5 #define TSILIMIT 0.99
scohennm 0:04499bc54bee 6 #define LCDCHARLEN 10
scohennm 0:04499bc54bee 7 #define DATAINTERVAL 0.1
scohennm 0:04499bc54bee 8 #define PROGNAME "kl46z_slider_test_v1\n\r"
scohennm 0:04499bc54bee 9
annalou 1:47e9195ab653 10
scohennm 0:04499bc54bee 11 SLCD slcd; //define LCD display
scohennm 0:04499bc54bee 12 Serial pc(USBTX, USBRX);
scohennm 0:04499bc54bee 13
scohennm 0:04499bc54bee 14 float tsidata;
annalou 1:47e9195ab653 15 Timer T;
scohennm 0:04499bc54bee 16
scohennm 0:04499bc54bee 17 void LCDMess(char *lMess){
scohennm 0:04499bc54bee 18 slcd.Home();
scohennm 0:04499bc54bee 19 slcd.clear();
scohennm 0:04499bc54bee 20 slcd.printf(lMess);
scohennm 0:04499bc54bee 21 }
scohennm 0:04499bc54bee 22
scohennm 0:04499bc54bee 23 int main(void) {
scohennm 0:04499bc54bee 24 char lcdData[LCDCHARLEN];
scohennm 0:04499bc54bee 25 PwmOut gled(LED_GREEN);
scohennm 0:04499bc54bee 26 PwmOut rled(LED_RED);
scohennm 0:04499bc54bee 27 pc.printf(PROGNAME);
scohennm 0:04499bc54bee 28 TSISensor tsi;
scohennm 0:04499bc54bee 29
scohennm 0:04499bc54bee 30 while (true) {
scohennm 0:04499bc54bee 31 tsidata = tsi.readPercentage();
scohennm 0:04499bc54bee 32 if (tsidata > TSILIMIT){
scohennm 0:04499bc54bee 33 gled = 0.0;
scohennm 0:04499bc54bee 34 rled = 0.0;
annalou 1:47e9195ab653 35 }
annalou 1:47e9195ab653 36 else
annalou 1:47e9195ab653 37 {
annalou 1:47e9195ab653 38 if(tsidata >= 0.01)
annalou 1:47e9195ab653 39 {
annalou 1:47e9195ab653 40 pc.printf("\n Position %f\n\r", tsidata);
annalou 1:47e9195ab653 41 sprintf (lcdData,"%0.4f",tsidata);
annalou 1:47e9195ab653 42 LCDMess(lcdData);
annalou 1:47e9195ab653 43 gled = tsidata;
annalou 1:47e9195ab653 44 rled = 1.0 - tsidata;
annalou 1:47e9195ab653 45 }
scohennm 0:04499bc54bee 46 }
annalou 1:47e9195ab653 47
annalou 1:47e9195ab653 48 T.start();
annalou 1:47e9195ab653 49 float read = T.read();
annalou 1:47e9195ab653 50 if(read >= 0.1)
annalou 1:47e9195ab653 51 {
annalou 1:47e9195ab653 52 pc.printf("stopping");
annalou 1:47e9195ab653 53 T.stop();
annalou 1:47e9195ab653 54 }
annalou 1:47e9195ab653 55 T.reset();
annalou 1:47e9195ab653 56
annalou 1:47e9195ab653 57 // wait(DATAINTERVAL);
scohennm 0:04499bc54bee 58 }
annalou 1:47e9195ab653 59
scohennm 0:04499bc54bee 60 }