stoppuhr s
Fork of pineingabe by
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "PinDetect.h" 00003 #include "stdlib.h" 00004 #include "TextLCD.h" 00005 // must import Cookbook PinDetct library into project 00006 // URL: http://mbed.org/users/AjK/libraries/PinDetect/lkyxpw 00007 //TST was here 00008 00009 DigitalOut myled(LED1); 00010 Timer t; 00011 TextLCD lcd(p36, p34, p9, p10, p15, p16); // rs, e, d0-d3 00012 PinDetect pb1(p18); 00013 PinDetect pb2(p19); 00014 Serial pc(USBTX, USBRX); 00015 00016 // SPST Pushbutton debounced count demo using interrupts and callback 00017 // no external PullUp resistor needed 00018 // Pushbutton from P8 to GND. 00019 // Second Pushbutton from P7 to GND. 00020 // A pb hit generates an interrupt and activates the callback function 00021 // after the switch is debounced 00022 00023 // Global count variable 00024 int volatile count=0; 00025 int volatile resetcnt=0; 00026 int volatile zz1=0; 00027 int volatile zz2=0; 00028 int volatile sblock=0; 00029 int volatile reset=0; 00030 int volatile D=0; 00031 int ms; 00032 int sec; 00033 int min; 00034 int ms1; 00035 char buffer[9]; 00036 char zwischenzeit[9]; 00037 char zwischenzeit1[9]; 00038 00039 /*Funktions Dekleration*/ 00040 void stoppuhr(void) 00041 { 00042 ms = t.read_ms(); //hole mir den TimerWert in ms 00043 sec = (ms/1000); //erzeuge mir durch division eine sekunde - aktueller Timerwert/1000 - z.b: 2548/1000=2sec 00044 ms = ms - (sec*1000); //stelle meine ms richtig 00045 min = (sec/60); //erzeuge mir Minuten 00046 sec = sec - (min*60); //stelle Sekunden richtig 00047 ms = (ms/10); 00048 ms1 = (ms/10); //erzeuge mir zwei Stellen nach komma 00049 sprintf(buffer, "%02d:%02d:%02d", min, sec, ms); //schreibe in den buffer 00050 return; 00051 } 00052 00053 void reset_halten( void ) 00054 { 00055 00056 if(sblock==1) 00057 { 00058 t.stop(); 00059 t.reset(); 00060 stoppuhr(); 00061 sprintf(zwischenzeit,"%01d:%02d:%1d", min, sec, ms1); 00062 sprintf(zwischenzeit1,"%01d:%02d:%1d", min, sec, ms1); 00063 resetcnt=0; 00064 count=0; 00065 zz1=0; 00066 zz2=0; 00067 sblock=0; 00068 D++; 00069 if(D>99){D=0;} 00070 } 00071 } 00072 00073 // Callback routine is interrupt activated by a debounced pb1 hit 00074 void pb1_hit_callback (void) { 00075 00076 ++count; //erhöhe die Variable count nach jedem drücken des Startbuttoms um 1 00077 00078 if ((resetcnt==0) && (count <= 1)&& (sblock==0)) 00079 { 00080 t.reset(); //restiere Timer 00081 t.start(); //starte Timer 00082 resetcnt=1; 00083 } 00084 else if ((resetcnt==1) && (count <= 2) && (sblock==0)) 00085 { 00086 zz1=1; 00087 sprintf(zwischenzeit,"%01d:%02d:%1d", min, sec, ms1); 00088 resetcnt=2; 00089 } 00090 else if ((resetcnt==2) && (count <= 3) && (sblock==0)) 00091 { 00092 zz2=1; 00093 sprintf(zwischenzeit1,"%01d:%02d:%1d", min, sec, ms1); 00094 } 00095 else 00096 { 00097 lcd.cls(); 00098 // wait(0.05); 00099 lcd.locate(1, 0); 00100 if(sblock==0) 00101 { 00102 00103 lcd.printf("STOPP DRUEKEN!"); 00104 wait(1); 00105 } 00106 if(sblock==1) 00107 { 00108 lcd.printf("RESET: START LANGE DRUEKEN!"); 00109 wait(1); 00110 } 00111 } 00112 resetcnt=resetcnt++; 00113 } 00114 00115 // Callback routine is interrupt activated by a debounced pb2 hit 00116 void pb2_hit_callback (void) { 00117 t.stop(); 00118 if(sblock==1) 00119 { 00120 lcd.cls(); 00121 // wait(0.05); 00122 lcd.printf("RESET: START LANGE DRUEKEN!"); 00123 wait(1); 00124 } 00125 pc.printf("Gesamtzeit: %s\n", buffer); 00126 pc.printf("Zwischenzeit: %s\n", zwischenzeit); 00127 pc.printf("Zwischenzeit: %s\n", zwischenzeit1); 00128 sblock=1; 00129 } 00130 int main() { 00131 00132 // Setup Interrupt callback functions for a pb hit 00133 pb1.attach_deasserted(&pb1_hit_callback); 00134 pb1.attach_deasserted_held(&reset_halten); 00135 pb2.attach_deasserted(&pb2_hit_callback); 00136 00137 // Start sampling pb inputs using interrupts 00138 pb1.setSampleFrequency(); 00139 pb2.setSampleFrequency(); 00140 00141 while (1) { 00142 wait(.1); 00143 lcd.cls(); 00144 myled = !myled; // LED1 blickt 00145 stoppuhr(); //rufe Funktion stoppuhr auf 00146 lcd.locate(0, 0); //setze den curser auf Zeihen 0 Reihe 1 00147 lcd.printf("D%02d", D); //Formatiere mein LCD-Ausgabe nach D00 (zwei stellen) 00148 lcd.locate(4, 0); 00149 lcd.printf("ZE:%s", buffer); 00150 if(zz1==1) 00151 { 00152 lcd.locate(0, 1); 00153 lcd.printf("A%s", zwischenzeit); 00154 } 00155 if(zz2==1) 00156 { 00157 lcd.locate(8, 1); 00158 lcd.printf("B%s", zwischenzeit1); 00159 } 00160 // wait(.1); 00161 // lcd.cls(); 00162 } 00163 00164 }
Generated on Wed Jul 20 2022 11:45:03 by
1.7.2
