diff options
author | Federico Fissore <f.fissore@arduino.cc> | 2013-06-26 16:04:55 +0200 |
---|---|---|
committer | Federico Fissore <f.fissore@arduino.cc> | 2013-06-26 16:04:55 +0200 |
commit | bf82b241f55a34543e94cea854d819d0a607988c (patch) | |
tree | fae9fa99088155d956b9c408d02b13f547007dea /libraries/Bridge/examples/ShellCommands/ShellCommands.ino | |
parent | 4ba06563af4c74cb37aecf1b34136eec0772b5fb (diff) | |
parent | f07c6f2a52af85a63e9e4ebb98d4673b4183287a (diff) |
Merge branch 'ide-1.5.x-discovery' into dev-ide-1.5.x-discovery
Diffstat (limited to 'libraries/Bridge/examples/ShellCommands/ShellCommands.ino')
-rw-r--r-- | libraries/Bridge/examples/ShellCommands/ShellCommands.ino | 35 |
1 files changed, 23 insertions, 12 deletions
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 } + + |