aboutsummaryrefslogtreecommitdiff
path: root/libraries
diff options
context:
space:
mode:
authorFede85 <f.vanzati@gmail.com>2013-07-02 16:38:59 +0200
committerFede85 <f.vanzati@gmail.com>2013-07-02 16:38:59 +0200
commit13c664ed488cf1dfdf621d2a9f45e044a1103709 (patch)
tree5f0c36e76e528eeaf8893a25d563945d6cf32316 /libraries
parentfa859e27830708851a0d35f352b645a4653ba5f5 (diff)
modified and added comments to the ConsoleRead.ino example
Diffstat (limited to 'libraries')
-rw-r--r--libraries/Bridge/examples/ConsoleRead/ConsoleRead.ino31
1 files changed, 16 insertions, 15 deletions
diff --git a/libraries/Bridge/examples/ConsoleRead/ConsoleRead.ino b/libraries/Bridge/examples/ConsoleRead/ConsoleRead.ino
index 7b38f03..0019c20 100644
--- a/libraries/Bridge/examples/ConsoleRead/ConsoleRead.ino
+++ b/libraries/Bridge/examples/ConsoleRead/ConsoleRead.ino
@@ -1,11 +1,12 @@
/*
- Console.read() example:
- read data coming from bridge using the Console.read() function
+ Console Read example
+
+ Read data coming from bridge using the Console.read() function
and store it in a string.
- To see the Console, pick your Yun's name and IP address in the Port menu
+ To see the Console, pick your Yún's name and IP address in the Port menu
then open the Port Monitor. You can also see it by opening a terminal window
- and typing
+ and typing:
ssh root@ yourYunsName.local 'telnet localhost 6571'
then pressing enter. When prompted for the password, enter it.
@@ -22,32 +23,32 @@
String name;
void setup() {
- //Initialize Console and wait for port to open:
+ // Initialize Console and wait for port to open:
Bridge.begin();
Console.begin();
- while (!Console){
- ; // wait for Console port to connect.
- }
+ // Wait for Console port to connect
+ while (!Console);
+
Console.println("Hi, what's your name?");
}
void loop() {
if (Console.available() > 0) {
- char thisChar = Console.read(); //read the next char received
- //look for the newline character, this is the last character in the string
- if (thisChar == '\n') {
+ char c = Console.read(); // read the next char received
+ // look for the newline character, this is the last character in the string
+ if (c == '\n') {
//print text with the name received
Console.print("Hi ");
Console.print(name);
Console.println("! Nice to meet you!");
Console.println();
- //Ask again for name and clear the old name
+ // Ask again for name and clear the old name
Console.println("Hi, what's your name?");
- name = "";
+ name = ""; // clear the name string
}
- else { //if the buffer is empty Cosole.read returns -1
- name += thisChar; //thisChar is int, treat him as char and add it to the name string
+ else { // if the buffer is empty Cosole.read() returns -1
+ name += c; // append the read char from Console to the name string
}
}
}