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
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 #include "LCD.h" 00009 #include <string> 00010 00011 00012 // Blinking rate in milliseconds 00013 #define BLINKING_RATE_MS 500 00014 00015 #define Init 0 00016 #define Geschlossen 1 00017 #define Oeffnen 2 00018 #define Offen 3 00019 #define Schliessen 4 00020 #define Gestoppt 5 00021 lcd mylcd; 00022 DigitalIn TorOeffnen(PA_1); 00023 DigitalIn TorSchliessen(PA_6); 00024 InterruptIn Lichtschranke(PA_10); 00025 DigitalIn EndschalterOffen(PB_0); 00026 DigitalIn EndschalterZu(PB_3); 00027 PwmOut heben(PC_6); 00028 PwmOut senken(PC_7); 00029 AnalogIn Geschwindigkeit(PA_0); 00030 DigitalOut Warnleuchte(PC_0); 00031 00032 int zustand=Init; 00033 float tastgrad; 00034 string meldung[]={"Tor-offen","Tor-zu","Tor-gestoppt","Tor-faehrt"}; 00035 00036 void blinkenEin() 00037 { 00038 TIM6->CR1=1; 00039 } 00040 00041 void blinkenAus() 00042 { 00043 TIM6->CR1=0; 00044 Warnleuchte=0; 00045 } 00046 00047 void isrTimer() 00048 { 00049 TIM6->SR=0; 00050 Warnleuchte=!Warnleuchte; 00051 } 00052 00053 void initTimer() 00054 { 00055 RCC->APB1ENR |= 0b10000; //TIM6 00056 TIM6->PSC=31999; //1ms 00057 TIM6->ARR=499; //500ms 00058 TIM6->CNT=0; //Counter startet bei 0 00059 TIM6->SR=0; //UIF =0 00060 TIM6->DIER=1; //Interrupt Freigabe 00061 NVIC_SetVector(TIM6_IRQn,(uint32_t)&isrTimer); 00062 HAL_NVIC_EnableIRQ(TIM6_IRQn); 00063 __enable_irq(); 00064 } 00065 00066 void oeffnen() 00067 { 00068 senken=0; 00069 heben=Geschwindigkeit; 00070 } 00071 00072 void schliessen() 00073 { 00074 heben=0; 00075 senken=Geschwindigkeit; 00076 } 00077 00078 void lcdOut(int nr) 00079 { 00080 mylcd.clear(); 00081 mylcd.cursorpos(0); 00082 mylcd.printf("%s",meldung[nr].c_str()); 00083 } 00084 00085 void motorstop() 00086 { 00087 heben=0; 00088 senken=0; 00089 } 00090 00091 void normaleFrequenz() 00092 { 00093 TIM6->ARR=499; //500ms 00094 } 00095 00096 void doppelteFrequenz() 00097 { 00098 TIM6->CNT=0; //Counter startet bei 0 00099 TIM6->ARR=249; //250ms 00100 00101 } 00102 void schnellstop() 00103 { 00104 if (zustand==Schliessen || zustand==Oeffnen) 00105 { 00106 zustand=Gestoppt; 00107 lcdOut(2); 00108 doppelteFrequenz(); 00109 } 00110 } 00111 00112 void init() 00113 { 00114 TorOeffnen.mode(PullDown); 00115 TorSchliessen.mode(PullDown); 00116 Lichtschranke.mode(PullDown); 00117 EndschalterOffen.mode(PullDown); 00118 EndschalterZu.mode(PullDown); 00119 Lichtschranke.fall(&schnellstop); 00120 Lichtschranke.enable_irq(); 00121 __enable_irq(); 00122 heben.period_us(100); 00123 senken.period_us(100); 00124 initTimer(); 00125 00126 } 00127 00128 00129 int main() 00130 { 00131 while (true) { 00132 switch(zustand) 00133 { 00134 case Init: 00135 init(); 00136 zustand=Geschlossen; 00137 motorstop(); 00138 lcdOut(1); 00139 break; 00140 case Geschlossen: if (TorOeffnen==1) 00141 { 00142 zustand=Oeffnen; 00143 blinkenEin(); 00144 lcdOut(3); 00145 } 00146 break; 00147 case Oeffnen: 00148 oeffnen(); 00149 if (EndschalterOffen==1) 00150 { 00151 blinkenAus(); 00152 zustand=Offen; 00153 motorstop(); 00154 lcdOut(0); 00155 } 00156 break; 00157 case Offen: if (TorSchliessen==1) 00158 { 00159 zustand=Schliessen; 00160 blinkenEin(); 00161 lcdOut(3); 00162 } 00163 break; 00164 case Schliessen: 00165 schliessen(); 00166 if (EndschalterZu==1) 00167 { 00168 zustand=Geschlossen; 00169 lcdOut(1); 00170 motorstop(); 00171 blinkenAus(); 00172 } 00173 break; 00174 case Gestoppt: 00175 motorstop(); 00176 if (TorOeffnen==1) 00177 { 00178 lcdOut(3); 00179 zustand=Oeffnen; 00180 blinkenEin(); 00181 normaleFrequenz(); 00182 } 00183 if (TorSchliessen==1) 00184 { 00185 lcdOut(3); 00186 zustand=Schliessen; 00187 blinkenEin(); 00188 normaleFrequenz(); 00189 } 00190 break; 00191 } 00192 HAL_Delay(20); 00193 } 00194 }
Generated on Sat Aug 6 2022 15:28:27 by
1.7.2