all publish

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
daikinect
Date:
Mon May 06 00:20:37 2019 +0000
Commit message:
all publish

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon May 06 00:20:37 2019 +0000
@@ -0,0 +1,48 @@
+#include "mbed.h"
+
+Timeout timer;
+DigitalOut my_led(LED1);
+DigitalOut my_pwm(D10); // IO used by pwm_io function
+
+int on_delay = 0;
+int off_delay = 0;
+
+void toggleOff(void);
+
+void toggleOn(void) {
+    my_pwm = 1;
+    timer.attach_us(toggleOff, on_delay);
+}
+
+void toggleOff(void) {
+    my_pwm = 0;
+    timer.attach_us(toggleOn, off_delay);
+}
+
+// p_us = signal period in micro_seconds
+// dc   = signal duty-cycle (0.0 to 1.0)
+void pwm_io(int p_us, float dc) {
+    timer.detach();
+    if ((p_us == 0) || (dc == 0)) {
+        my_pwm = 0;
+        return;
+    }
+    if (dc >= 1) {
+        my_pwm = 1;
+        return;
+    }
+    on_delay = (int)(p_us * dc);
+    off_delay = p_us - on_delay;
+    toggleOn();
+}
+
+int main() {
+    
+    pwm_io(20000, 0.25); // 20ms - 25%
+    
+    while(1) {
+        my_led = !my_led;
+        wait(0.5);
+    }
+}
+ 
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon May 06 00:20:37 2019 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/mbed/builds/97feb9bacc10
\ No newline at end of file