santos_ej2_modulo3

Dependencies:   mbed

Revision:
0:12a8fb08eb52
Child:
1:9fb35f902a08
diff -r 000000000000 -r 12a8fb08eb52 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Apr 24 17:54:57 2022 +0000
@@ -0,0 +1,28 @@
+#include "mbed.h"
+
+Serial pc(USBTX, USBRX);
+DigitalOut my_led(LED1);
+PwmOut my_pwm(D2);
+AnalogIn ldr(A0);
+
+void pressed() {
+    pc.baud(4800);
+    while (1) {
+        float c=ldr.read();
+        pc.printf("LDR READING = %4.2f \r\n", c);
+        if (c<0.3) {
+           my_pwm.write(0.15); // Si la luminosidad es 0.3 o mayor, el servo se establece en 0.15
+        }
+        else {
+           my_pwm.write(0.05); // Si la luminosidad menor que 0.3, el servo se establece 0.5
+        }
+    }
+}
+
+int main()
+{
+    // Set PWM
+    my_pwm.period_ms(10);
+    my_pwm.write(0.1);    
+    pressed();
+}
\ No newline at end of file