KBrat-SSD541-HW-5_2

Dependencies:   SLCD mbed

Fork of lightsense_kl46z_basic by Stanley Cohen

Committer:
tisbrat
Date:
Mon Sep 19 06:21:08 2016 +0000
Revision:
10:8ad79c335cfa
Parent:
9:f619cdaa7a65
KBrat-SSD541-HW-5_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
tisbrat 10:8ad79c335cfa 5 #define PROGNAME "KBrat-SSD541-HW-5_2_Part1\n\r"
scohennm 8:3b19ecdc4261 6 #define DATATIME 400 // milliseconds
scohennm 1:51f8c2b04ce2 7 #define LCDLEN 10
scohennm 8:3b19ecdc4261 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:3b19ecdc4261 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);
scohennm 1:51f8c2b04ce2 20 }
scohennm 0:e23fffd4b9a7 21
scohennm 9:f619cdaa7a65 22
scohennm 0:e23fffd4b9a7 23 int main() {
scohennm 8:3b19ecdc4261 24 AnalogIn LightSensor(LIGHTSENSORPORT);
scohennm 6:710e18c552f5 25 float lightData;
scohennm 1:51f8c2b04ce2 26 char lcdData[LCDLEN];
tisbrat 10:8ad79c335cfa 27 PwmOut gled(LED_GREEN);
tisbrat 10:8ad79c335cfa 28 PwmOut rled(LED_RED);
scohennm 4:bd42ab18979b 29
scohennm 8:3b19ecdc4261 30 int timeToChangeDF = DATATIME;
scohennm 3:64e28ee5719b 31 LEDTimer.start();
scohennm 3:64e28ee5719b 32 LEDTimer.reset();
scohennm 1:51f8c2b04ce2 33 pc.printf(PROGNAME);
scohennm 1:51f8c2b04ce2 34
scohennm 8:3b19ecdc4261 35 while(true) {
scohennm 8:3b19ecdc4261 36 if (LEDTimer.read_ms() > timeToChangeDF){ // check for timer time out transtion
tisbrat 10:8ad79c335cfa 37 lightData = (1.0 - LightSensor.read()); // show as increasing with increasing intensity
tisbrat 10:8ad79c335cfa 38 sprintf(lcdData,"%4.3f",lightData);
tisbrat 10:8ad79c335cfa 39 LCDMess(lcdData);
tisbrat 10:8ad79c335cfa 40 gled = 1.0 - lightData; //green light changes intensity as light data changes
tisbrat 10:8ad79c335cfa 41 rled = 1.0 - lightData; //red light changes intensity as light data changes
scohennm 8:3b19ecdc4261 42 timeToChangeDF = DATATIME;
scohennm 8:3b19ecdc4261 43 LEDTimer.reset();
scohennm 8:3b19ecdc4261 44 }
tisbrat 10:8ad79c335cfa 45 }// end while
scohennm 4:bd42ab18979b 46 }
tisbrat 10:8ad79c335cfa 47
tisbrat 10:8ad79c335cfa 48