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 mDot_AnalogIn_LDR_Example by
Diff: main.cpp
- Revision:
- 2:55d40722ec9d
- Parent:
- 1:ceddded7137c
- Child:
- 3:3947bb0a2b4f
--- a/main.cpp Fri Oct 02 16:46:53 2015 +0000
+++ b/main.cpp Sun Aug 06 00:24:22 2017 +0000
@@ -13,10 +13,20 @@
#include "mbed.h"
int main() {
- AnalogIn in(PB_1);
+ AnalogIn a0(PB_1);
while (true) {
- printf("analog value: 0x%04X\r\n", in.read_u16());
- wait_ms(500);
+ //read as float (0.0-1.0, multiply by 1000)
+ float ldr1 = a0.read() * 1000;
+ wait_ms(100);
+ float ldr2 = a0.read() * 1000;
+ wait_ms(100);
+ float ldr3 = a0.read() * 1000;
+ wait_ms(100);
+ //average
+ float ldr = (ldr1 + ldr2 + ldr3) / 3;
+ //output 3 digits . 3 decimal places
+ printf("LDR: %3.3f\r\n", ldr);
+ wait(1);
}
}
\ No newline at end of file
