Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of V3_ErsterVersuch by
main.cpp@0:ca528b525f28, 2014-06-04 (annotated)
- Committer:
- Stoeppke
- Date:
- Wed Jun 04 21:13:08 2014 +0000
- Revision:
- 0:ca528b525f28
- Child:
- 1:85d5fcea9bc4
Der erste, nicht getestete Ansatz. Vom Compiler akzeptiert. Auch missverst?ndlichkeiten mit BTN = 1/0 wurden von Anfang aus dem Weg ger?umt.
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); |
Stoeppke | 0:ca528b525f28 | 8 | |
Stoeppke | 0:ca528b525f28 | 9 | int jetzt=0; //schalter für alle 4 Sekunden |
Stoeppke | 0:ca528b525f28 | 10 | int BtnCheck=1; //Sicherung gegen Umschalter an-aus |
Stoeppke | 0:ca528b525f28 | 11 | |
Stoeppke | 0:ca528b525f28 | 12 | void BtnDown() |
Stoeppke | 0:ca528b525f28 | 13 | { |
Stoeppke | 0:ca528b525f28 | 14 | jetzt=1; |
Stoeppke | 0:ca528b525f28 | 15 | } |
Stoeppke | 0:ca528b525f28 | 16 | |
Stoeppke | 0:ca528b525f28 | 17 | void BtnUp() |
Stoeppke | 0:ca528b525f28 | 18 | { |
Stoeppke | 0:ca528b525f28 | 19 | BtnCheck=1; |
Stoeppke | 0:ca528b525f28 | 20 | } |
Stoeppke | 0:ca528b525f28 | 21 | |
Stoeppke | 0:ca528b525f28 | 22 | int main() |
Stoeppke | 0:ca528b525f28 | 23 | { |
Stoeppke | 0:ca528b525f28 | 24 | IrBtn1.fall(&BtnDown); |
Stoeppke | 0:ca528b525f28 | 25 | IrBtn2.fall(&BtnDown); |
Stoeppke | 0:ca528b525f28 | 26 | IrBtn1.rise(&BtnUp); |
Stoeppke | 0:ca528b525f28 | 27 | IrBtn2.rise(&BtnUp); |
Stoeppke | 0:ca528b525f28 | 28 | |
Stoeppke | 0:ca528b525f28 | 29 | int LedSw=0; //Switch welches die LED aus schaltet und veraenderungen an der Helligkeitsvariablen verhindert |
Stoeppke | 0:ca528b525f28 | 30 | int count=0; //timer absolut |
Stoeppke | 0:ca528b525f28 | 31 | int LedPwm=0; //timer 0 bis 100 fuer Led PWM |
Stoeppke | 0:ca528b525f28 | 32 | int Btn1=0, Btn2=0, Led=0; //Abgreifen der Physischen Eingaenge |
Stoeppke | 0:ca528b525f28 | 33 | int hell=50; //Helligkeitsvariable |
Stoeppke | 0:ca528b525f28 | 34 | |
Stoeppke | 0:ca528b525f28 | 35 | |
Stoeppke | 0:ca528b525f28 | 36 | while(1) { |
Stoeppke | 0:ca528b525f28 | 37 | |
Stoeppke | 0:ca528b525f28 | 38 | |
Stoeppke | 0:ca528b525f28 | 39 | //Auslesen der BTN Inputs |
Stoeppke | 0:ca528b525f28 | 40 | Btn1 = !BtnIn1; |
Stoeppke | 0:ca528b525f28 | 41 | Btn2 = !BtnIn2; |
Stoeppke | 0:ca528b525f28 | 42 | |
Stoeppke | 0:ca528b525f28 | 43 | /* |
Stoeppke | 0:ca528b525f28 | 44 | * Switch |
Stoeppke | 0:ca528b525f28 | 45 | * Led und Helliugkeits-steuerung An-Aus Schalter |
Stoeppke | 0:ca528b525f28 | 46 | */ |
Stoeppke | 0:ca528b525f28 | 47 | if (Btn1 && Btn2 && BtnCheck) { |
Stoeppke | 0:ca528b525f28 | 48 | BtnCheck= 0; //BtnCheck Variable muss in einem Interrupt BtnUp wieder auf 1 gesetzt werden!!! |
Stoeppke | 0:ca528b525f28 | 49 | LedSw = !LedSw; |
Stoeppke | 0:ca528b525f28 | 50 | } |
Stoeppke | 0:ca528b525f28 | 51 | |
Stoeppke | 0:ca528b525f28 | 52 | /* |
Stoeppke | 0:ca528b525f28 | 53 | * 4 Sekunden timer |
Stoeppke | 0:ca528b525f28 | 54 | * Loest alle 4 Sekunden aus Um langsam die Helligkeitsstufen zu durchlaufen. |
Stoeppke | 0:ca528b525f28 | 55 | */ |
Stoeppke | 0:ca528b525f28 | 56 | count++; |
Stoeppke | 0:ca528b525f28 | 57 | jetzt = (count==4000); //jetzt Variable muss in einem Interrupt BtnDown wieder auf 1 gesetzt werden. |
Stoeppke | 0:ca528b525f28 | 58 | count = count * !(jetzt); |
Stoeppke | 0:ca528b525f28 | 59 | |
Stoeppke | 0:ca528b525f28 | 60 | /* |
Stoeppke | 0:ca528b525f28 | 61 | * Heller Dunkler |
Stoeppke | 0:ca528b525f28 | 62 | * Veraenderung der Helligkeitsvariablen |
Stoeppke | 0:ca528b525f28 | 63 | */ |
Stoeppke | 0:ca528b525f28 | 64 | hell = hell + (Btn2 && LedSw && jetzt && (hell<=99)); |
Stoeppke | 0:ca528b525f28 | 65 | hell = hell - (Btn1 && LedSw && jetzt && (hell>=1)); |
Stoeppke | 0:ca528b525f28 | 66 | |
Stoeppke | 0:ca528b525f28 | 67 | /* |
Stoeppke | 0:ca528b525f28 | 68 | * PWM Timer |
Stoeppke | 0:ca528b525f28 | 69 | * Timer von 0 bis 100 um die LED leuchten zu lassen. |
Stoeppke | 0:ca528b525f28 | 70 | * Die Led ist nur an wenn sie nicht via LedSw aus geschaltet ist und die Helligkeitsvariable groesser dem PWM Timer ist. |
Stoeppke | 0:ca528b525f28 | 71 | */ |
Stoeppke | 0:ca528b525f28 | 72 | LedPwm++; |
Stoeppke | 0:ca528b525f28 | 73 | LedPwm = LedPwm * !(100==LedPwm); |
Stoeppke | 0:ca528b525f28 | 74 | Led = LedSw && (LedPwm<hell); |
Stoeppke | 0:ca528b525f28 | 75 | |
Stoeppke | 0:ca528b525f28 | 76 | //zuweisen auf LED Output |
Stoeppke | 0:ca528b525f28 | 77 | LedOut=Led; |
Stoeppke | 0:ca528b525f28 | 78 | |
Stoeppke | 0:ca528b525f28 | 79 | wait_ms(1); |
Stoeppke | 0:ca528b525f28 | 80 | |
Stoeppke | 0:ca528b525f28 | 81 | } |
Stoeppke | 0:ca528b525f28 | 82 | } |