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:4fa8bf6e3ade, 2016-09-19 (annotated)
- Committer:
- annalou
- Date:
- Mon Sep 19 02:37:43 2016 +0000
- Revision:
- 10:4fa8bf6e3ade
- Parent:
- 9:f619cdaa7a65
- Child:
- 11:75596fecb8d5
AMartssd341_ledbrightlights
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 |
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 | |
annalou | 10:4fa8bf6e3ade | 16 | void LCDMess(char *lMess) |
annalou | 10:4fa8bf6e3ade | 17 | { |
annalou | 10:4fa8bf6e3ade | 18 | slcd.Home(); |
annalou | 10:4fa8bf6e3ade | 19 | slcd.clear(); |
annalou | 10:4fa8bf6e3ade | 20 | slcd.printf(lMess); |
annalou | 10:4fa8bf6e3ade | 21 | } |
scohennm | 0:e23fffd4b9a7 | 22 | |
scohennm | 9:f619cdaa7a65 | 23 | |
annalou | 10:4fa8bf6e3ade | 24 | int main() |
annalou | 10:4fa8bf6e3ade | 25 | { |
scohennm | 8:3b19ecdc4261 | 26 | AnalogIn LightSensor(LIGHTSENSORPORT); |
annalou | 10:4fa8bf6e3ade | 27 | float lightData; |
scohennm | 1:51f8c2b04ce2 | 28 | char lcdData[LCDLEN]; |
annalou | 10:4fa8bf6e3ade | 29 | PwmOut gled(LED_GREEN); |
annalou | 10:4fa8bf6e3ade | 30 | PwmOut rled(LED_RED); |
annalou | 10:4fa8bf6e3ade | 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); |
annalou | 10:4fa8bf6e3ade | 36 | |
annalou | 10:4fa8bf6e3ade | 37 | while(true) { |
annalou | 10:4fa8bf6e3ade | 38 | if (LEDTimer.read_ms() > timeToChangeDF) { // check for timer time out transtion |
annalou | 10:4fa8bf6e3ade | 39 | lightData = (1.0 - LightSensor.read()); // show as increasiing with increasing intensity |
annalou | 10:4fa8bf6e3ade | 40 | sprintf(lcdData,"%4.3f",lightData); |
annalou | 10:4fa8bf6e3ade | 41 | LCDMess(lcdData); |
scohennm | 8:3b19ecdc4261 | 42 | timeToChangeDF = DATATIME; |
annalou | 10:4fa8bf6e3ade | 43 | pc.printf(lcdData); |
annalou | 10:4fa8bf6e3ade | 44 | rled = lightData; |
annalou | 10:4fa8bf6e3ade | 45 | gled = lightData; |
scohennm | 8:3b19ecdc4261 | 46 | LEDTimer.reset(); |
annalou | 10:4fa8bf6e3ade | 47 | } |
scohennm | 4:bd42ab18979b | 48 | }// emd while |
scohennm | 4:bd42ab18979b | 49 | } |