Keyboard and pwm led brightness

Dependencies:   mbed

Revision:
0:ae5e8aa73f3a
--- /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);
+}