4
EXAMPLES
4.1
Example 1: Say hello to Linux
Introduction:
This example is a hello test between the Arduino and Yun Shield. The example can be found on
the
Arduino IDE--> File --> Examples --> Bridge --> ConsoleRead.
Tutorial of this example can be
found on
http://arduino.cc/en/Tutorial/ConsoleRead
. Below listing the code and add some detail
to understand it with the Yun Shield:
Code:
#include <Console.h>
//use Console class for Arduino IDE debug over WiFi, similar to Serial class,
String name;
void setup() {
// Initialize Console and wait for port to open:
Bridge.begin();
Console.begin();
// Wait for Console port to connect
while (!Console);
Console.println("Hi, what's your name?");
//Data flow: Arduino --> Yun Shield --> Arduino IDE
}
void loop() {
if (Console.available() > 0) {
char c = Console.read();
//read the next char received, data flow: IDE --> Yun Shield--> Arduino
// look for the newline character, this is the last character in the string
if (c == '\n') {
//print text with the name received
Console.print("Hi ");
Console.print(name);
Console.println("! Nice to meet you!");
Console.println();
// Ask again for name and clear the old name
Console.println("Hi, what's your name?");
name = "";
// clear the name string
}
else {
// if the buffer is empty Cosole.read() returns -1
name += c;
// append the read char from Console to the name string
}
}
}
Screen Shot:
w w w . e k t
2
. c o m
Electronics
Katrangi
Trading
Содержание PAB2
Страница 1: ...Yun Shield User Manual VERSION 1 1 w w w e k t 2 c o m Electronics Katrangi Trading...
Страница 20: ...Screen Shot Xively Dashboard w w w e k t 2 c o m Electronics Katrangi Trading...
Страница 28: ...Yun Shield Quick Start Guide VERSION 1 0 w w w e k t 2 c o m Electronics Katrangi Trading...
Страница 39: ...Screen Shot Xively Dashboard w w w e k t 2 c o m Electronics Katrangi Trading...