With the first three Buttons you can turn on and of the free collors. With the fouth Button you can switch between Poti and Light sensor.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers blink.cpp Source File

blink.cpp

00001 #include "mbed.h"
00002 
00003 PwmOut r(p36);
00004 PwmOut g(p5);
00005 PwmOut b(p34);
00006 AnalogIn pot(p15);
00007 BusOut leds(P1_13,P1_12,P1_7,P1_6,P1_4,P1_3,P1_1,P1_0,LED4,LED3,LED2,LED1);
00008 InterruptIn tr(P1_16);
00009 InterruptIn tg(P0_23);
00010 InterruptIn tb(P0_10);
00011 InterruptIn wt(P0_15);
00012 AnalogIn licht(p16);
00013 Serial pc(USBTX, USBRX);
00014 Timer T;
00015 
00016 int x1=0, x2=0, x3=0, wtv=0;
00017 float f;
00018 
00019 void ir()
00020 {
00021     
00022     if(x1==1)
00023     {x1=0;}
00024     else
00025     if(x1==0)
00026     {x1=1;}
00027     wait(0.2);
00028     
00029 }
00030 
00031 void ig()
00032 {
00033     
00034     if(x2==1)
00035     {x2=0;}
00036     else
00037     if(x2==0)
00038     {x2=1;}
00039     wait(0.2);
00040     
00041 }
00042 
00043 void ib()
00044 {
00045     
00046     if(x3==1)
00047     {x3=0;}
00048     else
00049     if(x3==0)
00050     {x3=1;}
00051     wait(0.2);
00052     
00053 }
00054 
00055 void wti()
00056 {
00057     
00058     if(wtv==0)
00059     {wtv=1;}
00060     else
00061     if(wtv==1)
00062     {wtv=0;}
00063     wait(0.2);
00064     
00065 }
00066 
00067 int main()
00068 {
00069         
00070     tr.rise(&ir);
00071     tg.rise(&ig);
00072     tb.rise(&ib);
00073     wt.rise(&wti);
00074         
00075     r.period(0.001);
00076     g.period(0.001);
00077     b.period(0.001);
00078     
00079     while(1)
00080         {
00081             T.start();
00082             if(x1==1)
00083             {r=1;}
00084             else
00085             if(x1==0)
00086             {r=0;}
00087             
00088             if(x2==1)
00089             {g=1;}
00090             else
00091             if(x2==0)
00092             {g=0;}
00093             
00094             if(x3==1)
00095             {b=1;}
00096             else
00097             if(x3==0)
00098             {b=0;}
00099             
00100             leds = 0xFFF;
00101             
00102             if(wtv==0)
00103             {wait(pot);}
00104             else
00105             if(wtv==1)
00106             {wait(licht);}
00107             
00108             r=1;
00109             g=1;
00110             b=1;
00111             
00112             leds = 0x0000;
00113             
00114             if(wtv==0)
00115             {wait(pot);}
00116             else
00117             if(wtv==1)
00118             {wait(licht);}
00119             
00120             T.stop();
00121             f=1/T;
00122             if(wtv==0)
00123             {pc.printf("Potentiometer Frequenz: %.2f Hz \n\r", float(f));}
00124             else
00125             if(wtv==1)
00126             {pc.printf("Helligkeitssensor Frequenz: %.2f Hz \n\r", float(f));}
00127             T.reset();
00128          
00129         }
00130         
00131     
00132 }