aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Fissore <f.fissore@arduino.cc>2013-06-26 16:04:55 +0200
committerFederico Fissore <f.fissore@arduino.cc>2013-06-26 16:04:55 +0200
commitbf82b241f55a34543e94cea854d819d0a607988c (patch)
treefae9fa99088155d956b9c408d02b13f547007dea
parent4ba06563af4c74cb37aecf1b34136eec0772b5fb (diff)
parentf07c6f2a52af85a63e9e4ebb98d4673b4183287a (diff)
Merge branch 'ide-1.5.x-discovery' into dev-ide-1.5.x-discovery
-rw-r--r--libraries/Bridge/examples/ConsolePixel/ConsolePixel.ino58
-rw-r--r--libraries/Bridge/examples/ShellCommands/ShellCommands.ino35
-rw-r--r--libraries/Bridge/examples/XivelyClient/XivelyClient.ino14
3 files changed, 88 insertions, 19 deletions
diff --git a/libraries/Bridge/examples/ConsolePixel/ConsolePixel.ino b/libraries/Bridge/examples/ConsolePixel/ConsolePixel.ino
new file mode 100644
index 0000000..4201465
--- /dev/null
+++ b/libraries/Bridge/examples/ConsolePixel/ConsolePixel.ino
@@ -0,0 +1,58 @@
+/*
+ Console Pixel
+
+ An example of using the Arduino board to receive data from the
+ Console on the Arduino Yun. In this case, the Arduino boards turns on an LED when
+ it receives the character 'H', and turns off the LED when it
+ receives the character 'L'.
+
+ To see the Console, pick your Yun's name and IP address in the Port menu
+ then open the Port Monitor. You can also see it by opening a terminal window
+ and typing
+ ssh root@ yourYunsName.local 'telnet localhost 6571'
+ then pressing enter. When prompted for the password, enter it.
+
+
+ The circuit:
+ * LED connected from digital pin 13 to ground
+
+ created 2006
+ by David A. Mellis
+ modified 25 Jun 2013
+ by Tom Igoe
+
+ This example code is in the public domain.
+
+ */
+#include <Console.h>
+
+const int ledPin = 13; // the pin that the LED is attached to
+char incomingByte; // a variable to read incoming Console data into
+
+void setup() {
+ // initialize Console communication:
+ Bridge.begin();
+ Console.begin();
+ while(!Console); // wait for the Console to open from the remote side
+ Console.println("type H or L to turn pin 13 on or off");
+ // initialize the LED pin as an output:
+ pinMode(ledPin, OUTPUT);
+}
+
+void loop() {
+ // see if there's incoming Console data:
+ if (Console.available() > 0) {
+ // read the oldest byte in the Console buffer:
+ incomingByte = Console.read();
+ Console.println(incomingByte);
+ // if it's a capital H (ASCII 72), turn on the LED:
+ if (incomingByte == 'H') {
+ digitalWrite(ledPin, HIGH);
+ }
+ // if it's an L (ASCII 76) turn off the LED:
+ if (incomingByte == 'L') {
+ digitalWrite(ledPin, LOW);
+ }
+ }
+}
+
diff --git a/libraries/Bridge/examples/ShellCommands/ShellCommands.ino b/libraries/Bridge/examples/ShellCommands/ShellCommands.ino
index 47579f8..d2f9b7a 100644
--- a/libraries/Bridge/examples/ShellCommands/ShellCommands.ino
+++ b/libraries/Bridge/examples/ShellCommands/ShellCommands.ino
@@ -3,18 +3,21 @@
Running shell coommands using Process class.
This sketch demonstrate how to run linux shell commands
- using an Arduino Yún.
-
+ using an Arduino Yún. It runs the wifiCheck script on the linino side
+ of the Yun, then uses grep to get just the signal strength line.
+ Then it uses parseInt() to read the wifi signal strength as an integer,
+ and finally uses that number to fade an LED using analogWrite().
+
The circuit:
- * Arduino Yun
+ * Arduino Yun with LED connected to pin 9
created 12 Jun 2013
by Cristian Maglie
- modified 21 June 2013
+ modified 25 June 2013
by Tom Igoe
This example code is in the public domain.
-
+
*/
#include <Process.h>
@@ -27,15 +30,23 @@ void setup() {
void loop() {
Process p;
- // This command line prints the name of the wireless network
- // that the board is connected to, or the network which the board has created:
- p.runShellCommand(F("lua /usr/lib/lua/pretty_wifi_info.lua | grep SSID"));
+ // This command line runs the wifiCheck script, (lua /arduino/pretty...), then
+ // sends the result to the grep command to look for a line containing the word
+ // "Signal:" the result is passed to this sketch:
+ p.runShellCommand("lua /arduino/pretty_wifi_info.lua | grep Signal");
- // Read command output
+ // do nothing until the process finishes, so you get the whole output:
+ while(p.running());
+
+ // Read command output. runShellCommand() should have passed "Signal: xx&":
while (p.available()) {
- char c = p.read();
- Serial.print(c);
+ int result = p.parseInt(); // look for an integer
+ int signal = map(result, 0, 100, 0, 255); // map result from 0-100 range to 0-255
+ analogWrite(9, signal); // set the brightness of LED on pin 9
+ Serial.println(result); // print the number as well
}
- while (true); // do nothing more
+ delay(5000); // wait 5 seconds before you do it again
}
+
+
diff --git a/libraries/Bridge/examples/XivelyClient/XivelyClient.ino b/libraries/Bridge/examples/XivelyClient/XivelyClient.ino
index 48b1403..69f979c 100644
--- a/libraries/Bridge/examples/XivelyClient/XivelyClient.ino
+++ b/libraries/Bridge/examples/XivelyClient/XivelyClient.ino
@@ -33,10 +33,10 @@ String dataString = "";
void setup() {
// start serial port:
Bridge.begin();
- Console.begin();
+ Serial.begin(9600);
- while(!Console); // wait for Network Console to open
- Console.println("Xively client");
+ while(!Serial); // wait for Network Serial to open
+ Serial.println("Xively client");
// Do a first update immediately
updateData();
@@ -83,7 +83,7 @@ void sendData() {
// sendData function finishes the resources are immediately
// released. Declaring it global works too, BTW.
Process xively;
- Console.print("\n\nSending data... ");
+ Serial.print("\n\nSending data... ");
xively.begin("curl");
xively.addParameter("-k");
xively.addParameter("--request");
@@ -94,13 +94,13 @@ void sendData() {
xively.addParameter(apiString);
xively.addParameter(url);
xively.run();
- Console.println("done!");
+ Serial.println("done!");
// If there's incoming data from the net connection,
- // send it out the Console:
+ // send it out the Serial:
while (xively.available()>0) {
char c = xively.read();
- Console.write(c);
+ Serial.write(c);
}
}