Brightness of four leds is changed by PWM.

Dependencies:   mbed

Revision:
1:151d44cd460b
Parent:
0:95e37c204360
diff -r 95e37c204360 -r 151d44cd460b pwm_blinky.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pwm_blinky.cpp	Tue May 15 04:03:38 2018 +0000
@@ -0,0 +1,26 @@
+#include "mbed.h"
+
+PwmOut pwmled1(LED1), pwmled2(LED2);
+PwmOut pwmled3(p22), pwmled4(p23);
+// Serial pc(USBTX, USBRX);
+
+void changeled(PwmOut *led)
+{ float val;
+  val= led->read() * 1.03 +0.01;
+  if (val>0.99) val=0.0;
+  led->write(val);}
+
+void changeled_rev(PwmOut *led)
+{ float val;
+  val= led->read() * 0.98 - 0.01;
+  if (val<0.01) val=0.99;
+  led->write(val);}
+  
+int main() {
+   while(1) {
+      changeled(&pwmled1);
+      changeled_rev(&pwmled2);
+      changeled(&pwmled3);
+      changeled_rev(&pwmled4); 
+     wait(0.05);      } }
+