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.
main.cpp@0:a082d4766316, 2018-11-15 (annotated)
- Committer:
- martwerl
- Date:
- Thu Nov 15 17:57:17 2018 +0000
- Revision:
- 0:a082d4766316
Btn_Runlight_Polling
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| martwerl | 0:a082d4766316 | 1 | #include "mbed.h" |
| martwerl | 0:a082d4766316 | 2 | |
| martwerl | 0:a082d4766316 | 3 | //Lauflicht, das sich bei jedem Button-Click um 1 weiterbewegt |
| martwerl | 0:a082d4766316 | 4 | //Das ist die Polling Lösung |
| martwerl | 0:a082d4766316 | 5 | |
| martwerl | 0:a082d4766316 | 6 | // LSB MSB |
| martwerl | 0:a082d4766316 | 7 | // 2^0 2^1 2^2 2^11 |
| martwerl | 0:a082d4766316 | 8 | BusOut lb(P1_13,P1_12,P1_7,P1_6,P1_4,P1_3,P1_1,P1_0,LED4,LED3,LED2,LED1); // Ausgabe für eine Bit Gruppe |
| martwerl | 0:a082d4766316 | 9 | // D20 D19 D18 D17 D16 D15 D14 D13 D4 D3 D2 D1 |
| martwerl | 0:a082d4766316 | 10 | // SW1 SW2 SW3 SW4 |
| martwerl | 0:a082d4766316 | 11 | // Bit0 Bit1 Bit2 Bit3 |
| martwerl | 0:a082d4766316 | 12 | //BusIn btn(P0_10,P0_15,P0_23,P1_16); //Ausgabe für eine Bitgruppe |
| martwerl | 0:a082d4766316 | 13 | |
| martwerl | 0:a082d4766316 | 14 | DigitalIn sw4(P1_16); //Taster |
| martwerl | 0:a082d4766316 | 15 | int PrevSW4 = 0;//Schalterzustand, wie er bei der letzten Abfrage war |
| martwerl | 0:a082d4766316 | 16 | |
| martwerl | 0:a082d4766316 | 17 | void OneRunLightStep(); //einen Schritt eines Lauflichts ausführen |
| martwerl | 0:a082d4766316 | 18 | int CheckButton(); |
| martwerl | 0:a082d4766316 | 19 | |
| martwerl | 0:a082d4766316 | 20 | |
| martwerl | 0:a082d4766316 | 21 | int main() |
| martwerl | 0:a082d4766316 | 22 | { |
| martwerl | 0:a082d4766316 | 23 | lb = 1; |
| martwerl | 0:a082d4766316 | 24 | while(1) { |
| martwerl | 0:a082d4766316 | 25 | if(CheckButton() ) |
| martwerl | 0:a082d4766316 | 26 | OneRunLightStep(); |
| martwerl | 0:a082d4766316 | 27 | } |
| martwerl | 0:a082d4766316 | 28 | } |
| martwerl | 0:a082d4766316 | 29 | |
| martwerl | 0:a082d4766316 | 30 | int CheckButton() |
| martwerl | 0:a082d4766316 | 31 | { |
| martwerl | 0:a082d4766316 | 32 | int ret = 0; |
| martwerl | 0:a082d4766316 | 33 | if(sw4 == 1 && PrevSW4 == 0)//Taster gedrückt und alter Schalterzustand 0 |
| martwerl | 0:a082d4766316 | 34 | ret = 1; |
| martwerl | 0:a082d4766316 | 35 | else |
| martwerl | 0:a082d4766316 | 36 | ret = 0; |
| martwerl | 0:a082d4766316 | 37 | PrevSW4 = sw4; //alten Schalterzustand merken |
| martwerl | 0:a082d4766316 | 38 | return ret;//wenn 1 retouniert wird, wird Funktion OneRunLightStep() aufgerufen |
| martwerl | 0:a082d4766316 | 39 | } |
| martwerl | 0:a082d4766316 | 40 | |
| martwerl | 0:a082d4766316 | 41 | |
| martwerl | 0:a082d4766316 | 42 | void OneRunLightStep() |
| martwerl | 0:a082d4766316 | 43 | { |
| martwerl | 0:a082d4766316 | 44 | if(lb == 0)//wenns finster ist... |
| martwerl | 0:a082d4766316 | 45 | lb = 1;//einschalten |
| martwerl | 0:a082d4766316 | 46 | else |
| martwerl | 0:a082d4766316 | 47 | lb = lb << 1;//...um 1 nach links schieben |
| martwerl | 0:a082d4766316 | 48 | } |