stoppuhr s

Dependencies:   PinDetect TextLCD mbed

Fork of FeuerwehrStoppuhr0805 by Jovica D.

Files at this revision

API Documentation at this revision

Comitter:
joca89
Date:
Wed May 08 13:59:35 2013 +0000
Parent:
2:9c7ca5717309
Child:
4:8c274febf3b0
Commit message:
Feuerwehrprojekt

Changed in this revision

HM-TRP.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HM-TRP.h	Wed May 08 13:59:35 2013 +0000
@@ -0,0 +1,48 @@
+//send data routine
+ 
+// link between the computer and the SoftSerial Shield
+//at 9600 bps 8-N-1
+//Computer is connected to Hardware UART
+//SoftSerial Shield is connected to the Software UART:D2&D3 
+ 
+#include <SoftwareSerial.h>
+ 
+SoftwareSerial SoftSerial(11, 10); // TX, RX
+int buffer[64];
+int count=0;
+void setup()  
+{
+  SoftSerial.begin(9600);               // the SoftSerial baud rate   
+  Serial.begin(9600);             // the Serial port of Arduino baud rate.
+ 
+}
+ 
+void loop()
+{
+  delay(1000);
+  SoftSerial.write(0xAA);
+  SoftSerial.write(0xFA);
+  SoftSerial.write(0xE1);
+ 
+  if (SoftSerial.available())              // if date is comming from softwareserial port ==> data is comming from SoftSerial shield
+  {
+    while(SoftSerial.available())          // reading data into char array 
+    {
+      buffer[count++]=SoftSerial.read();     // writing data into array
+      if(count == 64)break;
+    }
+    for (int i=0; i<count; i++) {
+      Serial.print(buffer[i],HEX);            // if no data transmission ends, write buffer to hardware serial port
+    }
+    clearBufferArray();              // call clearBufferArray function to clear the storaged data from the array
+    count = 0;                       // set counter of while loop to zero
+  }
+  if (Serial.available())            // if data is available on hardwareserial port ==> data is comming from PC or notebook
+    SoftSerial.write(Serial.read());       // write it to the SoftSerial shield
+  Serial.println("...");
+}
+void clearBufferArray()              // function to clear buffer array
+{
+  for (int i=0; i<count;i++)
+    { buffer[i]=NULL;}                  // clear all index of array with command NULL
+}
\ No newline at end of file
--- a/main.cpp	Fri Apr 26 09:10:33 2013 +0000
+++ b/main.cpp	Wed May 08 13:59:35 2013 +0000
@@ -2,23 +2,17 @@
 #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
-//TST was here
+
  
 DigitalOut myled(LED1);
 Timer t;
-TextLCD lcd(p36, p34, p9, p10, p15, p16); // rs, e, d0-d3
+TextLCD lcd(p36, p34, p24, p23, 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.
-// Second Pushbutton from P7 to GND.
-// A pb hit generates an interrupt and activates the callback function
-// after the switch is debounced
+Serial hm(p9, p10); // definiere UART für HM-TPR433 Modul
+DigitalOut config(p22);
+DigitalOut enable(p21);
  
 // Global count variable
 int volatile count=0;
@@ -28,6 +22,7 @@
 int volatile sblock=0;
 int volatile reset=0;
 int volatile D=0;
+//int volatile send=0;
 int ms;
 int sec;
 int min;
@@ -37,6 +32,36 @@
 char zwischenzeit1[9];
 
 /*Funktions Dekleration*/
+
+void empfangen() {
+    // Note: you need to actually read from the serial to clear the RX interrupt    
+  
+  //  send = 1;
+    t.stop();
+    if(sblock==1)
+     {
+    lcd.cls();
+    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;
+    lcd.printf("%c\n", hm.getc());
+    return;
+}
+
+void konfiguration(void)
+{
+ config = 0;
+ enable = 0;
+ hm.printf("AA FA F0");
+ wait(0.1);
+ config = 1;
+ return;
+}
+
 void stoppuhr(void)
 {
     ms = t.read_ms();           //hole mir den TimerWert in ms
@@ -51,8 +76,7 @@
 }  
 
 void reset_halten( void ) 
-{
-    
+{  
     if(sblock==1) 
     {   
         t.stop();
@@ -111,7 +135,7 @@
     }
     resetcnt=resetcnt++;  
 }
-
+/*
 // Callback routine is interrupt activated by a debounced pb2 hit
 void pb2_hit_callback (void) {
     t.stop();
@@ -127,20 +151,28 @@
     pc.printf("Zwischenzeit: %s\n", zwischenzeit1);
     sblock=1;
 }
+*/
 int main() {
- 
+
+    konfiguration();
+    hm.attach(&empfangen);  
+    
     // 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);
+  //  pb2.attach_deasserted(&pb2_hit_callback);
     
     // Start sampling pb inputs using interrupts
     pb1.setSampleFrequency();
-    pb2.setSampleFrequency();
-       
+   // pb2.setSampleFrequency();
+    
+    
     while (1) {
         wait(.1);
         lcd.cls(); 
+      //  if(send=1){
+        
+        //}
         myled = !myled;                 // LED1 blickt
         stoppuhr();                     //rufe Funktion stoppuhr auf      
         lcd.locate(0, 0);               //setze den curser auf Zeihen 0 Reihe 1
@@ -157,8 +189,7 @@
             lcd.locate(8, 1);
             lcd.printf("B%s", zwischenzeit1);         
             }                          
-      //  wait(.1);
-       // lcd.cls();        
+            
     }
  
 }