EMench_SSD645_HW3.2. Took out the decimal point.

Dependencies:   SLCD mbed

Fork of lightsense_kl46z_PWM_simple by Stanley Cohen

Committer:
menchacaeli
Date:
Sun Feb 05 23:36:36 2017 +0000
Revision:
9:1a503296af3c
Parent:
8:ea818c9220fc
EMench_SSD645_HW3.2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
scohennm 0:e23fffd4b9a7 1 #include "mbed.h"
scohennm 1:51f8c2b04ce2 2 #include "SLCD.h"
scohennm 1:51f8c2b04ce2 3
scohennm 3:64e28ee5719b 4
scohennm 8:ea818c9220fc 5 #define PROGNAME "lightsense_kl46z_PWM v1\n\r"
scohennm 8:ea818c9220fc 6 #define DATATIME 400 // milliseconds
scohennm 1:51f8c2b04ce2 7 #define LCDLEN 10
scohennm 8:ea818c9220fc 8 #define LIGHTSENSORPORT PTE22
scohennm 6:710e18c552f5 9
scohennm 6:710e18c552f5 10
scohennm 0:e23fffd4b9a7 11
scohennm 4:bd42ab18979b 12 SLCD slcd; //define LCD display globally define
scohennm 1:51f8c2b04ce2 13 Serial pc(USBTX, USBRX);
scohennm 8:ea818c9220fc 14 Timer LEDTimer;
scohennm 1:51f8c2b04ce2 15
scohennm 1:51f8c2b04ce2 16 void LCDMess(char *lMess){
scohennm 1:51f8c2b04ce2 17 slcd.Home();
scohennm 1:51f8c2b04ce2 18 slcd.clear();
scohennm 1:51f8c2b04ce2 19 slcd.printf(lMess);
menchacaeli 9:1a503296af3c 20 // removing decimal point
menchacaeli 9:1a503296af3c 21 slcd.DP(0, false);
scohennm 1:51f8c2b04ce2 22 }
scohennm 0:e23fffd4b9a7 23
scohennm 0:e23fffd4b9a7 24 int main() {
scohennm 8:ea818c9220fc 25 PwmOut greenColor(LED_GREEN);
scohennm 8:ea818c9220fc 26 PwmOut redColor(LED_RED);
scohennm 8:ea818c9220fc 27 AnalogIn LightSensor(LIGHTSENSORPORT);
scohennm 6:710e18c552f5 28 float lightData;
scohennm 1:51f8c2b04ce2 29 char lcdData[LCDLEN];
scohennm 4:bd42ab18979b 30
scohennm 8:ea818c9220fc 31 int timeToChangeDF = DATATIME;
scohennm 3:64e28ee5719b 32 // set up timer for next step of Duty Factor timing
scohennm 3:64e28ee5719b 33 LEDTimer.start();
scohennm 3:64e28ee5719b 34 LEDTimer.reset();
scohennm 1:51f8c2b04ce2 35 pc.printf(PROGNAME);
scohennm 1:51f8c2b04ce2 36
scohennm 3:64e28ee5719b 37
scohennm 8:ea818c9220fc 38 while(true) {
scohennm 8:ea818c9220fc 39 if (LEDTimer.read_ms() > timeToChangeDF){ // check for timer time out transtion
scohennm 8:ea818c9220fc 40 lightData = (1.0 - LightSensor.read()); // show as increasiing with increasing intensity
scohennm 8:ea818c9220fc 41 greenColor.write(1.0- lightData);
scohennm 8:ea818c9220fc 42 redColor.write(1.0-lightData);
scohennm 8:ea818c9220fc 43 sprintf(lcdData,"%4.3f",lightData);
scohennm 8:ea818c9220fc 44 LCDMess(lcdData);
scohennm 8:ea818c9220fc 45 pc.printf("%4.3f\r\n",lightData);
scohennm 8:ea818c9220fc 46 timeToChangeDF = DATATIME;
scohennm 8:ea818c9220fc 47 LEDTimer.reset();
scohennm 8:ea818c9220fc 48 }
scohennm 4:bd42ab18979b 49 }// emd while
scohennm 4:bd42ab18979b 50 }