Iván Santos
/
santos_ej2_modulo3
santos_ej2_modulo3
main.cpp@1:9fb35f902a08, 2022-04-24 (annotated)
- Committer:
- sedu_santos
- Date:
- Sun Apr 24 18:20:48 2022 +0000
- Revision:
- 1:9fb35f902a08
- Parent:
- 0:12a8fb08eb52
aa
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sedu_santos | 0:12a8fb08eb52 | 1 | #include "mbed.h" |
sedu_santos | 0:12a8fb08eb52 | 2 | |
sedu_santos | 0:12a8fb08eb52 | 3 | Serial pc(USBTX, USBRX); |
sedu_santos | 0:12a8fb08eb52 | 4 | DigitalOut my_led(LED1); |
sedu_santos | 0:12a8fb08eb52 | 5 | PwmOut my_pwm(D2); |
sedu_santos | 0:12a8fb08eb52 | 6 | AnalogIn ldr(A0); |
sedu_santos | 0:12a8fb08eb52 | 7 | |
sedu_santos | 0:12a8fb08eb52 | 8 | void pressed() { |
sedu_santos | 0:12a8fb08eb52 | 9 | pc.baud(4800); |
sedu_santos | 0:12a8fb08eb52 | 10 | while (1) { |
sedu_santos | 0:12a8fb08eb52 | 11 | float c=ldr.read(); |
sedu_santos | 0:12a8fb08eb52 | 12 | pc.printf("LDR READING = %4.2f \r\n", c); |
sedu_santos | 0:12a8fb08eb52 | 13 | if (c<0.3) { |
sedu_santos | 1:9fb35f902a08 | 14 | my_pwm.write(0.15); // Si la luminosidad menor que 0.3, el servo se establece en 0.15 |
sedu_santos | 0:12a8fb08eb52 | 15 | } |
sedu_santos | 0:12a8fb08eb52 | 16 | else { |
sedu_santos | 1:9fb35f902a08 | 17 | my_pwm.write(0.05); // Si la luminosidad es 0.3 o mayor, el servo se establece en 0.05 |
sedu_santos | 0:12a8fb08eb52 | 18 | } |
sedu_santos | 0:12a8fb08eb52 | 19 | } |
sedu_santos | 0:12a8fb08eb52 | 20 | } |
sedu_santos | 0:12a8fb08eb52 | 21 | |
sedu_santos | 0:12a8fb08eb52 | 22 | int main() |
sedu_santos | 0:12a8fb08eb52 | 23 | { |
sedu_santos | 0:12a8fb08eb52 | 24 | // Set PWM |
sedu_santos | 0:12a8fb08eb52 | 25 | my_pwm.period_ms(10); |
sedu_santos | 0:12a8fb08eb52 | 26 | my_pwm.write(0.1); |
sedu_santos | 0:12a8fb08eb52 | 27 | pressed(); |
sedu_santos | 0:12a8fb08eb52 | 28 | } |