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.
E5_Lekt1_HexLeds_Digitalio.cpp@0:b4e3ba4a7bd3, 2020-01-12 (annotated)
- Committer:
- robertbuc
- Date:
- Sun Jan 12 21:58:09 2020 +0000
- Revision:
- 0:b4e3ba4a7bd3
Digitalio
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| robertbuc | 0:b4e3ba4a7bd3 | 1 | /* |
| robertbuc | 0:b4e3ba4a7bd3 | 2 | 5. [HexLeds] Erzeuge das folgende HexLeds Programm für vier Leds und folgenden Funktionen: |
| robertbuc | 0:b4e3ba4a7bd3 | 3 | |
| robertbuc | 0:b4e3ba4a7bd3 | 4 | main() { |
| robertbuc | 0:b4e3ba4a7bd3 | 5 | hexleds.eingabe() // einlesen eines Integer-Wertes von der Tastatur mit scanf("%d", &ein); |
| robertbuc | 0:b4e3ba4a7bd3 | 6 | hexleds.ausgabe() // ausgeben des Integer-Wertes der von der Tastatur eingegeben wurde |
| robertbuc | 0:b4e3ba4a7bd3 | 7 | hexleds.hexOut() // Ausgabe des Wertes in Hex-Darstellung an den 4 Leds |
| robertbuc | 0:b4e3ba4a7bd3 | 8 | hexleds.printStatus() // Anzeigen ob Leds ein oder aus |
| robertbuc | 0:b4e3ba4a7bd3 | 9 | */ |
| robertbuc | 0:b4e3ba4a7bd3 | 10 | #include "mbed.h" |
| robertbuc | 0:b4e3ba4a7bd3 | 11 | |
| robertbuc | 0:b4e3ba4a7bd3 | 12 | //BusOut leds(D0,D3,D6,D9,D11,D12,A1,A5); |
| robertbuc | 0:b4e3ba4a7bd3 | 13 | BusOut leds(D0,D3,D6,D9); |
| robertbuc | 0:b4e3ba4a7bd3 | 14 | |
| robertbuc | 0:b4e3ba4a7bd3 | 15 | int hexleds_eingabe(int eingabe); |
| robertbuc | 0:b4e3ba4a7bd3 | 16 | int hexleds_ausgabe(int ausgabe); |
| robertbuc | 0:b4e3ba4a7bd3 | 17 | int hexleds_hexout(int hexout); |
| robertbuc | 0:b4e3ba4a7bd3 | 18 | int hexleds_printstatus(int value); |
| robertbuc | 0:b4e3ba4a7bd3 | 19 | |
| robertbuc | 0:b4e3ba4a7bd3 | 20 | int main() |
| robertbuc | 0:b4e3ba4a7bd3 | 21 | { |
| robertbuc | 0:b4e3ba4a7bd3 | 22 | int value=0; |
| robertbuc | 0:b4e3ba4a7bd3 | 23 | while(1) |
| robertbuc | 0:b4e3ba4a7bd3 | 24 | { |
| robertbuc | 0:b4e3ba4a7bd3 | 25 | value=hexleds_eingabe(value); |
| robertbuc | 0:b4e3ba4a7bd3 | 26 | hexleds_ausgabe(value); |
| robertbuc | 0:b4e3ba4a7bd3 | 27 | hexleds_hexout(value); |
| robertbuc | 0:b4e3ba4a7bd3 | 28 | hexleds_printstatus(value); |
| robertbuc | 0:b4e3ba4a7bd3 | 29 | } |
| robertbuc | 0:b4e3ba4a7bd3 | 30 | } |
| robertbuc | 0:b4e3ba4a7bd3 | 31 | |
| robertbuc | 0:b4e3ba4a7bd3 | 32 | |
| robertbuc | 0:b4e3ba4a7bd3 | 33 | int hexleds_printstatus(int kontrolle) |
| robertbuc | 0:b4e3ba4a7bd3 | 34 | { |
| robertbuc | 0:b4e3ba4a7bd3 | 35 | if(leds=kontrolle) |
| robertbuc | 0:b4e3ba4a7bd3 | 36 | { |
| robertbuc | 0:b4e3ba4a7bd3 | 37 | printf("alles leuchtet\n"); |
| robertbuc | 0:b4e3ba4a7bd3 | 38 | } |
| robertbuc | 0:b4e3ba4a7bd3 | 39 | else |
| robertbuc | 0:b4e3ba4a7bd3 | 40 | { |
| robertbuc | 0:b4e3ba4a7bd3 | 41 | printf("alles falsch\n"); |
| robertbuc | 0:b4e3ba4a7bd3 | 42 | } |
| robertbuc | 0:b4e3ba4a7bd3 | 43 | return kontrolle; |
| robertbuc | 0:b4e3ba4a7bd3 | 44 | } |
| robertbuc | 0:b4e3ba4a7bd3 | 45 | |
| robertbuc | 0:b4e3ba4a7bd3 | 46 | int hexleds_hexout(int hexout) |
| robertbuc | 0:b4e3ba4a7bd3 | 47 | { |
| robertbuc | 0:b4e3ba4a7bd3 | 48 | leds=hexout; |
| robertbuc | 0:b4e3ba4a7bd3 | 49 | return hexout; |
| robertbuc | 0:b4e3ba4a7bd3 | 50 | } |
| robertbuc | 0:b4e3ba4a7bd3 | 51 | |
| robertbuc | 0:b4e3ba4a7bd3 | 52 | int hexleds_ausgabe(int ausgabe) |
| robertbuc | 0:b4e3ba4a7bd3 | 53 | { |
| robertbuc | 0:b4e3ba4a7bd3 | 54 | printf("Wert: %d\n",ausgabe); |
| robertbuc | 0:b4e3ba4a7bd3 | 55 | return ausgabe; |
| robertbuc | 0:b4e3ba4a7bd3 | 56 | } |
| robertbuc | 0:b4e3ba4a7bd3 | 57 | |
| robertbuc | 0:b4e3ba4a7bd3 | 58 | int hexleds_eingabe(int eingabe) |
| robertbuc | 0:b4e3ba4a7bd3 | 59 | { |
| robertbuc | 0:b4e3ba4a7bd3 | 60 | eingabe=0xE; |
| robertbuc | 0:b4e3ba4a7bd3 | 61 | return eingabe; |
| robertbuc | 0:b4e3ba4a7bd3 | 62 | } |