Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Kmj
Date:
Wed Jan 27 04:55:43 2016 +0000
Commit message:
This is remake version of Nucleo_pwm3.

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
diff -r 000000000000 -r eb891a3bc014 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jan 27 04:55:43 2016 +0000
@@ -0,0 +1,55 @@
+#include "mbed.h"
+
+Timeout timer;
+InterruptIn my_button(USER_BUTTON);
+DigitalOut my_pwm(LED1); // IO used by pwm_io function
+
+int on_delay = 0;
+int off_delay = 0;
+float duty[5]={0.2f,0.4f,0.6f,0.8f,1.0f};
+int i=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();
+}
+void pressed()
+{   if(i>=5)
+        i=0;
+
+    pwm_io(20000,duty[i]);
+    i++;
+}
+
+int main() {
+    my_button.fall(&pressed);
+    pwm_io(20000, 0.25); // 20ms - 25%
+    
+    while(1) {
+        
+    }
+}
+ 
\ No newline at end of file
diff -r 000000000000 -r eb891a3bc014 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Jan 27 04:55:43 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/6f327212ef96
\ No newline at end of file