testing dht22 / ldr

Dependencies:   DHT22 mbed

Fork of mDot_AnalogIn_LDR_Example by Brendan Kelly

Committer:
kellybs1
Date:
Sun Aug 06 00:24:22 2017 +0000
Revision:
2:55d40722ec9d
Parent:
1:ceddded7137c
Child:
3:3947bb0a2b4f
reading analogue LDR

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mfiore 1:ceddded7137c 1 /** mDot AnalogIn Example Program
mfiore 0:436a6a6b80a1 2 *
mfiore 0:436a6a6b80a1 3 * This program demonstrates how to read an anglog pin using the
mfiore 1:ceddded7137c 4 * MultiTech mDot and MultiTech UDK2 hardware. The only
mfiore 0:436a6a6b80a1 5 * additional hardware required is an analog voltage source like
mfiore 0:436a6a6b80a1 6 * a potentiometer.
mfiore 0:436a6a6b80a1 7 *
mfiore 0:436a6a6b80a1 8 *
mfiore 1:ceddded7137c 9 * This program reads the analog input connected to pin PB_1 (UDK2
mfiore 1:ceddded7137c 10 * pin A0) and prints the result.
mfiore 0:436a6a6b80a1 11 */
mfiore 0:436a6a6b80a1 12
mfiore 0:436a6a6b80a1 13 #include "mbed.h"
mfiore 0:436a6a6b80a1 14
mfiore 0:436a6a6b80a1 15 int main() {
kellybs1 2:55d40722ec9d 16 AnalogIn a0(PB_1);
mfiore 0:436a6a6b80a1 17
mfiore 0:436a6a6b80a1 18 while (true) {
kellybs1 2:55d40722ec9d 19 //read as float (0.0-1.0, multiply by 1000)
kellybs1 2:55d40722ec9d 20 float ldr1 = a0.read() * 1000;
kellybs1 2:55d40722ec9d 21 wait_ms(100);
kellybs1 2:55d40722ec9d 22 float ldr2 = a0.read() * 1000;
kellybs1 2:55d40722ec9d 23 wait_ms(100);
kellybs1 2:55d40722ec9d 24 float ldr3 = a0.read() * 1000;
kellybs1 2:55d40722ec9d 25 wait_ms(100);
kellybs1 2:55d40722ec9d 26 //average
kellybs1 2:55d40722ec9d 27 float ldr = (ldr1 + ldr2 + ldr3) / 3;
kellybs1 2:55d40722ec9d 28 //output 3 digits . 3 decimal places
kellybs1 2:55d40722ec9d 29 printf("LDR: %3.3f\r\n", ldr);
kellybs1 2:55d40722ec9d 30 wait(1);
mfiore 0:436a6a6b80a1 31 }
mfiore 0:436a6a6b80a1 32 }