1 | int incomingByte = 0; // for incoming serial data |
---|
2 | |
---|
3 | void setup() { |
---|
4 | Serial.begin(9600); // opens serial port, sets data rate to 9600 bps |
---|
5 | } |
---|
6 | |
---|
7 | void loop() { |
---|
8 | |
---|
9 | // send data only when you receive data: |
---|
10 | if (Serial.available() > 0) |
---|
11 | { |
---|
12 | digitalWrite(13, HIGH); |
---|
13 | // read the incoming byte: |
---|
14 | incomingByte = Serial.read(); |
---|
15 | |
---|
16 | // say what you got: |
---|
17 | Serial.print("I received: "); |
---|
18 | Serial.print(char(incomingByte)); |
---|
19 | Serial.print(" = "); |
---|
20 | Serial.println(incomingByte, DEC); |
---|
21 | } |
---|
22 | else |
---|
23 | { |
---|
24 | digitalWrite(13, LOW); |
---|
25 | |
---|
26 | } |
---|
27 | } |
---|
28 | |
---|
29 |
|
---|