libraries / Bridge / examples / ConsoleRead / ConsoleRead.inoon commit Added link to project report (97a3ba0)
   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://www.arduino.cc/en/Tutorial/ConsoleRead
  21
  22 */
  23
  24#include <Console.h>
  25
  26String name;
  27
  28void 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
  39void 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    } else {     // if the buffer is empty Cosole.read() returns -1
  53      name += c; // append the read char from Console to the name string
  54    }
  55  } else {
  56    delay(100);
  57  }
  58}
  59
  60