Umschalten der Leuchtdauer mittels Knöpfen...
Dependencies: mbed
main.cpp@1:85d5fcea9bc4, 2014-06-05 (annotated)
- Committer:
- Sneid
- Date:
- Thu Jun 05 10:36:45 2014 +0000
- Revision:
- 1:85d5fcea9bc4
- Parent:
- 0:ca528b525f28
asd
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Stoeppke | 0:ca528b525f28 | 1 | #include "mbed.h" |
Stoeppke | 0:ca528b525f28 | 2 | |
Stoeppke | 0:ca528b525f28 | 3 | DigitalOut LedOut(P1_18); |
Stoeppke | 0:ca528b525f28 | 4 | DigitalIn BtnIn1(p8); |
Stoeppke | 0:ca528b525f28 | 5 | DigitalIn BtnIn2(p14); |
Stoeppke | 0:ca528b525f28 | 6 | InterruptIn IrBtn1(p8); |
Stoeppke | 0:ca528b525f28 | 7 | InterruptIn IrBtn2(p14); |
Sneid | 1:85d5fcea9bc4 | 8 | DigitalOut PeepOut(P2_5); |
Sneid | 1:85d5fcea9bc4 | 9 | |
Sneid | 1:85d5fcea9bc4 | 10 | #define PEEP |
Stoeppke | 0:ca528b525f28 | 11 | |
Stoeppke | 0:ca528b525f28 | 12 | int jetzt=0; //schalter für alle 4 Sekunden |
Stoeppke | 0:ca528b525f28 | 13 | int BtnCheck=1; //Sicherung gegen Umschalter an-aus |
Stoeppke | 0:ca528b525f28 | 14 | |
Stoeppke | 0:ca528b525f28 | 15 | void BtnDown() |
Stoeppke | 0:ca528b525f28 | 16 | { |
Stoeppke | 0:ca528b525f28 | 17 | jetzt=1; |
Stoeppke | 0:ca528b525f28 | 18 | } |
Stoeppke | 0:ca528b525f28 | 19 | |
Stoeppke | 0:ca528b525f28 | 20 | void BtnUp() |
Stoeppke | 0:ca528b525f28 | 21 | { |
Stoeppke | 0:ca528b525f28 | 22 | BtnCheck=1; |
Stoeppke | 0:ca528b525f28 | 23 | } |
Stoeppke | 0:ca528b525f28 | 24 | |
Stoeppke | 0:ca528b525f28 | 25 | int main() |
Stoeppke | 0:ca528b525f28 | 26 | { |
Stoeppke | 0:ca528b525f28 | 27 | IrBtn1.fall(&BtnDown); |
Stoeppke | 0:ca528b525f28 | 28 | IrBtn2.fall(&BtnDown); |
Stoeppke | 0:ca528b525f28 | 29 | IrBtn1.rise(&BtnUp); |
Stoeppke | 0:ca528b525f28 | 30 | IrBtn2.rise(&BtnUp); |
Stoeppke | 0:ca528b525f28 | 31 | |
Stoeppke | 0:ca528b525f28 | 32 | int LedSw=0; //Switch welches die LED aus schaltet und veraenderungen an der Helligkeitsvariablen verhindert |
Stoeppke | 0:ca528b525f28 | 33 | int count=0; //timer absolut |
Sneid | 1:85d5fcea9bc4 | 34 | int LedPwm=0, PeepPwm=0; //timer 0 bis 100 fuer Led PWM |
Sneid | 1:85d5fcea9bc4 | 35 | int Btn1=0, Btn2=0, Led=0, Peep=0; //Abgreifen der Physischen Eingaenge |
Sneid | 1:85d5fcea9bc4 | 36 | int hell=50, freq=700; //Helligkeitsvariable |
Sneid | 1:85d5fcea9bc4 | 37 | |
Stoeppke | 0:ca528b525f28 | 38 | |
Stoeppke | 0:ca528b525f28 | 39 | while(1) { |
Stoeppke | 0:ca528b525f28 | 40 | |
Stoeppke | 0:ca528b525f28 | 41 | |
Stoeppke | 0:ca528b525f28 | 42 | //Auslesen der BTN Inputs |
Stoeppke | 0:ca528b525f28 | 43 | Btn1 = !BtnIn1; |
Stoeppke | 0:ca528b525f28 | 44 | Btn2 = !BtnIn2; |
Stoeppke | 0:ca528b525f28 | 45 | |
Stoeppke | 0:ca528b525f28 | 46 | /* |
Stoeppke | 0:ca528b525f28 | 47 | * Switch |
Stoeppke | 0:ca528b525f28 | 48 | * Led und Helliugkeits-steuerung An-Aus Schalter |
Stoeppke | 0:ca528b525f28 | 49 | */ |
Stoeppke | 0:ca528b525f28 | 50 | if (Btn1 && Btn2 && BtnCheck) { |
Stoeppke | 0:ca528b525f28 | 51 | BtnCheck= 0; //BtnCheck Variable muss in einem Interrupt BtnUp wieder auf 1 gesetzt werden!!! |
Stoeppke | 0:ca528b525f28 | 52 | LedSw = !LedSw; |
Stoeppke | 0:ca528b525f28 | 53 | } |
Stoeppke | 0:ca528b525f28 | 54 | |
Stoeppke | 0:ca528b525f28 | 55 | /* |
Stoeppke | 0:ca528b525f28 | 56 | * 4 Sekunden timer |
Stoeppke | 0:ca528b525f28 | 57 | * Loest alle 4 Sekunden aus Um langsam die Helligkeitsstufen zu durchlaufen. |
Stoeppke | 0:ca528b525f28 | 58 | */ |
Stoeppke | 0:ca528b525f28 | 59 | count++; |
Sneid | 1:85d5fcea9bc4 | 60 | jetzt = (count==20000); //jetzt Variable muss in einem Interrupt BtnDown wieder auf 1 gesetzt werden. |
Stoeppke | 0:ca528b525f28 | 61 | count = count * !(jetzt); |
Stoeppke | 0:ca528b525f28 | 62 | |
Stoeppke | 0:ca528b525f28 | 63 | /* |
Stoeppke | 0:ca528b525f28 | 64 | * Heller Dunkler |
Stoeppke | 0:ca528b525f28 | 65 | * Veraenderung der Helligkeitsvariablen |
Stoeppke | 0:ca528b525f28 | 66 | */ |
Sneid | 1:85d5fcea9bc4 | 67 | hell = hell + (Btn2 && LedSw && jetzt && (hell<99)); |
Stoeppke | 0:ca528b525f28 | 68 | hell = hell - (Btn1 && LedSw && jetzt && (hell>=1)); |
Sneid | 1:85d5fcea9bc4 | 69 | //Hier folgt der frequenzveraenderer, leider noch nicht fertig |
Sneid | 1:85d5fcea9bc4 | 70 | #ifdef PEEP |
Sneid | 1:85d5fcea9bc4 | 71 | freq = freq + (Btn2 && !LedSw && jetzt && (freq<1000)); |
Sneid | 1:85d5fcea9bc4 | 72 | freq = freq - (Btn1 && !LedSw && jetzt && (freq>400)); |
Sneid | 1:85d5fcea9bc4 | 73 | #endif |
Stoeppke | 0:ca528b525f28 | 74 | |
Stoeppke | 0:ca528b525f28 | 75 | /* |
Stoeppke | 0:ca528b525f28 | 76 | * PWM Timer |
Stoeppke | 0:ca528b525f28 | 77 | * Timer von 0 bis 100 um die LED leuchten zu lassen. |
Stoeppke | 0:ca528b525f28 | 78 | * Die Led ist nur an wenn sie nicht via LedSw aus geschaltet ist und die Helligkeitsvariable groesser dem PWM Timer ist. |
Stoeppke | 0:ca528b525f28 | 79 | */ |
Stoeppke | 0:ca528b525f28 | 80 | LedPwm++; |
Stoeppke | 0:ca528b525f28 | 81 | LedPwm = LedPwm * !(100==LedPwm); |
Stoeppke | 0:ca528b525f28 | 82 | Led = LedSw && (LedPwm<hell); |
Sneid | 1:85d5fcea9bc4 | 83 | |
Sneid | 1:85d5fcea9bc4 | 84 | #ifdef PEEP |
Sneid | 1:85d5fcea9bc4 | 85 | /* |
Sneid | 1:85d5fcea9bc4 | 86 | * Bullshit |
Sneid | 1:85d5fcea9bc4 | 87 | * hier folgt der Peeper und aller anderer Misst |
Sneid | 1:85d5fcea9bc4 | 88 | */ |
Sneid | 1:85d5fcea9bc4 | 89 | PeepPwm++; |
Sneid | 1:85d5fcea9bc4 | 90 | PeepPwm = LedPwm * !(freq==LedPwm); |
Sneid | 1:85d5fcea9bc4 | 91 | Peep = !LedSw && (LedPwm<hell); |
Sneid | 1:85d5fcea9bc4 | 92 | PeepOut=Peep; |
Sneid | 1:85d5fcea9bc4 | 93 | #endif |
Stoeppke | 0:ca528b525f28 | 94 | //zuweisen auf LED Output |
Stoeppke | 0:ca528b525f28 | 95 | LedOut=Led; |
Sneid | 1:85d5fcea9bc4 | 96 | |
Stoeppke | 0:ca528b525f28 | 97 | |
Sneid | 1:85d5fcea9bc4 | 98 | wait_us(1); |
Stoeppke | 0:ca528b525f28 | 99 | |
Stoeppke | 0:ca528b525f28 | 100 | } |
Stoeppke | 0:ca528b525f28 | 101 | } |