Jovica D.
/
FeuerwehrStoppuhr
stoppuhr s
Fork of pineingabe by
Diff: main.cpp
- Revision:
- 1:3ed42298abc3
- Parent:
- 0:48f4880c730b
- Child:
- 2:9c7ca5717309
--- a/main.cpp Fri Apr 19 18:36:29 2013 +0000 +++ b/main.cpp Fri Apr 26 09:05:20 2013 +0000 @@ -1,18 +1,17 @@ #include "mbed.h" #include "PinDetect.h" +#include "stdlib.h" #include "TextLCD.h" // must import Cookbook PinDetct library into project // URL: http://mbed.org/users/AjK/libraries/PinDetect/lkyxpw DigitalOut myled(LED1); -DigitalOut myled2(LED2); -DigitalOut myled3(LED3); -DigitalOut myled4(LED4); Timer t; TextLCD lcd(p36, p34, p9, p10, p15, p16); // rs, e, d0-d3 - PinDetect pb1(p18); PinDetect pb2(p19); +Serial pc(USBTX, USBRX); + // SPST Pushbutton debounced count demo using interrupts and callback // no external PullUp resistor needed // Pushbutton from P8 to GND. @@ -23,54 +22,142 @@ // Global count variable int volatile count=0; int volatile resetcnt=0; +int volatile zz1=0; +int volatile zz2=0; +int volatile sblock=0; +int volatile reset=0; +int volatile D=0; +int ms; +int sec; +int min; +int ms1; +char buffer[9]; +char zwischenzeit[9]; +char zwischenzeit1[9]; + +/*Funktions Dekleration*/ +void stoppuhr(void) +{ + ms = t.read_ms(); //hole mir den TimerWert in ms + sec = (ms/1000); //erzeuge mir durch division eine sekunde - aktueller Timerwert/1000 - z.b: 2548/1000=2sec + ms = ms - (sec*1000); //stelle meine ms richtig + min = (sec/60); //erzeuge mir Minuten + sec = sec - (min*60); //stelle Sekunden richtig + ms = (ms/10); + ms1 = (ms/10); //erzeuge mir zwei Stellen nach komma + sprintf(buffer, "%02d:%02d:%02d", min, sec, ms); //schreibe in den buffer + return; +} + +void reset_halten( void ) +{ + + if(sblock==1) + { + t.stop(); + t.reset(); + stoppuhr(); + sprintf(zwischenzeit,"%01d:%02d:%1d", min, sec, ms1); + sprintf(zwischenzeit1,"%01d:%02d:%1d", min, sec, ms1); + resetcnt=0; + count=0; + zz1=0; + zz2=0; + sblock=0; + D++; + if(D>99){D=0;} + } +} // Callback routine is interrupt activated by a debounced pb1 hit void pb1_hit_callback (void) { - count++; - myled4 = count & 0x01; - myled3 = (count & 0x02)>>1; - myled2 = (count & 0x04)>>2; - t.start(); - if (resetcnt==1) { - t.reset(); - resetcnt=0; - } + + ++count; //erhöhe die Variable count nach jedem drücken des Startbuttoms um 1 + + if ((resetcnt==0) && (count <= 1)&& (sblock==0)) + { + t.reset(); //restiere Timer + t.start(); //starte Timer + resetcnt=1; + } + else if ((resetcnt==1) && (count <= 2) && (sblock==0)) + { + zz1=1; + sprintf(zwischenzeit,"%01d:%02d:%1d", min, sec, ms1); + resetcnt=2; + } + else if ((resetcnt==2) && (count <= 3) && (sblock==0)) + { + zz2=1; + sprintf(zwischenzeit1,"%01d:%02d:%1d", min, sec, ms1); + } + else + { + lcd.cls(); + // wait(0.05); + lcd.locate(1, 0); + if(sblock==0) + { + + lcd.printf("STOPP DRUEKEN!"); + wait(1); + } + if(sblock==1) + { + lcd.printf("RESET: START LANGE DRUEKEN!"); + wait(1); + } + } + resetcnt=resetcnt++; } + // Callback routine is interrupt activated by a debounced pb2 hit void pb2_hit_callback (void) { - count--; - myled4 = count & 0x01; - myled3 = (count & 0x02)>>1; - myled2 = (count & 0x04)>>2; t.stop(); - resetcnt=resetcnt++; + if(sblock==1) + { + lcd.cls(); +// wait(0.05); + lcd.printf("RESET: START LANGE DRUEKEN!"); + wait(1); + } + pc.printf("Gesamtzeit: %s\n", buffer); + pc.printf("Zwischenzeit: %s\n", zwischenzeit); + pc.printf("Zwischenzeit: %s\n", zwischenzeit1); + sblock=1; } int main() { - // Use internal pullups for pushbutton - //pb1.mode(PullUp); - //pb2.mode(PullUp); - // Delay for initial pullup to take effect - //wait(.01); // Setup Interrupt callback functions for a pb hit pb1.attach_deasserted(&pb1_hit_callback); + pb1.attach_deasserted_held(&reset_halten); pb2.attach_deasserted(&pb2_hit_callback); + // Start sampling pb inputs using interrupts pb1.setSampleFrequency(); pb2.setSampleFrequency(); - //Blink myled in main routine forever while responding to pb changes - // via interrupts that activate the callback counter function + while (1) { - myled = !myled; - - lcd.printf("Timer\n"); - lcd.printf(" %4.2f sec\n", t.read()); - - - wait(.01); - lcd.cls(); - resetcnt=1; - + wait(.1); + lcd.cls(); + myled = !myled; // LED1 blickt + stoppuhr(); //rufe Funktion stoppuhr auf + lcd.locate(0, 0); //setze den curser auf Zeihen 0 Reihe 1 + lcd.printf("D%02d", D); //Formatiere mein LCD-Ausgabe nach D00 (zwei stellen) + lcd.locate(4, 0); + lcd.printf("ZE:%s", buffer); + if(zz1==1) + { + lcd.locate(0, 1); + lcd.printf("A%s", zwischenzeit); + } + if(zz2==1) + { + lcd.locate(8, 1); + lcd.printf("B%s", zwischenzeit1); + } + // wait(.1); + // lcd.cls(); } -} \ No newline at end of file +}