Keyboard and pwm led brightness

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
juanitoinig84
Date:
Thu Jun 30 23:28:52 2016 +0000
Commit message:
PWM brightness with keyboard input

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	Thu Jun 30 23:28:52 2016 +0000
@@ -0,0 +1,74 @@
+#include "mbed.h"
+
+PwmOut pwm1(PTC11);
+PwmOut pwmLED(LED_RED);
+//AnalogOut dac(DAC0_OUT);
+Serial pc(USBTX,USBRX);
+ 
+
+uint16_t periodPWM1 = 1;
+uint16_t periodPWMLED =1;
+float dutyPWM1 = 0;
+float dutyPWMLED = 0;
+
+void rxInterrupt()
+{
+    switch(pc.getc()) {
+ 
+        case 'a':
+      
+            periodPWM1++;
+            periodPWMLED++;
+ 
+            pwm1.period_ms(periodPWM1);
+            pwmLED.period_ms(periodPWMLED);
+                    
+            break;
+ 
+        case 's':
+        
+            if (periodPWM1>1) {
+                periodPWM1--;
+                periodPWMLED--;
+             }
+            pwm1.period_ms(periodPWM1);
+            pwmLED.period_ms(periodPWMLED);          
+ 
+            break;
+            
+            case 'f':    
+       
+            if (dutyPWM1<1) {
+                dutyPWM1 = dutyPWM1 + 0.05 ;
+                dutyPWMLED = dutyPWMLED + 0.05;
+            }
+ 
+            pwm1.write(dutyPWM1);
+            pwmLED.write(dutyPWMLED);
+  
+            break;
+            
+            
+            case 'g':      
+            if (dutyPWM1>0) {
+                dutyPWM1 = dutyPWM1 - 0.05 ;
+                dutyPWMLED = dutyPWMLED - 0.05;
+            }
+            pwm1.write(dutyPWM1);
+            pwmLED.write(dutyPWMLED);
+                   
+            break;
+            
+            default: break;
+    }
+    
+    pc.printf("Period (ms): %i, Duty: %.2f \r\n", periodPWM1,dutyPWM1);
+ 
+}
+
+int main()
+{
+   // pc.baud(115200);
+    pc.attach(&rxInterrupt);
+    while(1);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Jun 30 23:28:52 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/6c34061e7c34
\ No newline at end of file