stoppuhr s

Fork of FeuerwehrStoppuhr by Jovica D.

Committer:
joca89
Date:
Wed May 08 13:59:35 2013 +0000
Revision:
3:6f6ee868bf8c
Feuerwehrprojekt

Who changed what in which revision?

UserRevisionLine numberNew contents of line
joca89 3:6f6ee868bf8c 1 //send data routine
joca89 3:6f6ee868bf8c 2
joca89 3:6f6ee868bf8c 3 // link between the computer and the SoftSerial Shield
joca89 3:6f6ee868bf8c 4 //at 9600 bps 8-N-1
joca89 3:6f6ee868bf8c 5 //Computer is connected to Hardware UART
joca89 3:6f6ee868bf8c 6 //SoftSerial Shield is connected to the Software UART:D2&D3
joca89 3:6f6ee868bf8c 7
joca89 3:6f6ee868bf8c 8 #include <SoftwareSerial.h>
joca89 3:6f6ee868bf8c 9
joca89 3:6f6ee868bf8c 10 SoftwareSerial SoftSerial(11, 10); // TX, RX
joca89 3:6f6ee868bf8c 11 int buffer[64];
joca89 3:6f6ee868bf8c 12 int count=0;
joca89 3:6f6ee868bf8c 13 void setup()
joca89 3:6f6ee868bf8c 14 {
joca89 3:6f6ee868bf8c 15 SoftSerial.begin(9600); // the SoftSerial baud rate
joca89 3:6f6ee868bf8c 16 Serial.begin(9600); // the Serial port of Arduino baud rate.
joca89 3:6f6ee868bf8c 17
joca89 3:6f6ee868bf8c 18 }
joca89 3:6f6ee868bf8c 19
joca89 3:6f6ee868bf8c 20 void loop()
joca89 3:6f6ee868bf8c 21 {
joca89 3:6f6ee868bf8c 22 delay(1000);
joca89 3:6f6ee868bf8c 23 SoftSerial.write(0xAA);
joca89 3:6f6ee868bf8c 24 SoftSerial.write(0xFA);
joca89 3:6f6ee868bf8c 25 SoftSerial.write(0xE1);
joca89 3:6f6ee868bf8c 26
joca89 3:6f6ee868bf8c 27 if (SoftSerial.available()) // if date is comming from softwareserial port ==> data is comming from SoftSerial shield
joca89 3:6f6ee868bf8c 28 {
joca89 3:6f6ee868bf8c 29 while(SoftSerial.available()) // reading data into char array
joca89 3:6f6ee868bf8c 30 {
joca89 3:6f6ee868bf8c 31 buffer[count++]=SoftSerial.read(); // writing data into array
joca89 3:6f6ee868bf8c 32 if(count == 64)break;
joca89 3:6f6ee868bf8c 33 }
joca89 3:6f6ee868bf8c 34 for (int i=0; i<count; i++) {
joca89 3:6f6ee868bf8c 35 Serial.print(buffer[i],HEX); // if no data transmission ends, write buffer to hardware serial port
joca89 3:6f6ee868bf8c 36 }
joca89 3:6f6ee868bf8c 37 clearBufferArray(); // call clearBufferArray function to clear the storaged data from the array
joca89 3:6f6ee868bf8c 38 count = 0; // set counter of while loop to zero
joca89 3:6f6ee868bf8c 39 }
joca89 3:6f6ee868bf8c 40 if (Serial.available()) // if data is available on hardwareserial port ==> data is comming from PC or notebook
joca89 3:6f6ee868bf8c 41 SoftSerial.write(Serial.read()); // write it to the SoftSerial shield
joca89 3:6f6ee868bf8c 42 Serial.println("...");
joca89 3:6f6ee868bf8c 43 }
joca89 3:6f6ee868bf8c 44 void clearBufferArray() // function to clear buffer array
joca89 3:6f6ee868bf8c 45 {
joca89 3:6f6ee868bf8c 46 for (int i=0; i<count;i++)
joca89 3:6f6ee868bf8c 47 { buffer[i]=NULL;} // clear all index of array with command NULL
joca89 3:6f6ee868bf8c 48 }