mirror of https://github.com/noisymime/Arduino.git
Simpllified ConsoleRead, added available(), added explanation.
This commit is contained in:
parent
45f7d1e6f8
commit
00bd3fd10b
|
@ -3,8 +3,16 @@
|
||||||
read data coming from bridge using the Console.read() function
|
read data coming from bridge using the Console.read() function
|
||||||
and store it in a string.
|
and store it in a string.
|
||||||
|
|
||||||
|
To see the Console, pick your Yun'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
|
||||||
|
ssh root@ yourYunsName.local 'telnet localhost 6571'
|
||||||
|
then pressing enter. When prompted for the password, enter it.
|
||||||
|
|
||||||
created 13 Jun 2013
|
created 13 Jun 2013
|
||||||
by Angelo Scialabba
|
by Angelo Scialabba
|
||||||
|
modified 16 June 2013
|
||||||
|
by Tom Igoe
|
||||||
|
|
||||||
This example code is in the public domain.
|
This example code is in the public domain.
|
||||||
*/
|
*/
|
||||||
|
@ -12,7 +20,6 @@
|
||||||
#include <Console.h>
|
#include <Console.h>
|
||||||
|
|
||||||
String name;
|
String name;
|
||||||
int current_char;
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
//Initialize Console and wait for port to open:
|
//Initialize Console and wait for port to open:
|
||||||
|
@ -22,22 +29,27 @@ void setup() {
|
||||||
while (!Console){
|
while (!Console){
|
||||||
; // wait for Console port to connect.
|
; // wait for Console port to connect.
|
||||||
}
|
}
|
||||||
Console.println("Hi, who are you?");
|
Console.println("Hi, what's your name?");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
current_char = Console.read(); //read the next char received
|
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
|
//look for the newline character, this is the last character in the string
|
||||||
if (current_char == '\n') {
|
if (thisChar == '\n') {
|
||||||
//print text with the name received
|
//print text with the name received
|
||||||
Console.print("Hi ");
|
Console.print("Hi ");
|
||||||
Console.print(name);
|
Console.print(name);
|
||||||
Console.println("! Nice to meet you!");
|
Console.println("! Nice to meet you!");
|
||||||
Console.println();
|
Console.println();
|
||||||
//Ask again for name and clear the old name
|
//Ask again for name and clear the old name
|
||||||
Console.println("Hi, who are you?");
|
Console.println("Hi, what's your name?");
|
||||||
name = "";
|
name = "";
|
||||||
} else if (current_char != -1) { //if the buffer is empty Cosole.read returns -1
|
}
|
||||||
name = name + (char)current_char; //current_char is int, treat him as char and add it to 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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue