Balazs Szalai / Mbed 2 deprecated 4led-dim3

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 // dimmed kitt LED blinking
00002 //   the question was how to enable dimming on multiple digital led the same time.
00003 //   it could be done simpler with math/sin, yet it I found it more fun
00004 #include "mbed.h"
00005 #include "math.h"
00006 
00007 PwmOut led[4] = { LED1, LED2, LED3, LED4 };
00008 
00009 float DimVal( int idx, float f ) {
00010     return (sin(f + float(idx)*1.6) + 1.0) / 2.0;   // transform value from -1.0 .. 1.0 to 0.0 .. 1.0
00011 }
00012 
00013 int main() {
00014     while (1) {
00015          for (float f = 0.0f; f < 6.3; f += 0.1f) {
00016             led[0] = DimVal( 0, f );
00017             led[1] = DimVal( 1, f );
00018             led[2] = DimVal( 2, f );
00019             led[3] = DimVal( 3, f );
00020             wait_ms(10);
00021         }
00022     }
00023 }