ej3

Dependencies:   mbed

Committer:
sedu_santos
Date:
Sun Apr 17 16:09:53 2022 +0000
Revision:
0:5b26a9e84373
ej3

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sedu_santos 0:5b26a9e84373 1 #include "mbed.h"
sedu_santos 0:5b26a9e84373 2
sedu_santos 0:5b26a9e84373 3 Serial pc(USBTX, USBRX);
sedu_santos 0:5b26a9e84373 4 AnalogIn ldr(A0);
sedu_santos 0:5b26a9e84373 5 PwmOut led(D2);
sedu_santos 0:5b26a9e84373 6 PwmOut led2(D7);
sedu_santos 0:5b26a9e84373 7 PwmOut led3(D8);
sedu_santos 0:5b26a9e84373 8
sedu_santos 0:5b26a9e84373 9 void intensidadLDR() {
sedu_santos 0:5b26a9e84373 10 pc.baud(4800);
sedu_santos 0:5b26a9e84373 11 while(1) {
sedu_santos 0:5b26a9e84373 12 float ldrStatus = ldr.read();
sedu_santos 0:5b26a9e84373 13 pc.printf("LDR READING = %4.2f \r\n", ldrStatus);
sedu_santos 0:5b26a9e84373 14 if(ldrStatus >= 0.75f && ldrStatus <=1.0f) {
sedu_santos 0:5b26a9e84373 15 led.write(0.25);
sedu_santos 0:5b26a9e84373 16 led2.write(0.25);
sedu_santos 0:5b26a9e84373 17 led3.write(0.25);
sedu_santos 0:5b26a9e84373 18 } else if(ldrStatus >= 0.5f && ldrStatus < 0.75f) {
sedu_santos 0:5b26a9e84373 19 led.write(0.5);
sedu_santos 0:5b26a9e84373 20 led2.write(0.5);
sedu_santos 0:5b26a9e84373 21 led3.write(0.5);
sedu_santos 0:5b26a9e84373 22 } else if(ldrStatus >= 0.25f && ldrStatus < 0.5f) {
sedu_santos 0:5b26a9e84373 23 led.write(0.75);
sedu_santos 0:5b26a9e84373 24 led2.write(0.75);
sedu_santos 0:5b26a9e84373 25 led3.write(0.75);
sedu_santos 0:5b26a9e84373 26 } else if(ldrStatus >= 0.0f && ldrStatus < 0.25f) {
sedu_santos 0:5b26a9e84373 27 led.write(1.0);
sedu_santos 0:5b26a9e84373 28 led2.write(1.0);
sedu_santos 0:5b26a9e84373 29 led3.write(1.0);
sedu_santos 0:5b26a9e84373 30 } else {
sedu_santos 0:5b26a9e84373 31 led.write(0.0);
sedu_santos 0:5b26a9e84373 32 led2.write(0.0);
sedu_santos 0:5b26a9e84373 33 led3.write(0.0);
sedu_santos 0:5b26a9e84373 34 }
sedu_santos 0:5b26a9e84373 35 }
sedu_santos 0:5b26a9e84373 36 }
sedu_santos 0:5b26a9e84373 37
sedu_santos 0:5b26a9e84373 38 int main() {
sedu_santos 0:5b26a9e84373 39 intensidadLDR();
sedu_santos 0:5b26a9e84373 40 }