Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of lightsense_kl46z_basic by
main.cpp@10:380416fe6a88, 2016-09-19 (annotated)
- Committer:
- menchacaeli
- Date:
- Mon Sep 19 02:34:00 2016 +0000
- Revision:
- 10:380416fe6a88
- Parent:
- 9:f619cdaa7a65
light sensor LEDs.
Who changed what in which revision?
| User | Revision | Line number | New 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 | 9:f619cdaa7a65 | 5 | #define PROGNAME "lightsense_kl46z_basic v1\n\r" |
| scohennm | 8:3b19ecdc4261 | 6 | #define DATATIME 400 // milliseconds |
| scohennm | 1:51f8c2b04ce2 | 7 | #define LCDLEN 10 |
| scohennm | 8:3b19ecdc4261 | 8 | #define LIGHTSENSORPORT PTE22 |
| menchacaeli | 10:380416fe6a88 | 9 | #define LEDON false |
| menchacaeli | 10:380416fe6a88 | 10 | #define LEDOFF true |
| menchacaeli | 10:380416fe6a88 | 11 | #define LRED "RED" |
| menchacaeli | 10:380416fe6a88 | 12 | #define LGREEN "GREN" |
| scohennm | 0:e23fffd4b9a7 | 13 | |
| scohennm | 4:bd42ab18979b | 14 | SLCD slcd; //define LCD display globally define |
| scohennm | 1:51f8c2b04ce2 | 15 | Serial pc(USBTX, USBRX); |
| scohennm | 8:3b19ecdc4261 | 16 | Timer LEDTimer; |
| menchacaeli | 10:380416fe6a88 | 17 | Timer LIGHTTimer; |
| menchacaeli | 10:380416fe6a88 | 18 | |
| menchacaeli | 10:380416fe6a88 | 19 | bool ledState = LEDON; |
| scohennm | 1:51f8c2b04ce2 | 20 | |
| scohennm | 1:51f8c2b04ce2 | 21 | void LCDMess(char *lMess){ |
| scohennm | 1:51f8c2b04ce2 | 22 | slcd.Home(); |
| scohennm | 1:51f8c2b04ce2 | 23 | slcd.clear(); |
| scohennm | 1:51f8c2b04ce2 | 24 | slcd.printf(lMess); |
| scohennm | 1:51f8c2b04ce2 | 25 | } |
| scohennm | 0:e23fffd4b9a7 | 26 | |
| scohennm | 0:e23fffd4b9a7 | 27 | int main() { |
| scohennm | 8:3b19ecdc4261 | 28 | AnalogIn LightSensor(LIGHTSENSORPORT); |
| scohennm | 6:710e18c552f5 | 29 | float lightData; |
| scohennm | 1:51f8c2b04ce2 | 30 | char lcdData[LCDLEN]; |
| scohennm | 4:bd42ab18979b | 31 | |
| scohennm | 8:3b19ecdc4261 | 32 | int timeToChangeDF = DATATIME; |
| scohennm | 3:64e28ee5719b | 33 | LEDTimer.start(); |
| scohennm | 3:64e28ee5719b | 34 | LEDTimer.reset(); |
| scohennm | 1:51f8c2b04ce2 | 35 | pc.printf(PROGNAME); |
| scohennm | 1:51f8c2b04ce2 | 36 | |
| menchacaeli | 10:380416fe6a88 | 37 | PwmOut gled(LED_GREEN); |
| menchacaeli | 10:380416fe6a88 | 38 | PwmOut rled(LED_RED); |
| menchacaeli | 10:380416fe6a88 | 39 | |
| scohennm | 8:3b19ecdc4261 | 40 | while(true) { |
| scohennm | 8:3b19ecdc4261 | 41 | if (LEDTimer.read_ms() > timeToChangeDF){ // check for timer time out transtion |
| scohennm | 9:f619cdaa7a65 | 42 | lightData = (1.0 - LightSensor.read()); // show as increasiing with increasing intensity |
| scohennm | 9:f619cdaa7a65 | 43 | sprintf(lcdData,"%4.3f",lightData); |
| scohennm | 8:3b19ecdc4261 | 44 | LCDMess(lcdData); |
| scohennm | 8:3b19ecdc4261 | 45 | timeToChangeDF = DATATIME; |
| menchacaeli | 10:380416fe6a88 | 46 | gled = 0.0; |
| menchacaeli | 10:380416fe6a88 | 47 | rled = 0.0; |
| scohennm | 8:3b19ecdc4261 | 48 | LEDTimer.reset(); |
| menchacaeli | 10:380416fe6a88 | 49 | } |
| scohennm | 4:bd42ab18979b | 50 | }// emd while |
| scohennm | 4:bd42ab18979b | 51 | } |
