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:c635b2c93ead, 2021-12-15 (annotated)
- Committer:
- thomasheck
- Date:
- Wed Dec 15 10:15:07 2021 +0000
- Revision:
- 0:c635b2c93ead
LFB - Erstes MBED-Beispiel
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| thomasheck | 0:c635b2c93ead | 1 | /* mbed Microcontroller Library |
| thomasheck | 0:c635b2c93ead | 2 | * Copyright (c) 2019 ARM Limited |
| thomasheck | 0:c635b2c93ead | 3 | * SPDX-License-Identifier: Apache-2.0 |
| thomasheck | 0:c635b2c93ead | 4 | */ |
| thomasheck | 0:c635b2c93ead | 5 | |
| thomasheck | 0:c635b2c93ead | 6 | #include "mbed.h" |
| thomasheck | 0:c635b2c93ead | 7 | #include "platform/mbed_thread.h" |
| thomasheck | 0:c635b2c93ead | 8 | #include "LCD.h" |
| thomasheck | 0:c635b2c93ead | 9 | |
| thomasheck | 0:c635b2c93ead | 10 | // Blinking rate in milliseconds |
| thomasheck | 0:c635b2c93ead | 11 | #define BLINKING_RATE_MS 500 |
| thomasheck | 0:c635b2c93ead | 12 | int zaehler=0; |
| thomasheck | 0:c635b2c93ead | 13 | DigitalOut statusled(PC_0); |
| thomasheck | 0:c635b2c93ead | 14 | PortOut reste(PortC,0b11111110); |
| thomasheck | 0:c635b2c93ead | 15 | PortOut alle(PortC,0b11111111); |
| thomasheck | 0:c635b2c93ead | 16 | DigitalIn taste(PA_1); |
| thomasheck | 0:c635b2c93ead | 17 | InterruptIn taste2(PA_10); |
| thomasheck | 0:c635b2c93ead | 18 | lcd meinLCD; |
| thomasheck | 0:c635b2c93ead | 19 | |
| thomasheck | 0:c635b2c93ead | 20 | void isr() //Interrupt-Service-Routine |
| thomasheck | 0:c635b2c93ead | 21 | { |
| thomasheck | 0:c635b2c93ead | 22 | statusled=0; |
| thomasheck | 0:c635b2c93ead | 23 | reste=0b11111111; |
| thomasheck | 0:c635b2c93ead | 24 | } |
| thomasheck | 0:c635b2c93ead | 25 | |
| thomasheck | 0:c635b2c93ead | 26 | |
| thomasheck | 0:c635b2c93ead | 27 | int main() |
| thomasheck | 0:c635b2c93ead | 28 | { |
| thomasheck | 0:c635b2c93ead | 29 | // Initialise the digital pin LED1 as an output |
| thomasheck | 0:c635b2c93ead | 30 | DigitalOut led(LED1); |
| thomasheck | 0:c635b2c93ead | 31 | PortIn schalterchen (PortB,0b11111111); |
| thomasheck | 0:c635b2c93ead | 32 | taste.mode(PullDown); //die Grundplatine benötigt bei Eingängen PullDown) |
| thomasheck | 0:c635b2c93ead | 33 | schalterchen.mode(PullDown); |
| thomasheck | 0:c635b2c93ead | 34 | taste2.mode(PullDown); //Interrupt-Definitionen |
| thomasheck | 0:c635b2c93ead | 35 | taste2.rise(&isr); //taste2.fall für fallende Flanke |
| thomasheck | 0:c635b2c93ead | 36 | taste2.enable_irq(); |
| thomasheck | 0:c635b2c93ead | 37 | __enable_irq(); //globale Freigabe |
| thomasheck | 0:c635b2c93ead | 38 | statusled=1; |
| thomasheck | 0:c635b2c93ead | 39 | meinLCD.clear(); |
| thomasheck | 0:c635b2c93ead | 40 | meinLCD.cursorpos(0x40); |
| thomasheck | 0:c635b2c93ead | 41 | meinLCD.printf("Urlaubsbaron"); |
| thomasheck | 0:c635b2c93ead | 42 | AnalogIn poti(PA_0); |
| thomasheck | 0:c635b2c93ead | 43 | |
| thomasheck | 0:c635b2c93ead | 44 | |
| thomasheck | 0:c635b2c93ead | 45 | while (true) { |
| thomasheck | 0:c635b2c93ead | 46 | led = !led; |
| thomasheck | 0:c635b2c93ead | 47 | zaehler++; |
| thomasheck | 0:c635b2c93ead | 48 | meinLCD.cursorpos(0); |
| thomasheck | 0:c635b2c93ead | 49 | meinLCD.printf("Zaehler= %d" ,zaehler); |
| thomasheck | 0:c635b2c93ead | 50 | if (poti>0.5) statusled=1; |
| thomasheck | 0:c635b2c93ead | 51 | else |
| thomasheck | 0:c635b2c93ead | 52 | { |
| thomasheck | 0:c635b2c93ead | 53 | statusled=0; |
| thomasheck | 0:c635b2c93ead | 54 | alle=schalterchen; |
| thomasheck | 0:c635b2c93ead | 55 | } |
| thomasheck | 0:c635b2c93ead | 56 | if(taste==1){statusled=0;} |
| thomasheck | 0:c635b2c93ead | 57 | thread_sleep_for(BLINKING_RATE_MS); |
| thomasheck | 0:c635b2c93ead | 58 | } |
| thomasheck | 0:c635b2c93ead | 59 | } |