Skip to content

Commit 2b4346b

Browse files
committed
modified and added comments to the ConsoleRead.ino example
1 parent f9989cc commit 2b4346b

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

hardware/arduino/avr/libraries/Bridge/examples/ConsoleRead/ConsoleRead.ino

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/*
2-
Console.read() example:
3-
read data coming from bridge using the Console.read() function
2+
Console Read example
3+
4+
Read data coming from bridge using the Console.read() function
45
and store it in a string.
56
6-
To see the Console, pick your Yun's name and IP address in the Port menu
7+
To see the Console, pick your Yún's name and IP address in the Port menu
78
then open the Port Monitor. You can also see it by opening a terminal window
8-
and typing
9+
and typing:
910
ssh root@ yourYunsName.local 'telnet localhost 6571'
1011
then pressing enter. When prompted for the password, enter it.
1112
@@ -22,32 +23,32 @@
2223
String name;
2324

2425
void setup() {
25-
//Initialize Console and wait for port to open:
26+
// Initialize Console and wait for port to open:
2627
Bridge.begin();
2728
Console.begin();
2829

29-
while (!Console){
30-
; // wait for Console port to connect.
31-
}
30+
// Wait for Console port to connect
31+
while (!Console);
32+
3233
Console.println("Hi, what's your name?");
3334
}
3435

3536
void loop() {
3637
if (Console.available() > 0) {
37-
char thisChar = Console.read(); //read the next char received
38-
//look for the newline character, this is the last character in the string
39-
if (thisChar == '\n') {
38+
char c = Console.read(); // read the next char received
39+
// look for the newline character, this is the last character in the string
40+
if (c == '\n') {
4041
//print text with the name received
4142
Console.print("Hi ");
4243
Console.print(name);
4344
Console.println("! Nice to meet you!");
4445
Console.println();
45-
//Ask again for name and clear the old name
46+
// Ask again for name and clear the old name
4647
Console.println("Hi, what's your name?");
47-
name = "";
48+
name = ""; // clear the name string
4849
}
49-
else { //if the buffer is empty Cosole.read returns -1
50-
name += thisChar; //thisChar is int, treat him as char and add it to the name string
50+
else { // if the buffer is empty Cosole.read() returns -1
51+
name += c; // append the read char from Console to the name string
5152
}
5253
}
5354
}

0 commit comments

Comments
 (0)