Line | |
---|
1 | /*
|
---|
2 | Console Read example
|
---|
3 |
|
---|
4 | Read data coming from bridge using the Console.read() function
|
---|
5 | and store it in a string.
|
---|
6 |
|
---|
7 | To see the Console, pick your Y炭n's name and IP address in the Port menu
|
---|
8 | then open the Port Monitor. You can also see it by opening a terminal window
|
---|
9 | and typing:
|
---|
10 | ssh root@ yourYunsName.local 'telnet localhost 6571'
|
---|
11 | then pressing enter. When prompted for the password, enter it.
|
---|
12 |
|
---|
13 | created 13 Jun 2013
|
---|
14 | by Angelo Scialabba
|
---|
15 | modified 16 June 2013
|
---|
16 | by Tom Igoe
|
---|
17 |
|
---|
18 | This example code is in the public domain.
|
---|
19 |
|
---|
20 | http://arduino.cc/en/Tutorial/ConsoleRead
|
---|
21 |
|
---|
22 | */
|
---|
23 |
|
---|
24 | #include <Console.h>
|
---|
25 |
|
---|
26 | String name;
|
---|
27 |
|
---|
28 | void setup() {
|
---|
29 | // Initialize Console and wait for port to open:
|
---|
30 | Bridge.begin();
|
---|
31 | Console.begin();
|
---|
32 |
|
---|
33 | // Wait for Console port to connect
|
---|
34 | while (!Console);
|
---|
35 |
|
---|
36 | Console.println("Hi, what's your name?");
|
---|
37 | }
|
---|
38 |
|
---|
39 | void loop() {
|
---|
40 | if (Console.available() > 0) {
|
---|
41 | char c = Console.read(); // read the next char received
|
---|
42 | // look for the newline character, this is the last character in the string
|
---|
43 | if (c == '\n') {
|
---|
44 | //print text with the name received
|
---|
45 | Console.print("Hi ");
|
---|
46 | Console.print(name);
|
---|
47 | Console.println("! Nice to meet you!");
|
---|
48 | Console.println();
|
---|
49 | // Ask again for name and clear the old name
|
---|
50 | Console.println("Hi, what's your name?");
|
---|
51 | name = ""; // clear the name string
|
---|
52 | }
|
---|
53 | else { // if the buffer is empty Cosole.read() returns -1
|
---|
54 | name += c; // append the read char from Console to the name string
|
---|
55 | }
|
---|
56 | } else {
|
---|
57 | delay(100);
|
---|
58 | }
|
---|
59 | }
|
---|
60 |
|
---|
61 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.