1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| //link between the computer and the Serial2 Shield
//at 9600 bps 8-N-1
//Computer is connected to Hardware UART
//Serial2 Shield is connected to the Software UART:D2&D3
unsigned char buffer[12]; //64 caracteres lus à
changer selon longueur tag
// buffer array for data receive over serial port
int count=0;
// counter for buffer array
void setup()
{
Serial2.begin(9600); // the Serial2 baud rate
Serial.begin(9600);
// the Serial port of Arduino baud rate. }
Serial.write("demarrer");
}
void loop()
{
//checker si information disponible 'available' qqlchose
// serial.
{ buffer[count++]=Serial2.read(); // writing data into array
if(count == 64)break;
}
Serial.write(buffer,count); // if no data transmission ends, write buffer to hardware serial port
clearBufferArray(); // call clearBufferArray function to clear the stored data from the array
count = 0; // set counter of while loop to zero
}
if (Serial.available()) // if data is available on hardware serial port ==> data is coming from PC or notebook
Serial2.write(Serial.read()); // write it to the Serial2 shield
}
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
Delay(1000);
} |
Partager