testSerial.ino
1.18 KB
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
42
43
/*
DigitalReadSerial
Reads a digital input on pin 2, prints the result to the serial monitor
This example code is in the public domain.
*/
byte incomingBytes[3]; // for incoming serial data
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input pin:
// print out the state of the button:
/*Serial.write('H');
delay(1); // delay in between reads for stability*/
if (Serial.available() <= 3 && Serial.available() >= 1 ) {
// read the incoming byte:
Serial.readBytes(incomingBytes,3);
// say what you got:
/*Serial.print("I received: ");
Serial.print(incomingBytes[0]);
Serial.print(incomingBytes[1]);
Serial.print(incomingBytes[2]);
Serial.write(incomingBytes[0]);
Serial.write(incomingBytes[1]);
Serial.write(incomingBytes[2]);*/
//Serial.print(incomingBytes,3);
Serial.write(incomingBytes,3);
}/*else{
while(Serial.available()){Serial.read();}
}*/
//while(Serial.available()){Serial.read();} //censé vider le buffer série
}