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