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

Meine Projekte

Diese Projekte habe ich im SS 2015 in FSST programmiert.

hgjk

Committer:
04M04
Date:
Fri Apr 24 08:18:20 2015 +0000
Revision:
0:3120b9f00d30
Test Poti, Light sensor and LDR

Who changed what in which revision?

UserRevisionLine numberNew contents of line
04M04 0:3120b9f00d30 1 #include "mbed.h"
04M04 0:3120b9f00d30 2
04M04 0:3120b9f00d30 3 PwmOut r(p36);
04M04 0:3120b9f00d30 4 PwmOut g(p5);
04M04 0:3120b9f00d30 5 PwmOut b(p34);
04M04 0:3120b9f00d30 6 AnalogIn pot(p15);
04M04 0:3120b9f00d30 7 BusOut leds(P1_13,P1_12,P1_7,P1_6,P1_4,P1_3,P1_1,P1_0,LED4,LED3,LED2,LED1);
04M04 0:3120b9f00d30 8 InterruptIn tr(P1_16);
04M04 0:3120b9f00d30 9 InterruptIn tg(P0_23);
04M04 0:3120b9f00d30 10 InterruptIn tb(P0_10);
04M04 0:3120b9f00d30 11 InterruptIn wt(P0_15);
04M04 0:3120b9f00d30 12 AnalogIn licht(p16);
04M04 0:3120b9f00d30 13 Serial pc(USBTX, USBRX);
04M04 0:3120b9f00d30 14 Timer T;
04M04 0:3120b9f00d30 15
04M04 0:3120b9f00d30 16 int x1=0, x2=0, x3=0, wtv=0;
04M04 0:3120b9f00d30 17 float f;
04M04 0:3120b9f00d30 18
04M04 0:3120b9f00d30 19 void ir()
04M04 0:3120b9f00d30 20 {
04M04 0:3120b9f00d30 21
04M04 0:3120b9f00d30 22 if(x1==1)
04M04 0:3120b9f00d30 23 {x1=0;}
04M04 0:3120b9f00d30 24 else
04M04 0:3120b9f00d30 25 if(x1==0)
04M04 0:3120b9f00d30 26 {x1=1;}
04M04 0:3120b9f00d30 27 wait(0.2);
04M04 0:3120b9f00d30 28
04M04 0:3120b9f00d30 29 }
04M04 0:3120b9f00d30 30
04M04 0:3120b9f00d30 31 void ig()
04M04 0:3120b9f00d30 32 {
04M04 0:3120b9f00d30 33
04M04 0:3120b9f00d30 34 if(x2==1)
04M04 0:3120b9f00d30 35 {x2=0;}
04M04 0:3120b9f00d30 36 else
04M04 0:3120b9f00d30 37 if(x2==0)
04M04 0:3120b9f00d30 38 {x2=1;}
04M04 0:3120b9f00d30 39 wait(0.2);
04M04 0:3120b9f00d30 40
04M04 0:3120b9f00d30 41 }
04M04 0:3120b9f00d30 42
04M04 0:3120b9f00d30 43 void ib()
04M04 0:3120b9f00d30 44 {
04M04 0:3120b9f00d30 45
04M04 0:3120b9f00d30 46 if(x3==1)
04M04 0:3120b9f00d30 47 {x3=0;}
04M04 0:3120b9f00d30 48 else
04M04 0:3120b9f00d30 49 if(x3==0)
04M04 0:3120b9f00d30 50 {x3=1;}
04M04 0:3120b9f00d30 51 wait(0.2);
04M04 0:3120b9f00d30 52
04M04 0:3120b9f00d30 53 }
04M04 0:3120b9f00d30 54
04M04 0:3120b9f00d30 55 void wti()
04M04 0:3120b9f00d30 56 {
04M04 0:3120b9f00d30 57
04M04 0:3120b9f00d30 58 if(wtv==0)
04M04 0:3120b9f00d30 59 {wtv=1;}
04M04 0:3120b9f00d30 60 else
04M04 0:3120b9f00d30 61 if(wtv==1)
04M04 0:3120b9f00d30 62 {wtv=0;}
04M04 0:3120b9f00d30 63 wait(0.2);
04M04 0:3120b9f00d30 64
04M04 0:3120b9f00d30 65 }
04M04 0:3120b9f00d30 66
04M04 0:3120b9f00d30 67 int main()
04M04 0:3120b9f00d30 68 {
04M04 0:3120b9f00d30 69
04M04 0:3120b9f00d30 70 tr.rise(&ir);
04M04 0:3120b9f00d30 71 tg.rise(&ig);
04M04 0:3120b9f00d30 72 tb.rise(&ib);
04M04 0:3120b9f00d30 73 wt.rise(&wti);
04M04 0:3120b9f00d30 74
04M04 0:3120b9f00d30 75 r.period(0.001);
04M04 0:3120b9f00d30 76 g.period(0.001);
04M04 0:3120b9f00d30 77 b.period(0.001);
04M04 0:3120b9f00d30 78
04M04 0:3120b9f00d30 79 while(1)
04M04 0:3120b9f00d30 80 {
04M04 0:3120b9f00d30 81 T.start();
04M04 0:3120b9f00d30 82 if(x1==1)
04M04 0:3120b9f00d30 83 {r=1;}
04M04 0:3120b9f00d30 84 else
04M04 0:3120b9f00d30 85 if(x1==0)
04M04 0:3120b9f00d30 86 {r=0;}
04M04 0:3120b9f00d30 87
04M04 0:3120b9f00d30 88 if(x2==1)
04M04 0:3120b9f00d30 89 {g=1;}
04M04 0:3120b9f00d30 90 else
04M04 0:3120b9f00d30 91 if(x2==0)
04M04 0:3120b9f00d30 92 {g=0;}
04M04 0:3120b9f00d30 93
04M04 0:3120b9f00d30 94 if(x3==1)
04M04 0:3120b9f00d30 95 {b=1;}
04M04 0:3120b9f00d30 96 else
04M04 0:3120b9f00d30 97 if(x3==0)
04M04 0:3120b9f00d30 98 {b=0;}
04M04 0:3120b9f00d30 99
04M04 0:3120b9f00d30 100 leds = 0xFFF;
04M04 0:3120b9f00d30 101
04M04 0:3120b9f00d30 102 if(wtv==0)
04M04 0:3120b9f00d30 103 {wait(pot);}
04M04 0:3120b9f00d30 104 else
04M04 0:3120b9f00d30 105 if(wtv==1)
04M04 0:3120b9f00d30 106 {wait(licht);}
04M04 0:3120b9f00d30 107
04M04 0:3120b9f00d30 108 r=1;
04M04 0:3120b9f00d30 109 g=1;
04M04 0:3120b9f00d30 110 b=1;
04M04 0:3120b9f00d30 111
04M04 0:3120b9f00d30 112 leds = 0x0000;
04M04 0:3120b9f00d30 113
04M04 0:3120b9f00d30 114 if(wtv==0)
04M04 0:3120b9f00d30 115 {wait(pot);}
04M04 0:3120b9f00d30 116 else
04M04 0:3120b9f00d30 117 if(wtv==1)
04M04 0:3120b9f00d30 118 {wait(licht);}
04M04 0:3120b9f00d30 119
04M04 0:3120b9f00d30 120 T.stop();
04M04 0:3120b9f00d30 121 f=1/T;
04M04 0:3120b9f00d30 122 if(wtv==0)
04M04 0:3120b9f00d30 123 {pc.printf("Potentiometer Frequenz: %.2f Hz \n\r", float(f));}
04M04 0:3120b9f00d30 124 else
04M04 0:3120b9f00d30 125 if(wtv==1)
04M04 0:3120b9f00d30 126 {pc.printf("Helligkeitssensor Frequenz: %.2f Hz \n\r", float(f));}
04M04 0:3120b9f00d30 127 T.reset();
04M04 0:3120b9f00d30 128
04M04 0:3120b9f00d30 129 }
04M04 0:3120b9f00d30 130
04M04 0:3120b9f00d30 131
04M04 0:3120b9f00d30 132 }