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.
Fork of FeuerwehrStoppuhr by
main.cpp
00001 #include "mbed.h" 00002 #include "PinDetect.h" 00003 #include "stdlib.h" 00004 #include "TextLCD.h" 00005 00006 00007 DigitalOut myled(LED1); 00008 Timer t; 00009 TextLCD lcd(p36, p34, p24, p23, p15, p16); // rs, e, d0-d3 00010 PinDetect pb1(p18); 00011 PinDetect pb2(p19); 00012 Serial pc(USBTX, USBRX); 00013 Serial hm(p9, p10); // definiere UART für HM-TPR433 Modul 00014 DigitalOut config(p22); 00015 DigitalOut enable(p21); 00016 00017 // Global count variable 00018 int volatile count=0; 00019 int volatile resetcnt=0; 00020 int volatile zz1=0; 00021 int volatile zz2=0; 00022 int volatile sblock=0; 00023 int volatile reset=0; 00024 int volatile D=0; 00025 //int volatile send=0; 00026 int ms; 00027 int sec; 00028 int min; 00029 int ms1; 00030 char buffer[9]; 00031 char zwischenzeit[9]; 00032 char zwischenzeit1[9]; 00033 00034 /*Funktions Dekleration*/ 00035 00036 void empfangen() { 00037 // Note: you need to actually read from the serial to clear the RX interrupt 00038 00039 // send = 1; 00040 t.stop(); 00041 if(sblock==1) 00042 { 00043 lcd.cls(); 00044 lcd.printf("RESET: START LANGE DRUEKEN!"); 00045 wait(1); 00046 } 00047 pc.printf("Gesamtzeit: %s\n", buffer); 00048 pc.printf("Zwischenzeit: %s\n", zwischenzeit); 00049 pc.printf("Zwischenzeit: %s\n", zwischenzeit1); 00050 sblock=1; 00051 lcd.printf("%c\n", hm.getc()); 00052 return; 00053 } 00054 00055 void konfiguration(void) 00056 { 00057 config = 0; 00058 enable = 0; 00059 hm.printf("AA FA F0"); 00060 wait(0.1); 00061 config = 1; 00062 return; 00063 } 00064 00065 void stoppuhr(void) 00066 { 00067 ms = t.read_ms(); //hole mir den TimerWert in ms 00068 sec = (ms/1000); //erzeuge mir durch division eine sekunde - aktueller Timerwert/1000 - z.b: 2548/1000=2sec 00069 ms = ms - (sec*1000); //stelle meine ms richtig 00070 min = (sec/60); //erzeuge mir Minuten 00071 sec = sec - (min*60); //stelle Sekunden richtig 00072 ms = (ms/10); 00073 ms1 = (ms/10); //erzeuge mir zwei Stellen nach komma 00074 sprintf(buffer, "%02d:%02d:%02d", min, sec, ms); //schreibe in den buffer 00075 return; 00076 } 00077 00078 void reset_halten( void ) 00079 { 00080 if(sblock==1) 00081 { 00082 t.stop(); 00083 t.reset(); 00084 stoppuhr(); 00085 sprintf(zwischenzeit,"%01d:%02d:%1d", min, sec, ms1); 00086 sprintf(zwischenzeit1,"%01d:%02d:%1d", min, sec, ms1); 00087 resetcnt=0; 00088 count=0; 00089 zz1=0; 00090 zz2=0; 00091 sblock=0; 00092 D++; 00093 if(D>99){D=0;} 00094 } 00095 } 00096 00097 // Callback routine is interrupt activated by a debounced pb1 hit 00098 void pb1_hit_callback (void) { 00099 00100 ++count; //erhöhe die Variable count nach jedem drücken des Startbuttoms um 1 00101 00102 if ((resetcnt==0) && (count <= 1)&& (sblock==0)) 00103 { 00104 t.reset(); //restiere Timer 00105 t.start(); //starte Timer 00106 resetcnt=1; 00107 } 00108 else if ((resetcnt==1) && (count <= 2) && (sblock==0)) 00109 { 00110 zz1=1; 00111 sprintf(zwischenzeit,"%01d:%02d:%1d", min, sec, ms1); 00112 resetcnt=2; 00113 } 00114 else if ((resetcnt==2) && (count <= 3) && (sblock==0)) 00115 { 00116 zz2=1; 00117 sprintf(zwischenzeit1,"%01d:%02d:%1d", min, sec, ms1); 00118 } 00119 else 00120 { 00121 lcd.cls(); 00122 // wait(0.05); 00123 lcd.locate(1, 0); 00124 if(sblock==0) 00125 { 00126 00127 lcd.printf("STOPP DRUEKEN!"); 00128 wait(1); 00129 } 00130 if(sblock==1) 00131 { 00132 lcd.printf("RESET: START LANGE DRUEKEN!"); 00133 wait(1); 00134 } 00135 } 00136 resetcnt=resetcnt++; 00137 } 00138 /* 00139 // Callback routine is interrupt activated by a debounced pb2 hit 00140 void pb2_hit_callback (void) { 00141 t.stop(); 00142 if(sblock==1) 00143 { 00144 lcd.cls(); 00145 // wait(0.05); 00146 lcd.printf("RESET: START LANGE DRUEKEN!"); 00147 wait(1); 00148 } 00149 pc.printf("Gesamtzeit: %s\n", buffer); 00150 pc.printf("Zwischenzeit: %s\n", zwischenzeit); 00151 pc.printf("Zwischenzeit: %s\n", zwischenzeit1); 00152 sblock=1; 00153 } 00154 */ 00155 int main() { 00156 00157 konfiguration(); 00158 hm.attach(&empfangen); 00159 00160 // Setup Interrupt callback functions for a pb hit 00161 pb1.attach_deasserted(&pb1_hit_callback); 00162 pb1.attach_deasserted_held(&reset_halten); 00163 // pb2.attach_deasserted(&pb2_hit_callback); 00164 00165 // Start sampling pb inputs using interrupts 00166 pb1.setSampleFrequency(); 00167 // pb2.setSampleFrequency(); 00168 00169 00170 while (1) { 00171 wait(.1); 00172 lcd.cls(); 00173 // if(send=1){ 00174 00175 //} 00176 myled = !myled; // LED1 blickt 00177 stoppuhr(); //rufe Funktion stoppuhr auf 00178 lcd.locate(0, 0); //setze den curser auf Zeihen 0 Reihe 1 00179 lcd.printf("D%02d", D); //Formatiere mein LCD-Ausgabe nach D00 (zwei stellen) 00180 lcd.locate(4, 0); 00181 lcd.printf("ZE:%s", buffer); 00182 if(zz1==1) 00183 { 00184 lcd.locate(0, 1); 00185 lcd.printf("A%s", zwischenzeit); 00186 } 00187 if(zz2==1) 00188 { 00189 lcd.locate(8, 1); 00190 lcd.printf("B%s", zwischenzeit1); 00191 } 00192 00193 } 00194 00195 }
Generated on Wed Aug 3 2022 10:35:34 by
1.7.2
