EMench_SSD645_HW3.2. Took out the decimal point.

Dependencies:   SLCD mbed

Fork of lightsense_kl46z_PWM_simple by Stanley Cohen

main.cpp

Committer:
menchacaeli
Date:
2017-02-05
Revision:
9:1a503296af3c
Parent:
8:ea818c9220fc

File content as of revision 9:1a503296af3c:

#include "mbed.h"
#include "SLCD.h"


#define PROGNAME "lightsense_kl46z_PWM v1\n\r"
#define DATATIME 400 // milliseconds
#define LCDLEN 10
#define LIGHTSENSORPORT PTE22



SLCD slcd; //define LCD display globally define
Serial pc(USBTX, USBRX);
Timer LEDTimer;

void LCDMess(char *lMess){
        slcd.Home();
        slcd.clear();
        slcd.printf(lMess);
        // removing decimal point
        slcd.DP(0, false);
} 

int main() {
    PwmOut greenColor(LED_GREEN);
    PwmOut redColor(LED_RED);
    AnalogIn LightSensor(LIGHTSENSORPORT);
    float lightData; 
    char lcdData[LCDLEN];
   
    int timeToChangeDF = DATATIME;
    // set up timer for next step of Duty Factor timing
    LEDTimer.start();
    LEDTimer.reset();
    pc.printf(PROGNAME);
    
    
    while(true) {    
        if (LEDTimer.read_ms() > timeToChangeDF){ // check for timer time out transtion
            lightData = (1.0 - LightSensor.read()); // show as increasiing with increasing intensity
            greenColor.write(1.0- lightData);
            redColor.write(1.0-lightData);
            sprintf(lcdData,"%4.3f",lightData);
            LCDMess(lcdData);  
            pc.printf("%4.3f\r\n",lightData);
            timeToChangeDF = DATATIME;
            LEDTimer.reset();
        }        
    }// emd while
}