Jack Hansdampf / Mbed OS Ampel
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2019 ARM Limited
00003  * SPDX-License-Identifier: Apache-2.0
00004  */
00005 
00006 #include "mbed.h"
00007 #include "platform/mbed_thread.h"
00008 
00009 
00010 // Blinking rate in milliseconds
00011 #define BLINKING_RATE_MS                                                    500
00012 
00013 bool angefordert=false;
00014 
00015 char phasen[10]= {
00016     0b01001001, //0 rot - rot - rot
00017     0b01001101, //1 rot - rot - rotgelb
00018     0b01001010, //2 rot - rot - grün
00019     0b01001100, //3 rot - rot - gelb
00020     0b01001001, //4 rot - rot - rot
00021     0b01101001, //5 rot - rotgelb - rot 
00022     0b01010001, //6 rot - grün - rot
00023     0b01100001, //7 rot - gleb - rot
00024     0b01001001, //8 rot - rot - rot
00025     0b10001001}; //9 grün - rot - rot
00026 
00027 void anfordern(void)
00028 {
00029    angefordert=true; 
00030 }
00031 
00032 int main()
00033 {
00034     // Initialise the digital pin LED1 as an output
00035     int z=0;
00036     InterruptIn anforderung(PA_1);
00037     anforderung.mode(PullDown);
00038     PortOut ampel(PortC,0xFF);
00039     anforderung.rise(&anfordern);
00040 
00041     while (true) {
00042         ampel=phasen[z];
00043         thread_sleep_for(BLINKING_RATE_MS);
00044         if ((z==0||z==4||z==8)&&angefordert)
00045         {          
00046             ampel=phasen[9];
00047             thread_sleep_for(BLINKING_RATE_MS);
00048             angefordert=false;
00049         }
00050         z++;
00051         if (z>8) z=0;
00052         
00053     }
00054 }