mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-01 23:29:28 +01:00
modified and added comments to the ConsoleRead.ino example
This commit is contained in:
parent
f9989cce62
commit
2b4346b1f5
@ -1,11 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
Console.read() example:
|
Console Read example
|
||||||
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
|
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
|
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'
|
ssh root@ yourYunsName.local 'telnet localhost 6571'
|
||||||
then pressing enter. When prompted for the password, enter it.
|
then pressing enter. When prompted for the password, enter it.
|
||||||
|
|
||||||
@ -22,32 +23,32 @@
|
|||||||
String name;
|
String name;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
//Initialize Console and wait for port to open:
|
// Initialize Console and wait for port to open:
|
||||||
Bridge.begin();
|
Bridge.begin();
|
||||||
Console.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?");
|
Console.println("Hi, what's your name?");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if (Console.available() > 0) {
|
if (Console.available() > 0) {
|
||||||
char thisChar = Console.read(); //read the next char received
|
char c = 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 (thisChar == '\n') {
|
if (c == '\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, what's your name?");
|
Console.println("Hi, what's your name?");
|
||||||
name = "";
|
name = ""; // clear the name string
|
||||||
}
|
}
|
||||||
else { //if the buffer is empty Cosole.read returns -1
|
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
|
name += c; // append the read char from Console to the name string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user