Jovica D.
/
FeuerwehrStoppuhr0805
stoppuhr s
Fork of FeuerwehrStoppuhr by
main.cpp@1:3ed42298abc3, 2013-04-26 (annotated)
- Committer:
- joca89
- Date:
- Fri Apr 26 09:05:20 2013 +0000
- Revision:
- 1:3ed42298abc3
- Parent:
- 0:48f4880c730b
- Child:
- 2:9c7ca5717309
derzeitiger Stand vom Feuerwehrprojekt 26.4.2013
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fox46 | 0:48f4880c730b | 1 | #include "mbed.h" |
fox46 | 0:48f4880c730b | 2 | #include "PinDetect.h" |
joca89 | 1:3ed42298abc3 | 3 | #include "stdlib.h" |
fox46 | 0:48f4880c730b | 4 | #include "TextLCD.h" |
fox46 | 0:48f4880c730b | 5 | // must import Cookbook PinDetct library into project |
fox46 | 0:48f4880c730b | 6 | // URL: http://mbed.org/users/AjK/libraries/PinDetect/lkyxpw |
fox46 | 0:48f4880c730b | 7 | |
fox46 | 0:48f4880c730b | 8 | DigitalOut myled(LED1); |
fox46 | 0:48f4880c730b | 9 | Timer t; |
fox46 | 0:48f4880c730b | 10 | TextLCD lcd(p36, p34, p9, p10, p15, p16); // rs, e, d0-d3 |
fox46 | 0:48f4880c730b | 11 | PinDetect pb1(p18); |
fox46 | 0:48f4880c730b | 12 | PinDetect pb2(p19); |
joca89 | 1:3ed42298abc3 | 13 | Serial pc(USBTX, USBRX); |
joca89 | 1:3ed42298abc3 | 14 | |
fox46 | 0:48f4880c730b | 15 | // SPST Pushbutton debounced count demo using interrupts and callback |
fox46 | 0:48f4880c730b | 16 | // no external PullUp resistor needed |
fox46 | 0:48f4880c730b | 17 | // Pushbutton from P8 to GND. |
fox46 | 0:48f4880c730b | 18 | // Second Pushbutton from P7 to GND. |
fox46 | 0:48f4880c730b | 19 | // A pb hit generates an interrupt and activates the callback function |
fox46 | 0:48f4880c730b | 20 | // after the switch is debounced |
fox46 | 0:48f4880c730b | 21 | |
fox46 | 0:48f4880c730b | 22 | // Global count variable |
fox46 | 0:48f4880c730b | 23 | int volatile count=0; |
fox46 | 0:48f4880c730b | 24 | int volatile resetcnt=0; |
joca89 | 1:3ed42298abc3 | 25 | int volatile zz1=0; |
joca89 | 1:3ed42298abc3 | 26 | int volatile zz2=0; |
joca89 | 1:3ed42298abc3 | 27 | int volatile sblock=0; |
joca89 | 1:3ed42298abc3 | 28 | int volatile reset=0; |
joca89 | 1:3ed42298abc3 | 29 | int volatile D=0; |
joca89 | 1:3ed42298abc3 | 30 | int ms; |
joca89 | 1:3ed42298abc3 | 31 | int sec; |
joca89 | 1:3ed42298abc3 | 32 | int min; |
joca89 | 1:3ed42298abc3 | 33 | int ms1; |
joca89 | 1:3ed42298abc3 | 34 | char buffer[9]; |
joca89 | 1:3ed42298abc3 | 35 | char zwischenzeit[9]; |
joca89 | 1:3ed42298abc3 | 36 | char zwischenzeit1[9]; |
joca89 | 1:3ed42298abc3 | 37 | |
joca89 | 1:3ed42298abc3 | 38 | /*Funktions Dekleration*/ |
joca89 | 1:3ed42298abc3 | 39 | void stoppuhr(void) |
joca89 | 1:3ed42298abc3 | 40 | { |
joca89 | 1:3ed42298abc3 | 41 | ms = t.read_ms(); //hole mir den TimerWert in ms |
joca89 | 1:3ed42298abc3 | 42 | sec = (ms/1000); //erzeuge mir durch division eine sekunde - aktueller Timerwert/1000 - z.b: 2548/1000=2sec |
joca89 | 1:3ed42298abc3 | 43 | ms = ms - (sec*1000); //stelle meine ms richtig |
joca89 | 1:3ed42298abc3 | 44 | min = (sec/60); //erzeuge mir Minuten |
joca89 | 1:3ed42298abc3 | 45 | sec = sec - (min*60); //stelle Sekunden richtig |
joca89 | 1:3ed42298abc3 | 46 | ms = (ms/10); |
joca89 | 1:3ed42298abc3 | 47 | ms1 = (ms/10); //erzeuge mir zwei Stellen nach komma |
joca89 | 1:3ed42298abc3 | 48 | sprintf(buffer, "%02d:%02d:%02d", min, sec, ms); //schreibe in den buffer |
joca89 | 1:3ed42298abc3 | 49 | return; |
joca89 | 1:3ed42298abc3 | 50 | } |
joca89 | 1:3ed42298abc3 | 51 | |
joca89 | 1:3ed42298abc3 | 52 | void reset_halten( void ) |
joca89 | 1:3ed42298abc3 | 53 | { |
joca89 | 1:3ed42298abc3 | 54 | |
joca89 | 1:3ed42298abc3 | 55 | if(sblock==1) |
joca89 | 1:3ed42298abc3 | 56 | { |
joca89 | 1:3ed42298abc3 | 57 | t.stop(); |
joca89 | 1:3ed42298abc3 | 58 | t.reset(); |
joca89 | 1:3ed42298abc3 | 59 | stoppuhr(); |
joca89 | 1:3ed42298abc3 | 60 | sprintf(zwischenzeit,"%01d:%02d:%1d", min, sec, ms1); |
joca89 | 1:3ed42298abc3 | 61 | sprintf(zwischenzeit1,"%01d:%02d:%1d", min, sec, ms1); |
joca89 | 1:3ed42298abc3 | 62 | resetcnt=0; |
joca89 | 1:3ed42298abc3 | 63 | count=0; |
joca89 | 1:3ed42298abc3 | 64 | zz1=0; |
joca89 | 1:3ed42298abc3 | 65 | zz2=0; |
joca89 | 1:3ed42298abc3 | 66 | sblock=0; |
joca89 | 1:3ed42298abc3 | 67 | D++; |
joca89 | 1:3ed42298abc3 | 68 | if(D>99){D=0;} |
joca89 | 1:3ed42298abc3 | 69 | } |
joca89 | 1:3ed42298abc3 | 70 | } |
fox46 | 0:48f4880c730b | 71 | |
fox46 | 0:48f4880c730b | 72 | // Callback routine is interrupt activated by a debounced pb1 hit |
fox46 | 0:48f4880c730b | 73 | void pb1_hit_callback (void) { |
joca89 | 1:3ed42298abc3 | 74 | |
joca89 | 1:3ed42298abc3 | 75 | ++count; //erhöhe die Variable count nach jedem drücken des Startbuttoms um 1 |
joca89 | 1:3ed42298abc3 | 76 | |
joca89 | 1:3ed42298abc3 | 77 | if ((resetcnt==0) && (count <= 1)&& (sblock==0)) |
joca89 | 1:3ed42298abc3 | 78 | { |
joca89 | 1:3ed42298abc3 | 79 | t.reset(); //restiere Timer |
joca89 | 1:3ed42298abc3 | 80 | t.start(); //starte Timer |
joca89 | 1:3ed42298abc3 | 81 | resetcnt=1; |
joca89 | 1:3ed42298abc3 | 82 | } |
joca89 | 1:3ed42298abc3 | 83 | else if ((resetcnt==1) && (count <= 2) && (sblock==0)) |
joca89 | 1:3ed42298abc3 | 84 | { |
joca89 | 1:3ed42298abc3 | 85 | zz1=1; |
joca89 | 1:3ed42298abc3 | 86 | sprintf(zwischenzeit,"%01d:%02d:%1d", min, sec, ms1); |
joca89 | 1:3ed42298abc3 | 87 | resetcnt=2; |
joca89 | 1:3ed42298abc3 | 88 | } |
joca89 | 1:3ed42298abc3 | 89 | else if ((resetcnt==2) && (count <= 3) && (sblock==0)) |
joca89 | 1:3ed42298abc3 | 90 | { |
joca89 | 1:3ed42298abc3 | 91 | zz2=1; |
joca89 | 1:3ed42298abc3 | 92 | sprintf(zwischenzeit1,"%01d:%02d:%1d", min, sec, ms1); |
joca89 | 1:3ed42298abc3 | 93 | } |
joca89 | 1:3ed42298abc3 | 94 | else |
joca89 | 1:3ed42298abc3 | 95 | { |
joca89 | 1:3ed42298abc3 | 96 | lcd.cls(); |
joca89 | 1:3ed42298abc3 | 97 | // wait(0.05); |
joca89 | 1:3ed42298abc3 | 98 | lcd.locate(1, 0); |
joca89 | 1:3ed42298abc3 | 99 | if(sblock==0) |
joca89 | 1:3ed42298abc3 | 100 | { |
joca89 | 1:3ed42298abc3 | 101 | |
joca89 | 1:3ed42298abc3 | 102 | lcd.printf("STOPP DRUEKEN!"); |
joca89 | 1:3ed42298abc3 | 103 | wait(1); |
joca89 | 1:3ed42298abc3 | 104 | } |
joca89 | 1:3ed42298abc3 | 105 | if(sblock==1) |
joca89 | 1:3ed42298abc3 | 106 | { |
joca89 | 1:3ed42298abc3 | 107 | lcd.printf("RESET: START LANGE DRUEKEN!"); |
joca89 | 1:3ed42298abc3 | 108 | wait(1); |
joca89 | 1:3ed42298abc3 | 109 | } |
joca89 | 1:3ed42298abc3 | 110 | } |
joca89 | 1:3ed42298abc3 | 111 | resetcnt=resetcnt++; |
fox46 | 0:48f4880c730b | 112 | } |
joca89 | 1:3ed42298abc3 | 113 | |
fox46 | 0:48f4880c730b | 114 | // Callback routine is interrupt activated by a debounced pb2 hit |
fox46 | 0:48f4880c730b | 115 | void pb2_hit_callback (void) { |
fox46 | 0:48f4880c730b | 116 | t.stop(); |
joca89 | 1:3ed42298abc3 | 117 | if(sblock==1) |
joca89 | 1:3ed42298abc3 | 118 | { |
joca89 | 1:3ed42298abc3 | 119 | lcd.cls(); |
joca89 | 1:3ed42298abc3 | 120 | // wait(0.05); |
joca89 | 1:3ed42298abc3 | 121 | lcd.printf("RESET: START LANGE DRUEKEN!"); |
joca89 | 1:3ed42298abc3 | 122 | wait(1); |
joca89 | 1:3ed42298abc3 | 123 | } |
joca89 | 1:3ed42298abc3 | 124 | pc.printf("Gesamtzeit: %s\n", buffer); |
joca89 | 1:3ed42298abc3 | 125 | pc.printf("Zwischenzeit: %s\n", zwischenzeit); |
joca89 | 1:3ed42298abc3 | 126 | pc.printf("Zwischenzeit: %s\n", zwischenzeit1); |
joca89 | 1:3ed42298abc3 | 127 | sblock=1; |
fox46 | 0:48f4880c730b | 128 | } |
fox46 | 0:48f4880c730b | 129 | int main() { |
fox46 | 0:48f4880c730b | 130 | |
fox46 | 0:48f4880c730b | 131 | // Setup Interrupt callback functions for a pb hit |
fox46 | 0:48f4880c730b | 132 | pb1.attach_deasserted(&pb1_hit_callback); |
joca89 | 1:3ed42298abc3 | 133 | pb1.attach_deasserted_held(&reset_halten); |
fox46 | 0:48f4880c730b | 134 | pb2.attach_deasserted(&pb2_hit_callback); |
joca89 | 1:3ed42298abc3 | 135 | |
fox46 | 0:48f4880c730b | 136 | // Start sampling pb inputs using interrupts |
fox46 | 0:48f4880c730b | 137 | pb1.setSampleFrequency(); |
fox46 | 0:48f4880c730b | 138 | pb2.setSampleFrequency(); |
joca89 | 1:3ed42298abc3 | 139 | |
fox46 | 0:48f4880c730b | 140 | while (1) { |
joca89 | 1:3ed42298abc3 | 141 | wait(.1); |
joca89 | 1:3ed42298abc3 | 142 | lcd.cls(); |
joca89 | 1:3ed42298abc3 | 143 | myled = !myled; // LED1 blickt |
joca89 | 1:3ed42298abc3 | 144 | stoppuhr(); //rufe Funktion stoppuhr auf |
joca89 | 1:3ed42298abc3 | 145 | lcd.locate(0, 0); //setze den curser auf Zeihen 0 Reihe 1 |
joca89 | 1:3ed42298abc3 | 146 | lcd.printf("D%02d", D); //Formatiere mein LCD-Ausgabe nach D00 (zwei stellen) |
joca89 | 1:3ed42298abc3 | 147 | lcd.locate(4, 0); |
joca89 | 1:3ed42298abc3 | 148 | lcd.printf("ZE:%s", buffer); |
joca89 | 1:3ed42298abc3 | 149 | if(zz1==1) |
joca89 | 1:3ed42298abc3 | 150 | { |
joca89 | 1:3ed42298abc3 | 151 | lcd.locate(0, 1); |
joca89 | 1:3ed42298abc3 | 152 | lcd.printf("A%s", zwischenzeit); |
joca89 | 1:3ed42298abc3 | 153 | } |
joca89 | 1:3ed42298abc3 | 154 | if(zz2==1) |
joca89 | 1:3ed42298abc3 | 155 | { |
joca89 | 1:3ed42298abc3 | 156 | lcd.locate(8, 1); |
joca89 | 1:3ed42298abc3 | 157 | lcd.printf("B%s", zwischenzeit1); |
joca89 | 1:3ed42298abc3 | 158 | } |
joca89 | 1:3ed42298abc3 | 159 | // wait(.1); |
joca89 | 1:3ed42298abc3 | 160 | // lcd.cls(); |
fox46 | 0:48f4880c730b | 161 | } |
fox46 | 0:48f4880c730b | 162 | |
joca89 | 1:3ed42298abc3 | 163 | } |