|
3 | 3 | read data coming from bridge using the Console.read() function
|
4 | 4 | and store it in a string.
|
5 | 5 |
|
| 6 | + To see the Console, pick your Yun's name and IP address in the Port menu |
| 7 | + then open the Port Monitor. You can also see it by opening a terminal window |
| 8 | + and typing |
| 9 | + ssh root@ yourYunsName.local 'telnet localhost 6571' |
| 10 | + then pressing enter. When prompted for the password, enter it. |
| 11 | + |
6 | 12 | created 13 Jun 2013
|
7 | 13 | by Angelo Scialabba
|
| 14 | + modified 16 June 2013 |
| 15 | + by Tom Igoe |
8 | 16 |
|
9 | 17 | This example code is in the public domain.
|
10 | 18 | */
|
11 | 19 |
|
12 | 20 | #include <Console.h>
|
13 | 21 |
|
14 | 22 | String name;
|
15 |
| -int current_char; |
16 | 23 |
|
17 | 24 | void setup() {
|
18 | 25 | //Initialize Console and wait for port to open:
|
19 | 26 | Bridge.begin();
|
20 | 27 | Console.begin();
|
21 |
| - |
22 |
| - while (!Console) { |
| 28 | + |
| 29 | + while (!Console){ |
23 | 30 | ; // wait for Console port to connect.
|
24 | 31 | }
|
25 |
| - Console.println("Hi, who are you?"); |
| 32 | + Console.println("Hi, what's your name?"); |
26 | 33 | }
|
27 | 34 |
|
28 | 35 | void loop() {
|
29 |
| - current_char = Console.read(); //read the next char received |
30 |
| - //look for the newline character, this is the last character in the string |
31 |
| - if (current_char == '\n') { |
32 |
| - //print text with the name received |
33 |
| - Console.print("Hi "); |
34 |
| - Console.print(name); |
35 |
| - Console.println("! Nice to meet you!"); |
36 |
| - Console.println(); |
37 |
| - //Ask again for name and clear the old name |
38 |
| - Console.println("Hi, who are you?"); |
39 |
| - name = ""; |
40 |
| - } else if (current_char != -1) { //if the buffer is empty Cosole.read returns -1 |
41 |
| - name = name + (char)current_char; //current_char is int, treat him as char and add it to the name string |
| 36 | + 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') { |
| 40 | + //print text with the name received |
| 41 | + Console.print("Hi "); |
| 42 | + Console.print(name); |
| 43 | + Console.println("! Nice to meet you!"); |
| 44 | + Console.println(); |
| 45 | + //Ask again for name and clear the old name |
| 46 | + Console.println("Hi, what's your name?"); |
| 47 | + name = ""; |
| 48 | + } |
| 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 |
| 51 | + } |
42 | 52 | }
|
43 | 53 | }
|
| 54 | + |
| 55 | + |
0 commit comments