mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-30 16:24:09 +03:00
Run new astyle formatter against all the examples
This commit is contained in:
@ -2,18 +2,18 @@
|
||||
Simple Audio Player
|
||||
|
||||
Demonstrates the use of the Audio library for the Arduino Due
|
||||
|
||||
|
||||
Hardware required :
|
||||
* Arduino shield with a SD card on CS4
|
||||
* A sound file named "test.wav" in the root directory of the SD card
|
||||
* A sound file named "test.wav" in the root directory of the SD card
|
||||
* An audio amplifier to connect to the DAC0 and ground
|
||||
* A speaker to connect to the audio amplifier
|
||||
* A speaker to connect to the audio amplifier
|
||||
|
||||
Original by Massimo Banzi September 20, 2012
|
||||
Modified by Scott Fitzgerald October 19, 2012
|
||||
|
||||
|
||||
This example code is in the public domain
|
||||
|
||||
|
||||
http://arduino.cc/en/Tutorial/SimpleAudioPlayer
|
||||
|
||||
*/
|
||||
@ -44,7 +44,7 @@ void setup()
|
||||
|
||||
void loop()
|
||||
{
|
||||
int count=0;
|
||||
int count = 0;
|
||||
|
||||
// open wave file from sdcard
|
||||
File myFile = SD.open("test.wav");
|
||||
@ -54,7 +54,7 @@ void loop()
|
||||
while (true);
|
||||
}
|
||||
|
||||
const int S=1024; // Number of samples to read in block
|
||||
const int S = 1024; // Number of samples to read in block
|
||||
short buffer[S];
|
||||
|
||||
Serial.print("Playing");
|
||||
|
@ -1,12 +1,12 @@
|
||||
/*
|
||||
Arduino Yun Bridge example
|
||||
|
||||
This example for the Arduino Yun shows how to use the
|
||||
Bridge library to access the digital and analog pins
|
||||
on the board through REST calls. It demonstrates how
|
||||
you can create your own API when using REST style
|
||||
|
||||
This example for the Arduino Yun shows how to use the
|
||||
Bridge library to access the digital and analog pins
|
||||
on the board through REST calls. It demonstrates how
|
||||
you can create your own API when using REST style
|
||||
calls through the browser.
|
||||
|
||||
|
||||
Possible commands created in this shetch:
|
||||
|
||||
* "/arduino/digital/13" -> digitalRead(13)
|
||||
@ -15,9 +15,9 @@
|
||||
* "/arduino/analog/2" -> analogRead(2)
|
||||
* "/arduino/mode/13/input" -> pinMode(13, INPUT)
|
||||
* "/arduino/mode/13/output" -> pinMode(13, OUTPUT)
|
||||
|
||||
|
||||
This example code is part of the public domain
|
||||
|
||||
|
||||
http://arduino.cc/en/Tutorial/Bridge
|
||||
|
||||
*/
|
||||
@ -32,7 +32,7 @@ YunServer server;
|
||||
|
||||
void setup() {
|
||||
// Bridge startup
|
||||
pinMode(13,OUTPUT);
|
||||
pinMode(13, OUTPUT);
|
||||
digitalWrite(13, LOW);
|
||||
Bridge.begin();
|
||||
digitalWrite(13, HIGH);
|
||||
@ -90,7 +90,7 @@ void digitalCommand(YunClient client) {
|
||||
if (client.read() == '/') {
|
||||
value = client.parseInt();
|
||||
digitalWrite(pin, value);
|
||||
}
|
||||
}
|
||||
else {
|
||||
value = digitalRead(pin);
|
||||
}
|
||||
|
@ -1,95 +1,95 @@
|
||||
/*
|
||||
ASCII table
|
||||
|
||||
Prints out byte values in all possible formats:
|
||||
|
||||
Prints out byte values in all possible formats:
|
||||
* as raw binary values
|
||||
* as ASCII-encoded decimal, hex, octal, and binary values
|
||||
|
||||
|
||||
For more on ASCII, see http://www.asciitable.com and http://en.wikipedia.org/wiki/ASCII
|
||||
|
||||
|
||||
The circuit: No external hardware needed.
|
||||
|
||||
|
||||
created 2006
|
||||
by Nicholas Zambetti
|
||||
by Nicholas Zambetti
|
||||
http://www.zambetti.com
|
||||
modified 9 Apr 2012
|
||||
by Tom Igoe
|
||||
modified 22 May 2013
|
||||
by Cristian Maglie
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
|
||||
http://arduino.cc/en/Tutorial/ConsoleAsciiTable
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#include <Console.h>
|
||||
|
||||
void setup() {
|
||||
//Initialize Console and wait for port to open:
|
||||
void setup() {
|
||||
//Initialize Console and wait for port to open:
|
||||
Bridge.begin();
|
||||
Console.begin();
|
||||
|
||||
Console.begin();
|
||||
|
||||
// Uncomment the following line to enable buffering:
|
||||
// - better transmission speed and efficiency
|
||||
// - needs to call Console.flush() to ensure that all
|
||||
// - needs to call Console.flush() to ensure that all
|
||||
// transmitted data is sent
|
||||
|
||||
|
||||
//Console.buffer(64);
|
||||
|
||||
|
||||
while (!Console) {
|
||||
; // wait for Console port to connect.
|
||||
}
|
||||
|
||||
// prints title with ending line break
|
||||
Console.println("ASCII Table ~ Character Map");
|
||||
}
|
||||
|
||||
// prints title with ending line break
|
||||
Console.println("ASCII Table ~ Character Map");
|
||||
}
|
||||
|
||||
// first visible ASCIIcharacter '!' is number 33:
|
||||
int thisByte = 33;
|
||||
int thisByte = 33;
|
||||
// you can also write ASCII characters in single quotes.
|
||||
// for example. '!' is the same as 33, so you could also use this:
|
||||
//int thisByte = '!';
|
||||
//int thisByte = '!';
|
||||
|
||||
void loop() {
|
||||
// prints value unaltered, i.e. the raw binary version of the
|
||||
// byte. The Console monitor interprets all bytes as
|
||||
// ASCII, so 33, the first number, will show up as '!'
|
||||
Console.write(thisByte);
|
||||
void loop() {
|
||||
// prints value unaltered, i.e. the raw binary version of the
|
||||
// byte. The Console monitor interprets all bytes as
|
||||
// ASCII, so 33, the first number, will show up as '!'
|
||||
Console.write(thisByte);
|
||||
|
||||
Console.print(", dec: ");
|
||||
Console.print(", dec: ");
|
||||
// prints value as string as an ASCII-encoded decimal (base 10).
|
||||
// Decimal is the default format for Console.print() and Console.println(),
|
||||
// so no modifier is needed:
|
||||
Console.print(thisByte);
|
||||
Console.print(thisByte);
|
||||
// But you can declare the modifier for decimal if you want to.
|
||||
//this also works if you uncomment it:
|
||||
|
||||
// Console.print(thisByte, DEC);
|
||||
// Console.print(thisByte, DEC);
|
||||
|
||||
Console.print(", hex: ");
|
||||
Console.print(", hex: ");
|
||||
// prints value as string in hexadecimal (base 16):
|
||||
Console.print(thisByte, HEX);
|
||||
Console.print(thisByte, HEX);
|
||||
|
||||
Console.print(", oct: ");
|
||||
Console.print(", oct: ");
|
||||
// prints value as string in octal (base 8);
|
||||
Console.print(thisByte, OCT);
|
||||
Console.print(thisByte, OCT);
|
||||
|
||||
Console.print(", bin: ");
|
||||
// prints value as string in binary (base 2)
|
||||
Console.print(", bin: ");
|
||||
// prints value as string in binary (base 2)
|
||||
// also prints ending line break:
|
||||
Console.println(thisByte, BIN);
|
||||
Console.println(thisByte, BIN);
|
||||
|
||||
// if printed last visible character '~' or 126, stop:
|
||||
if(thisByte == 126) { // you could also use if (thisByte == '~') {
|
||||
// if printed last visible character '~' or 126, stop:
|
||||
if (thisByte == 126) { // you could also use if (thisByte == '~') {
|
||||
// ensure the latest bit of data is sent
|
||||
Console.flush();
|
||||
|
||||
|
||||
// This loop loops forever and does nothing
|
||||
while(true) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
while (true) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// go on to the next character
|
||||
thisByte++;
|
||||
}
|
||||
thisByte++;
|
||||
}
|
||||
|
@ -1,30 +1,30 @@
|
||||
/*
|
||||
Console Pixel
|
||||
|
||||
An example of using the Arduino board to receive data from the
|
||||
|
||||
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 Yún'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
|
||||
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
|
||||
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
|
||||
http://arduino.cc/en/Tutorial/ConsolePixel
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <Console.h>
|
||||
@ -37,7 +37,7 @@ void setup() {
|
||||
Console.begin(); // Initialize Console
|
||||
|
||||
// Wait for the Console port to connect
|
||||
while(!Console);
|
||||
while (!Console);
|
||||
|
||||
Console.println("type H or L to turn pin 13 on or off");
|
||||
|
||||
@ -54,7 +54,7 @@ void loop() {
|
||||
// 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);
|
||||
|
@ -3,22 +3,22 @@
|
||||
|
||||
Read data coming from bridge using the Console.read() function
|
||||
and store it in a string.
|
||||
|
||||
|
||||
To see the Console, pick your Yún'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:
|
||||
and typing:
|
||||
ssh root@ yourYunsName.local 'telnet localhost 6571'
|
||||
then pressing enter. When prompted for the password, enter it.
|
||||
|
||||
|
||||
created 13 Jun 2013
|
||||
by Angelo Scialabba
|
||||
by Angelo Scialabba
|
||||
modified 16 June 2013
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
|
||||
http://arduino.cc/en/Tutorial/ConsoleRead
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <Console.h>
|
||||
@ -28,13 +28,13 @@ String name;
|
||||
void setup() {
|
||||
// Initialize Console and wait for port to open:
|
||||
Bridge.begin();
|
||||
Console.begin();
|
||||
Console.begin();
|
||||
|
||||
// Wait for Console port to connect
|
||||
while (!Console);
|
||||
|
||||
while (!Console);
|
||||
|
||||
Console.println("Hi, what's your name?");
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (Console.available() > 0) {
|
||||
@ -49,7 +49,7 @@ void loop() {
|
||||
// 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
|
||||
}
|
||||
|
@ -1,21 +1,21 @@
|
||||
/*
|
||||
SD card datalogger
|
||||
|
||||
This example shows how to log data from three analog sensors
|
||||
|
||||
This example shows how to log data from three analog sensors
|
||||
to an SD card mounted on the Arduino Yún using the Bridge library.
|
||||
|
||||
|
||||
The circuit:
|
||||
* analog sensors on analog pins 0, 1 and 2
|
||||
* SD card attached to SD card slot of the Arduino Yún
|
||||
|
||||
Prepare your SD card creating an empty folder in the SD root
|
||||
named "arduino". This will ensure that the Yún will create a link
|
||||
|
||||
Prepare your SD card creating an empty folder in the SD root
|
||||
named "arduino". This will ensure that the Yún will create a link
|
||||
to the SD to the "/mnt/sd" path.
|
||||
|
||||
You can remove the SD card while the Linux and the
|
||||
|
||||
You can remove the SD card while the Linux and the
|
||||
sketch are running but be careful not to remove it while
|
||||
the system is writing to it.
|
||||
|
||||
|
||||
created 24 Nov 2010
|
||||
modified 9 Apr 2012
|
||||
by Tom Igoe
|
||||
@ -23,11 +23,11 @@
|
||||
by Federico Vanzati
|
||||
modified 21 Jun 2013
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
|
||||
http://arduino.cc/en/Tutorial/YunDatalogger
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <FileIO.h>
|
||||
@ -38,7 +38,7 @@ void setup() {
|
||||
Serial.begin(9600);
|
||||
FileSystem.begin();
|
||||
|
||||
while(!Serial); // wait for Serial port to connect.
|
||||
while (!Serial); // wait for Serial port to connect.
|
||||
Serial.println("Filesystem datalogger\n");
|
||||
}
|
||||
|
||||
@ -69,12 +69,12 @@ void loop () {
|
||||
dataFile.close();
|
||||
// print to the serial port too:
|
||||
Serial.println(dataString);
|
||||
}
|
||||
}
|
||||
// if the file isn't open, pop up an error:
|
||||
else {
|
||||
Serial.println("error opening datalog.txt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
delay(15000);
|
||||
|
||||
}
|
||||
@ -83,19 +83,19 @@ void loop () {
|
||||
String getTimeStamp() {
|
||||
String result;
|
||||
Process time;
|
||||
// date is a command line utility to get the date and the time
|
||||
// in different formats depending on the additional parameter
|
||||
// date is a command line utility to get the date and the time
|
||||
// in different formats depending on the additional parameter
|
||||
time.begin("date");
|
||||
time.addParameter("+%D-%T"); // parameters: D for the complete date mm/dd/yy
|
||||
// T for the time hh:mm:ss
|
||||
// T for the time hh:mm:ss
|
||||
time.run(); // run the command
|
||||
|
||||
// read the output of the command
|
||||
while(time.available()>0) {
|
||||
while (time.available() > 0) {
|
||||
char c = time.read();
|
||||
if(c != '\n')
|
||||
if (c != '\n')
|
||||
result += c;
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -1,18 +1,18 @@
|
||||
/*
|
||||
Write to file using FileIO classes.
|
||||
|
||||
|
||||
This sketch demonstrate how to write file into the Yún filesystem.
|
||||
A shell script file is created in /tmp, and it is executed afterwards.
|
||||
|
||||
created 7 June 2010
|
||||
by Cristian Maglie
|
||||
|
||||
by Cristian Maglie
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
|
||||
http://arduino.cc/en/Tutorial/FileWriteScript
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#include <FileIO.h>
|
||||
|
||||
void setup() {
|
||||
@ -20,16 +20,16 @@ void setup() {
|
||||
Bridge.begin();
|
||||
// Initialize the Serial
|
||||
Serial.begin(9600);
|
||||
|
||||
while(!Serial); // wait for Serial port to connect.
|
||||
|
||||
while (!Serial); // wait for Serial port to connect.
|
||||
Serial.println("File Write Script example\n\n");
|
||||
|
||||
|
||||
// Setup File IO
|
||||
FileSystem.begin();
|
||||
|
||||
// Upload script used to gain network statistics
|
||||
// Upload script used to gain network statistics
|
||||
uploadScript();
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Run stats script every 5 secs.
|
||||
@ -41,10 +41,10 @@ void loop() {
|
||||
// to check the network traffic of the WiFi interface
|
||||
void uploadScript() {
|
||||
// Write our shell script in /tmp
|
||||
// Using /tmp stores the script in RAM this way we can preserve
|
||||
// Using /tmp stores the script in RAM this way we can preserve
|
||||
// the limited amount of FLASH erase/write cycles
|
||||
File script = FileSystem.open("/tmp/wlan-stats.sh", FILE_WRITE);
|
||||
// Shell script header
|
||||
// Shell script header
|
||||
script.print("#!/bin/sh\n");
|
||||
// shell commands:
|
||||
// ifconfig: is a command line utility for controlling the network interfaces.
|
||||
@ -53,7 +53,7 @@ void uploadScript() {
|
||||
// and extract the line that contains it
|
||||
script.print("ifconfig wlan0 | grep 'RX bytes'\n");
|
||||
script.close(); // close the file
|
||||
|
||||
|
||||
// Make the script executable
|
||||
Process chmod;
|
||||
chmod.begin("chmod"); // chmod: change mode
|
||||
@ -69,9 +69,9 @@ void runScript() {
|
||||
Process myscript;
|
||||
myscript.begin("/tmp/wlan-stats.sh");
|
||||
myscript.run();
|
||||
|
||||
|
||||
String output = "";
|
||||
|
||||
|
||||
// read the output of the script
|
||||
while (myscript.available()) {
|
||||
output += (char)myscript.read();
|
||||
|
@ -1,9 +1,9 @@
|
||||
/*
|
||||
Yun HTTP Client
|
||||
|
||||
This example for the Arduino Yún shows how create a basic
|
||||
HTTP client that connects to the internet and downloads
|
||||
content. In this case, you'll connect to the Arduino
|
||||
|
||||
This example for the Arduino Yún shows how create a basic
|
||||
HTTP client that connects to the internet and downloads
|
||||
content. In this case, you'll connect to the Arduino
|
||||
website and download a version of the logo as ASCII text.
|
||||
|
||||
created by Tom igoe
|
||||
@ -21,32 +21,32 @@
|
||||
void setup() {
|
||||
// Bridge takes about two seconds to start up
|
||||
// it can be helpful to use the on-board LED
|
||||
// as an indicator for when it has initialized
|
||||
// as an indicator for when it has initialized
|
||||
pinMode(13, OUTPUT);
|
||||
digitalWrite(13, LOW);
|
||||
Bridge.begin();
|
||||
digitalWrite(13, HIGH);
|
||||
|
||||
|
||||
Serial.begin(9600);
|
||||
|
||||
while(!Serial); // wait for a serial connection
|
||||
|
||||
while (!Serial); // wait for a serial connection
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Initialize the client library
|
||||
HttpClient client;
|
||||
|
||||
|
||||
// Make a HTTP request:
|
||||
client.get("http://arduino.cc/asciilogo.txt");
|
||||
|
||||
// if there are incoming bytes available
|
||||
// from the server, read them and print them:
|
||||
|
||||
// if there are incoming bytes available
|
||||
// from the server, read them and print them:
|
||||
while (client.available()) {
|
||||
char c = client.read();
|
||||
Serial.print(c);
|
||||
}
|
||||
Serial.flush();
|
||||
|
||||
|
||||
delay(5000);
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,14 @@
|
||||
/*
|
||||
Running process using Process class.
|
||||
|
||||
Running process using Process class.
|
||||
|
||||
This sketch demonstrate how to run linux processes
|
||||
using an Arduino Yún.
|
||||
|
||||
using an Arduino Yún.
|
||||
|
||||
created 5 Jun 2013
|
||||
by Cristian Maglie
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
|
||||
http://arduino.cc/en/Tutorial/Process
|
||||
|
||||
*/
|
||||
@ -18,10 +18,10 @@
|
||||
void setup() {
|
||||
// Initialize Bridge
|
||||
Bridge.begin();
|
||||
|
||||
|
||||
// Initialize Serial
|
||||
Serial.begin(9600);
|
||||
|
||||
|
||||
// Wait until a Serial Monitor is connected.
|
||||
while (!Serial);
|
||||
|
||||
@ -44,7 +44,7 @@ void runCurl() {
|
||||
|
||||
// Print arduino logo over the Serial
|
||||
// A process output can be read with the stream methods
|
||||
while (p.available()>0) {
|
||||
while (p.available() > 0) {
|
||||
char c = p.read();
|
||||
Serial.print(c);
|
||||
}
|
||||
@ -62,7 +62,7 @@ void runCpuInfo() {
|
||||
|
||||
// Print command output on the Serial.
|
||||
// A process output can be read with the stream methods
|
||||
while (p.available()>0) {
|
||||
while (p.available() > 0) {
|
||||
char c = p.read();
|
||||
Serial.print(c);
|
||||
}
|
||||
|
@ -1,24 +1,24 @@
|
||||
/*
|
||||
Running shell commands using Process class.
|
||||
|
||||
Running shell commands using Process class.
|
||||
|
||||
This sketch demonstrate how to run linux shell commands
|
||||
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 with LED connected to pin 9
|
||||
|
||||
|
||||
created 12 Jun 2013
|
||||
by Cristian Maglie
|
||||
modified 25 June 2013
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
|
||||
http://arduino.cc/en/Tutorial/ShellCommands
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <Process.h>
|
||||
@ -28,18 +28,18 @@ void setup() {
|
||||
Serial.begin(9600); // Initialize the Serial
|
||||
|
||||
// Wait until a Serial Monitor is connected.
|
||||
while(!Serial);
|
||||
while (!Serial);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Process p;
|
||||
// This command line runs the WifiStatus script, (/usr/bin/pretty-wifi-info.lua), then
|
||||
// This command line runs the WifiStatus script, (/usr/bin/pretty-wifi-info.lua), 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("/usr/bin/pretty-wifi-info.lua | grep Signal");
|
||||
|
||||
// do nothing until the process finishes, so you get the whole output:
|
||||
while(p.running());
|
||||
while (p.running());
|
||||
|
||||
// Read command output. runShellCommand() should have passed "Signal: xx&":
|
||||
while (p.available()) {
|
||||
@ -47,7 +47,7 @@ void loop() {
|
||||
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
|
||||
}
|
||||
}
|
||||
delay(5000); // wait 5 seconds before you do it again
|
||||
}
|
||||
|
||||
|
@ -2,23 +2,23 @@
|
||||
Input Output
|
||||
|
||||
Demonstrates how to create a sketch that sends and receives all standard
|
||||
spacebrew data types, and a custom data type. Every time data is
|
||||
spacebrew data types, and a custom data type. Every time data is
|
||||
received it is output to the Serial monitor.
|
||||
|
||||
Make sure that your Yun is connected to the internet for this example
|
||||
Make sure that your Yun is connected to the internet for this example
|
||||
to function properly.
|
||||
|
||||
|
||||
The circuit:
|
||||
- No circuit required
|
||||
|
||||
|
||||
created 2013
|
||||
by Julio Terra
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
More information about Spacebrew is available at:
|
||||
|
||||
More information about Spacebrew is available at:
|
||||
http://spacebrew.cc/
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <Bridge.h>
|
||||
@ -33,98 +33,100 @@ int interval = 2000;
|
||||
|
||||
int counter = 0;
|
||||
|
||||
void setup() {
|
||||
void setup() {
|
||||
|
||||
// start the serial port
|
||||
Serial.begin(57600);
|
||||
// start the serial port
|
||||
Serial.begin(57600);
|
||||
|
||||
// for debugging, wait until a serial console is connected
|
||||
delay(4000);
|
||||
while (!Serial) { ; }
|
||||
// for debugging, wait until a serial console is connected
|
||||
delay(4000);
|
||||
while (!Serial) {
|
||||
;
|
||||
}
|
||||
|
||||
// start-up the bridge
|
||||
Bridge.begin();
|
||||
// start-up the bridge
|
||||
Bridge.begin();
|
||||
|
||||
// configure the spacebrew object to print status messages to serial
|
||||
sb.verbose(true);
|
||||
// configure the spacebrew object to print status messages to serial
|
||||
sb.verbose(true);
|
||||
|
||||
// configure the spacebrew publisher and subscriber
|
||||
sb.addPublish("string test", "string");
|
||||
sb.addPublish("range test", "range");
|
||||
sb.addPublish("boolean test", "boolean");
|
||||
sb.addPublish("custom test", "crazy");
|
||||
sb.addSubscribe("string test", "string");
|
||||
sb.addSubscribe("range test", "range");
|
||||
sb.addSubscribe("boolean test", "boolean");
|
||||
sb.addSubscribe("custom test", "crazy");
|
||||
// configure the spacebrew publisher and subscriber
|
||||
sb.addPublish("string test", "string");
|
||||
sb.addPublish("range test", "range");
|
||||
sb.addPublish("boolean test", "boolean");
|
||||
sb.addPublish("custom test", "crazy");
|
||||
sb.addSubscribe("string test", "string");
|
||||
sb.addSubscribe("range test", "range");
|
||||
sb.addSubscribe("boolean test", "boolean");
|
||||
sb.addSubscribe("custom test", "crazy");
|
||||
|
||||
// register the string message handler method
|
||||
sb.onRangeMessage(handleRange);
|
||||
sb.onStringMessage(handleString);
|
||||
sb.onBooleanMessage(handleBoolean);
|
||||
sb.onCustomMessage(handleCustom);
|
||||
// register the string message handler method
|
||||
sb.onRangeMessage(handleRange);
|
||||
sb.onStringMessage(handleString);
|
||||
sb.onBooleanMessage(handleBoolean);
|
||||
sb.onCustomMessage(handleCustom);
|
||||
|
||||
// connect to cloud spacebrew server at "sandbox.spacebrew.cc"
|
||||
sb.connect("sandbox.spacebrew.cc");
|
||||
// connect to cloud spacebrew server at "sandbox.spacebrew.cc"
|
||||
sb.connect("sandbox.spacebrew.cc");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
// monitor spacebrew connection for new data
|
||||
sb.monitor();
|
||||
void loop() {
|
||||
// monitor spacebrew connection for new data
|
||||
sb.monitor();
|
||||
|
||||
// connected to spacebrew then send a string every 2 seconds
|
||||
if ( sb.connected() ) {
|
||||
// connected to spacebrew then send a string every 2 seconds
|
||||
if ( sb.connected() ) {
|
||||
|
||||
// check if it is time to send a new message
|
||||
if ( (millis() - last) > interval ) {
|
||||
String test_str_msg = "testing, testing, ";
|
||||
test_str_msg += counter;
|
||||
counter ++;
|
||||
// check if it is time to send a new message
|
||||
if ( (millis() - last) > interval ) {
|
||||
String test_str_msg = "testing, testing, ";
|
||||
test_str_msg += counter;
|
||||
counter ++;
|
||||
|
||||
sb.send("string test", test_str_msg);
|
||||
sb.send("range test", 500);
|
||||
sb.send("boolean test", true);
|
||||
sb.send("custom test", "youre loco");
|
||||
sb.send("string test", test_str_msg);
|
||||
sb.send("range test", 500);
|
||||
sb.send("boolean test", true);
|
||||
sb.send("custom test", "youre loco");
|
||||
|
||||
last = millis();
|
||||
last = millis();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// define handler methods, all standard data type handlers take two appropriate arguments
|
||||
|
||||
void handleRange (String route, int value) {
|
||||
Serial.print("Range msg ");
|
||||
Serial.print(route);
|
||||
Serial.print(", value ");
|
||||
Serial.println(value);
|
||||
Serial.print("Range msg ");
|
||||
Serial.print(route);
|
||||
Serial.print(", value ");
|
||||
Serial.println(value);
|
||||
}
|
||||
|
||||
void handleString (String route, String value) {
|
||||
Serial.print("String msg ");
|
||||
Serial.print(route);
|
||||
Serial.print(", value ");
|
||||
Serial.println(value);
|
||||
Serial.print("String msg ");
|
||||
Serial.print(route);
|
||||
Serial.print(", value ");
|
||||
Serial.println(value);
|
||||
}
|
||||
|
||||
void handleBoolean (String route, boolean value) {
|
||||
Serial.print("Boolen msg ");
|
||||
Serial.print(route);
|
||||
Serial.print(", value ");
|
||||
Serial.println(value ? "true" : "false");
|
||||
Serial.print("Boolen msg ");
|
||||
Serial.print(route);
|
||||
Serial.print(", value ");
|
||||
Serial.println(value ? "true" : "false");
|
||||
}
|
||||
|
||||
// custom data type handlers takes three String arguments
|
||||
|
||||
void handleCustom (String route, String value, String type) {
|
||||
Serial.print("Custom msg ");
|
||||
Serial.print(route);
|
||||
Serial.print(" of type ");
|
||||
Serial.print(type);
|
||||
Serial.print(", value ");
|
||||
Serial.println(value);
|
||||
Serial.print("Custom msg ");
|
||||
Serial.print(route);
|
||||
Serial.print(" of type ");
|
||||
Serial.print(type);
|
||||
Serial.print(", value ");
|
||||
Serial.println(value);
|
||||
}
|
||||
|
||||
|
@ -1,26 +1,26 @@
|
||||
/*
|
||||
Spacebrew Boolean
|
||||
|
||||
|
||||
Demonstrates how to create a sketch that sends and receives a
|
||||
boolean value to and from Spacebrew. Every time the buttton is
|
||||
pressed (or other digital input component) a spacebrew message
|
||||
is sent. The sketch also accepts analog range messages from
|
||||
boolean value to and from Spacebrew. Every time the buttton is
|
||||
pressed (or other digital input component) a spacebrew message
|
||||
is sent. The sketch also accepts analog range messages from
|
||||
other Spacebrew apps.
|
||||
|
||||
Make sure that your Yun is connected to the internet for this example
|
||||
Make sure that your Yun is connected to the internet for this example
|
||||
to function properly.
|
||||
|
||||
|
||||
The circuit:
|
||||
- Button connected to Yun, using the Arduino's internal pullup resistor.
|
||||
|
||||
|
||||
created 2013
|
||||
by Julio Terra
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
More information about Spacebrew is available at:
|
||||
|
||||
More information about Spacebrew is available at:
|
||||
http://spacebrew.cc/
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <Bridge.h>
|
||||
@ -33,57 +33,59 @@ SpacebrewYun sb = SpacebrewYun("spacebrewYun Boolean", "Boolean sender and recei
|
||||
int last_value = 0;
|
||||
|
||||
// create variables to manage interval between each time we send a string
|
||||
void setup() {
|
||||
void setup() {
|
||||
|
||||
// start the serial port
|
||||
Serial.begin(57600);
|
||||
// start the serial port
|
||||
Serial.begin(57600);
|
||||
|
||||
// for debugging, wait until a serial console is connected
|
||||
delay(4000);
|
||||
while (!Serial) { ; }
|
||||
// for debugging, wait until a serial console is connected
|
||||
delay(4000);
|
||||
while (!Serial) {
|
||||
;
|
||||
}
|
||||
|
||||
// start-up the bridge
|
||||
Bridge.begin();
|
||||
// start-up the bridge
|
||||
Bridge.begin();
|
||||
|
||||
// configure the spacebrew object to print status messages to serial
|
||||
sb.verbose(true);
|
||||
// configure the spacebrew object to print status messages to serial
|
||||
sb.verbose(true);
|
||||
|
||||
// configure the spacebrew publisher and subscriber
|
||||
sb.addPublish("physical button", "boolean");
|
||||
sb.addSubscribe("virtual button", "boolean");
|
||||
// configure the spacebrew publisher and subscriber
|
||||
sb.addPublish("physical button", "boolean");
|
||||
sb.addSubscribe("virtual button", "boolean");
|
||||
|
||||
// register the string message handler method
|
||||
sb.onBooleanMessage(handleBoolean);
|
||||
// register the string message handler method
|
||||
sb.onBooleanMessage(handleBoolean);
|
||||
|
||||
// connect to cloud spacebrew server at "sandbox.spacebrew.cc"
|
||||
sb.connect("sandbox.spacebrew.cc");
|
||||
// connect to cloud spacebrew server at "sandbox.spacebrew.cc"
|
||||
sb.connect("sandbox.spacebrew.cc");
|
||||
|
||||
pinMode(3, INPUT);
|
||||
digitalWrite(3, HIGH);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
// monitor spacebrew connection for new data
|
||||
sb.monitor();
|
||||
|
||||
// connected to spacebrew then send a new value whenever the pot value changes
|
||||
if ( sb.connected() ) {
|
||||
int cur_value = digitalRead(3);
|
||||
if ( last_value != cur_value ) {
|
||||
if (cur_value == HIGH) sb.send("physical button", false);
|
||||
else sb.send("physical button", true);
|
||||
last_value = cur_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// handler method that is called whenever a new string message is received
|
||||
void handleBoolean (String route, boolean value) {
|
||||
// print the message that was received
|
||||
Serial.print("From ");
|
||||
Serial.print(route);
|
||||
Serial.print(", received msg: ");
|
||||
Serial.println(value ? "true" : "false");
|
||||
pinMode(3, INPUT);
|
||||
digitalWrite(3, HIGH);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
// monitor spacebrew connection for new data
|
||||
sb.monitor();
|
||||
|
||||
// connected to spacebrew then send a new value whenever the pot value changes
|
||||
if ( sb.connected() ) {
|
||||
int cur_value = digitalRead(3);
|
||||
if ( last_value != cur_value ) {
|
||||
if (cur_value == HIGH) sb.send("physical button", false);
|
||||
else sb.send("physical button", true);
|
||||
last_value = cur_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// handler method that is called whenever a new string message is received
|
||||
void handleBoolean (String route, boolean value) {
|
||||
// print the message that was received
|
||||
Serial.print("From ");
|
||||
Serial.print(route);
|
||||
Serial.print(", received msg: ");
|
||||
Serial.println(value ? "true" : "false");
|
||||
}
|
||||
|
||||
|
@ -1,27 +1,27 @@
|
||||
/*
|
||||
Spacebrew Range
|
||||
|
||||
|
||||
Demonstrates how to create a sketch that sends and receives analog
|
||||
range value to and from Spacebrew. Every time the state of the
|
||||
range value to and from Spacebrew. Every time the state of the
|
||||
potentiometer (or other analog input component) change a spacebrew
|
||||
message is sent. The sketch also accepts analog range messages from
|
||||
message is sent. The sketch also accepts analog range messages from
|
||||
other Spacebrew apps.
|
||||
|
||||
Make sure that your Yun is connected to the internet for this example
|
||||
Make sure that your Yun is connected to the internet for this example
|
||||
to function properly.
|
||||
|
||||
|
||||
The circuit:
|
||||
- Potentiometer connected to Yun. Middle pin connected to analog pin A0,
|
||||
- Potentiometer connected to Yun. Middle pin connected to analog pin A0,
|
||||
other pins connected to 5v and GND pins.
|
||||
|
||||
|
||||
created 2013
|
||||
by Julio Terra
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
More information about Spacebrew is available at:
|
||||
|
||||
More information about Spacebrew is available at:
|
||||
http://spacebrew.cc/
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <Bridge.h>
|
||||
@ -34,53 +34,55 @@ SpacebrewYun sb = SpacebrewYun("spacebrewYun Range", "Range sender and receiver"
|
||||
int last_value = 0;
|
||||
|
||||
// create variables to manage interval between each time we send a string
|
||||
void setup() {
|
||||
void setup() {
|
||||
|
||||
// start the serial port
|
||||
Serial.begin(57600);
|
||||
// start the serial port
|
||||
Serial.begin(57600);
|
||||
|
||||
// for debugging, wait until a serial console is connected
|
||||
delay(4000);
|
||||
while (!Serial) { ; }
|
||||
// for debugging, wait until a serial console is connected
|
||||
delay(4000);
|
||||
while (!Serial) {
|
||||
;
|
||||
}
|
||||
|
||||
// start-up the bridge
|
||||
Bridge.begin();
|
||||
// start-up the bridge
|
||||
Bridge.begin();
|
||||
|
||||
// configure the spacebrew object to print status messages to serial
|
||||
sb.verbose(true);
|
||||
// configure the spacebrew object to print status messages to serial
|
||||
sb.verbose(true);
|
||||
|
||||
// configure the spacebrew publisher and subscriber
|
||||
sb.addPublish("physical pot", "range");
|
||||
sb.addSubscribe("virtual pot", "range");
|
||||
// configure the spacebrew publisher and subscriber
|
||||
sb.addPublish("physical pot", "range");
|
||||
sb.addSubscribe("virtual pot", "range");
|
||||
|
||||
// register the string message handler method
|
||||
sb.onRangeMessage(handleRange);
|
||||
// register the string message handler method
|
||||
sb.onRangeMessage(handleRange);
|
||||
|
||||
// connect to cloud spacebrew server at "sandbox.spacebrew.cc"
|
||||
sb.connect("sandbox.spacebrew.cc");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
// monitor spacebrew connection for new data
|
||||
sb.monitor();
|
||||
|
||||
// connected to spacebrew then send a new value whenever the pot value changes
|
||||
if ( sb.connected() ) {
|
||||
int cur_value = analogRead(A0);
|
||||
if ( last_value != cur_value ) {
|
||||
sb.send("physical pot", cur_value);
|
||||
last_value = cur_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// handler method that is called whenever a new string message is received
|
||||
void handleRange (String route, int value) {
|
||||
// print the message that was received
|
||||
Serial.print("From ");
|
||||
Serial.print(route);
|
||||
Serial.print(", received msg: ");
|
||||
Serial.println(value);
|
||||
// connect to cloud spacebrew server at "sandbox.spacebrew.cc"
|
||||
sb.connect("sandbox.spacebrew.cc");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
// monitor spacebrew connection for new data
|
||||
sb.monitor();
|
||||
|
||||
// connected to spacebrew then send a new value whenever the pot value changes
|
||||
if ( sb.connected() ) {
|
||||
int cur_value = analogRead(A0);
|
||||
if ( last_value != cur_value ) {
|
||||
sb.send("physical pot", cur_value);
|
||||
last_value = cur_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// handler method that is called whenever a new string message is received
|
||||
void handleRange (String route, int value) {
|
||||
// print the message that was received
|
||||
Serial.print("From ");
|
||||
Serial.print(route);
|
||||
Serial.print(", received msg: ");
|
||||
Serial.println(value);
|
||||
}
|
||||
|
||||
|
@ -1,24 +1,24 @@
|
||||
/*
|
||||
Spacebrew String
|
||||
|
||||
|
||||
Demonstrates how to create a sketch that sends and receives strings
|
||||
to and from Spacebrew. Every time string data is received it
|
||||
to and from Spacebrew. Every time string data is received it
|
||||
is output to the Serial monitor.
|
||||
|
||||
Make sure that your Yun is connected to the internet for this example
|
||||
Make sure that your Yun is connected to the internet for this example
|
||||
to function properly.
|
||||
|
||||
|
||||
The circuit:
|
||||
- No circuit required
|
||||
|
||||
|
||||
created 2013
|
||||
by Julio Terra
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
More information about Spacebrew is available at:
|
||||
|
||||
More information about Spacebrew is available at:
|
||||
http://spacebrew.cc/
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <Bridge.h>
|
||||
@ -31,54 +31,56 @@ SpacebrewYun sb = SpacebrewYun("spacebrewYun Strings", "String sender and receiv
|
||||
long last_time = 0;
|
||||
int interval = 2000;
|
||||
|
||||
void setup() {
|
||||
void setup() {
|
||||
|
||||
// start the serial port
|
||||
Serial.begin(57600);
|
||||
// start the serial port
|
||||
Serial.begin(57600);
|
||||
|
||||
// for debugging, wait until a serial console is connected
|
||||
delay(4000);
|
||||
while (!Serial) { ; }
|
||||
// for debugging, wait until a serial console is connected
|
||||
delay(4000);
|
||||
while (!Serial) {
|
||||
;
|
||||
}
|
||||
|
||||
// start-up the bridge
|
||||
Bridge.begin();
|
||||
// start-up the bridge
|
||||
Bridge.begin();
|
||||
|
||||
// configure the spacebrew object to print status messages to serial
|
||||
sb.verbose(true);
|
||||
// configure the spacebrew object to print status messages to serial
|
||||
sb.verbose(true);
|
||||
|
||||
// configure the spacebrew publisher and subscriber
|
||||
sb.addPublish("speak", "string");
|
||||
sb.addSubscribe("listen", "string");
|
||||
// configure the spacebrew publisher and subscriber
|
||||
sb.addPublish("speak", "string");
|
||||
sb.addSubscribe("listen", "string");
|
||||
|
||||
// register the string message handler method
|
||||
sb.onStringMessage(handleString);
|
||||
// register the string message handler method
|
||||
sb.onStringMessage(handleString);
|
||||
|
||||
// connect to cloud spacebrew server at "sandbox.spacebrew.cc"
|
||||
sb.connect("sandbox.spacebrew.cc");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
// monitor spacebrew connection for new data
|
||||
sb.monitor();
|
||||
|
||||
// connected to spacebrew then send a string every 2 seconds
|
||||
if ( sb.connected() ) {
|
||||
|
||||
// check if it is time to send a new message
|
||||
if ( (millis() - last_time) > interval ) {
|
||||
sb.send("speak", "is anybody out there?");
|
||||
last_time = millis();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// handler method that is called whenever a new string message is received
|
||||
void handleString (String route, String value) {
|
||||
// print the message that was received
|
||||
Serial.print("From ");
|
||||
Serial.print(route);
|
||||
Serial.print(", received msg: ");
|
||||
Serial.println(value);
|
||||
// connect to cloud spacebrew server at "sandbox.spacebrew.cc"
|
||||
sb.connect("sandbox.spacebrew.cc");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
// monitor spacebrew connection for new data
|
||||
sb.monitor();
|
||||
|
||||
// connected to spacebrew then send a string every 2 seconds
|
||||
if ( sb.connected() ) {
|
||||
|
||||
// check if it is time to send a new message
|
||||
if ( (millis() - last_time) > interval ) {
|
||||
sb.send("speak", "is anybody out there?");
|
||||
last_time = millis();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// handler method that is called whenever a new string message is received
|
||||
void handleString (String route, String value) {
|
||||
// print the message that was received
|
||||
Serial.print("From ");
|
||||
Serial.print(route);
|
||||
Serial.print(", received msg: ");
|
||||
Serial.println(value);
|
||||
}
|
||||
|
||||
|
@ -8,26 +8,26 @@
|
||||
|
||||
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
||||
|
||||
A Temboo account and application key are necessary to run all Temboo examples.
|
||||
If you don't already have one, you can register for a free Temboo account at
|
||||
A Temboo account and application key are necessary to run all Temboo examples.
|
||||
If you don't already have one, you can register for a free Temboo account at
|
||||
http://www.temboo.com
|
||||
|
||||
Since this sketch uses Twilio to retrieve the SMS, you'll also need a valid
|
||||
Since this sketch uses Twilio to retrieve the SMS, you'll also need a valid
|
||||
Twilio account. You can create one for free at https://www.twilio.com.
|
||||
|
||||
The sketch needs your Twilio Account SID and Auth Token you get when you
|
||||
register with Twilio. Make sure to use the Account SID and Auth Token from
|
||||
|
||||
The sketch needs your Twilio Account SID and Auth Token you get when you
|
||||
register with Twilio. Make sure to use the Account SID and Auth Token from
|
||||
your Twilio Dashboard (not your test credentials from the Dev Tools panel).
|
||||
|
||||
Normally, Twilio expects to contact a web site you provide to get a response
|
||||
when an SMS message is received for your Twilio number. In this case, we
|
||||
when an SMS message is received for your Twilio number. In this case, we
|
||||
don't want to send any response (and we don't want to have to set up a web
|
||||
site just to receive SMS messages.) You can use a URL that Twilio provides
|
||||
for this purpose. When a message is received and sent to the Twilio "twimlets"
|
||||
URL, it returns a code meaning "no response required." To set this up:
|
||||
|
||||
1. Log in to your Twilio account and go to this URL:
|
||||
|
||||
|
||||
https://www.twilio.com/user/account/phone-numbers/incoming
|
||||
|
||||
2. Select the Twilio number you want to receive SMS messages at.
|
||||
@ -40,7 +40,7 @@
|
||||
|
||||
https://www.twilio.com/help/faq/sms/how-can-i-receive-sms-messages-without-responding
|
||||
|
||||
4. Click the "Save Changes" button at the bottom of the page.
|
||||
4. Click the "Save Changes" button at the bottom of the page.
|
||||
|
||||
Your account will now receive SMS messages, but won't send any responses.
|
||||
|
||||
@ -48,14 +48,14 @@
|
||||
to the Internet.
|
||||
|
||||
Looking for another API? We've got over 100 in our Library!
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
|
||||
#include <Bridge.h>
|
||||
#include <Temboo.h>
|
||||
#include "TembooAccount.h" // contains Temboo account information
|
||||
// as described in the footer comment below
|
||||
// as described in the footer comment below
|
||||
|
||||
|
||||
|
||||
@ -85,7 +85,7 @@ unsigned long lastSMSCheckTime = -SMS_CHECK_PERIOD;
|
||||
// (we only need to process newer messages)
|
||||
String lastSid;
|
||||
|
||||
// we'll be turning the LED built in to the Yun on and off
|
||||
// we'll be turning the LED built in to the Yun on and off
|
||||
// to simulate controlling some device. That LED is on pin 13.
|
||||
int LED_PIN = 13;
|
||||
|
||||
@ -98,7 +98,7 @@ void setup() {
|
||||
|
||||
// for debugging, wait until a serial console is connected
|
||||
delay(4000);
|
||||
while(!Serial);
|
||||
while (!Serial);
|
||||
|
||||
// tell the board to treat the LED pin as an output.
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
@ -109,7 +109,7 @@ void setup() {
|
||||
// initialize the connection to the Linino processor.
|
||||
Bridge.begin();
|
||||
|
||||
// Twilio will report old SMS messages. We want to
|
||||
// Twilio will report old SMS messages. We want to
|
||||
// ignore any existing control messages when we start.
|
||||
Serial.println("Ignoring any existing control messages...");
|
||||
checkForMessages(true);
|
||||
@ -124,15 +124,15 @@ void loop()
|
||||
|
||||
// see if it's time to check for new SMS messages.
|
||||
if (now - lastSMSCheckTime >= SMS_CHECK_PERIOD) {
|
||||
|
||||
|
||||
// it's time to check for new messages
|
||||
// save this time so we know when to check next
|
||||
lastSMSCheckTime = now;
|
||||
|
||||
|
||||
if (numRuns <= maxRuns) {
|
||||
Serial.println("Checking for new SMS messages - Run #" + String(numRuns++));
|
||||
|
||||
// execute the choreo and don't ignore control messages.
|
||||
|
||||
// execute the choreo and don't ignore control messages.
|
||||
checkForMessages(false);
|
||||
} else {
|
||||
Serial.println("Already ran " + String(maxRuns) + " times.");
|
||||
@ -145,7 +145,7 @@ This function executes the Twilio > SMSMessages > ListMessages choreo
|
||||
and processes the results.
|
||||
|
||||
If ignoreCommands is 'true', this function will read and process messages
|
||||
updating 'lastSid', but will not actually take any action on any commands
|
||||
updating 'lastSid', but will not actually take any action on any commands
|
||||
found. This is so we can ignore any old control messages when we start.
|
||||
|
||||
If ignoreCommands is 'false', control messages WILL be acted on.
|
||||
@ -156,7 +156,7 @@ void checkForMessages(bool ignoreCommands) {
|
||||
TembooChoreo ListMessagesChoreo;
|
||||
|
||||
ListMessagesChoreo.begin();
|
||||
|
||||
|
||||
// set Temboo account credentials
|
||||
ListMessagesChoreo.setAccountName(TEMBOO_ACCOUNT);
|
||||
ListMessagesChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
||||
@ -166,12 +166,12 @@ void checkForMessages(bool ignoreCommands) {
|
||||
ListMessagesChoreo.setChoreo("/Library/Twilio/SMSMessages/ListMessages");
|
||||
|
||||
// set the choreo inputs
|
||||
// see https://www.temboo.com/library/Library/Twilio/SMSMessages/ListMessages/
|
||||
// see https://www.temboo.com/library/Library/Twilio/SMSMessages/ListMessages/
|
||||
// for complete details about the inputs for this Choreo
|
||||
|
||||
// the first input is a your Twilio AccountSID
|
||||
ListMessagesChoreo.addInput("AccountSID", TWILIO_ACCOUNT_SID);
|
||||
|
||||
|
||||
// next is your Twilio Auth Token
|
||||
ListMessagesChoreo.addInput("AuthToken", TWILIO_AUTH_TOKEN);
|
||||
|
||||
@ -179,24 +179,24 @@ void checkForMessages(bool ignoreCommands) {
|
||||
ListMessagesChoreo.addInput("From", FROM_PHONE_NUMBER);
|
||||
|
||||
// Twilio can return information about up to 1000 messages at a time.
|
||||
// we're only interested in the 3 most recent ones. Note that if
|
||||
// this account receives lots of messages in quick succession,
|
||||
// we're only interested in the 3 most recent ones. Note that if
|
||||
// this account receives lots of messages in quick succession,
|
||||
// (more than 3 per minute in this case), we might miss some control
|
||||
// messages. But if we request too many messages, we might run out of
|
||||
// messages. But if we request too many messages, we might run out of
|
||||
// memory on the Arduino side of the Yun.
|
||||
ListMessagesChoreo.addInput("PageSize", "3");
|
||||
|
||||
// We want the response in XML format to process with our
|
||||
// We want the response in XML format to process with our
|
||||
// XPath output filters.
|
||||
ListMessagesChoreo.addInput("ResponseFormat", "xml");
|
||||
|
||||
// we don't want everything from the output, just the
|
||||
// we don't want everything from the output, just the
|
||||
// message IDs (the Sids) and the message texts
|
||||
ListMessagesChoreo.addOutputFilter("sid", "Sid", "Response");
|
||||
ListMessagesChoreo.addOutputFilter("text", "Body", "Response");
|
||||
|
||||
// tell the Choreo to run and wait for the results. The
|
||||
// return code (returnCode) will tell us whether the Temboo client
|
||||
// tell the Choreo to run and wait for the results. The
|
||||
// return code (returnCode) will tell us whether the Temboo client
|
||||
// was able to send our request to the Temboo servers
|
||||
unsigned int returnCode = ListMessagesChoreo.run();
|
||||
|
||||
@ -204,7 +204,7 @@ void checkForMessages(bool ignoreCommands) {
|
||||
if (returnCode == 0) {
|
||||
|
||||
// Need a string to hold the list of message IDs.
|
||||
String messageSids;
|
||||
String messageSids;
|
||||
|
||||
// Need a string to hold the texts of the messages.
|
||||
String messageTexts;
|
||||
@ -214,8 +214,8 @@ void checkForMessages(bool ignoreCommands) {
|
||||
// lists containing the Sids and texts of the messages
|
||||
// from our designated phone number.
|
||||
|
||||
while(ListMessagesChoreo.available()) {
|
||||
|
||||
while (ListMessagesChoreo.available()) {
|
||||
|
||||
// output names are terminated with '\x1F' characters.
|
||||
String name = ListMessagesChoreo.readStringUntil('\x1F');
|
||||
name.trim();
|
||||
@ -236,46 +236,46 @@ void checkForMessages(bool ignoreCommands) {
|
||||
|
||||
// done reading output, close the Choreo to free up resources.
|
||||
ListMessagesChoreo.close();
|
||||
|
||||
// parse the comma delimited lists of messages and Sids
|
||||
|
||||
// parse the comma delimited lists of messages and Sids
|
||||
processMessages(messageTexts, messageSids, ignoreCommands);
|
||||
|
||||
} else {
|
||||
// a non-zero return code means there was an error
|
||||
// read and print the error message
|
||||
while(ListMessagesChoreo.available()) {
|
||||
while (ListMessagesChoreo.available()) {
|
||||
char c = ListMessagesChoreo.read();
|
||||
Serial.print(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
This function processes the lists of message texts and Sids.
|
||||
If a message contains a comma as part of the
|
||||
If a message contains a comma as part of the
|
||||
message text, that message will be enclosed in double quotes
|
||||
(") in the list. Example:
|
||||
|
||||
A message,"Hey, now",Another message text
|
||||
|
||||
If the message contains double quotes, it will be enclosed in
|
||||
double quotes AND the internal quotes will be doubled.
|
||||
double quotes AND the internal quotes will be doubled.
|
||||
Example:
|
||||
|
||||
"Hi ""Sam"" the man", Led on
|
||||
|
||||
NOTE! We are assuming that Twilio returns more recent messages
|
||||
first. This isn't officially documented by Twilio, but we've
|
||||
first. This isn't officially documented by Twilio, but we've
|
||||
not seen any other case.
|
||||
|
||||
'messageTexts' is a String containing a comma separated list of
|
||||
message texts with commas and quotes escaped as described above.
|
||||
|
||||
'messageSids' is a String containing a comma separated list of
|
||||
'messageSids' is a String containing a comma separated list of
|
||||
message Sids. Sids should not contain embedded commas or quotes.
|
||||
|
||||
'ignoreCommands' is a boolean. 'true' means and control messages
|
||||
will not be acted upon. 'false' means control messages will be
|
||||
'ignoreCommands' is a boolean. 'true' means and control messages
|
||||
will not be acted upon. 'false' means control messages will be
|
||||
acted upon in the usual way.
|
||||
*/
|
||||
void processMessages(String messageTexts, String messageSids, bool ignoreCommands) {
|
||||
@ -297,14 +297,14 @@ void processMessages(String messageTexts, String messageSids, bool ignoreCommand
|
||||
// find the start of the next item in the list
|
||||
i = messageSids.indexOf(',', sidsStart);
|
||||
if (i >= 0) {
|
||||
|
||||
|
||||
//extract a single Sid from the list.
|
||||
sid = messageSids.substring(sidsStart, i);
|
||||
sidsStart = i + 1;
|
||||
|
||||
// find the start of the next text in the list.
|
||||
// find the start of the next text in the list.
|
||||
// Note that we have to be prepared to handle embedded
|
||||
// quotes and commans in the message texts.
|
||||
// quotes and commans in the message texts.
|
||||
// The standard Arduino String class doesn't handle
|
||||
// this, so we have to write our own function to do it.
|
||||
i = quotedIndexOf(messageTexts, ',', textsStart);
|
||||
@ -314,12 +314,12 @@ void processMessages(String messageTexts, String messageSids, bool ignoreCommand
|
||||
text = messageTexts.substring(textsStart, i);
|
||||
textsStart = i + 1;
|
||||
|
||||
// process the Sid and text to see if it's a
|
||||
// process the Sid and text to see if it's a
|
||||
// control message.
|
||||
ledUpdated = processMessage(sid, text, ignoreCommands);
|
||||
}
|
||||
} else {
|
||||
|
||||
|
||||
// the last item in the lists won't have a comma at the end,
|
||||
// so we have to handle them specially.
|
||||
// Since we know this is the last item, we can just
|
||||
@ -333,9 +333,9 @@ void processMessages(String messageTexts, String messageSids, bool ignoreCommand
|
||||
|
||||
// keep going until either we run out of list items
|
||||
// or we run into a message we processed on a previous run.
|
||||
} while ((i >=0) && (sid != lastSid));
|
||||
|
||||
// print what we've found to the serial monitor,
|
||||
} while ((i >= 0) && (sid != lastSid));
|
||||
|
||||
// print what we've found to the serial monitor,
|
||||
// just so we can see what's going on.
|
||||
if (sid == lastSid) {
|
||||
if (ledUpdated)
|
||||
@ -359,17 +359,17 @@ A message with the text "LED ON" turns the LED on.
|
||||
A message with the text "LED OFF" turns the LED off.
|
||||
(Case is ignored.)
|
||||
|
||||
If 'ignoreCommands' is true, the actions described above will NOT
|
||||
take place.
|
||||
If 'ignoreCommands' is true, the actions described above will NOT
|
||||
take place.
|
||||
|
||||
It also updates the 'lastSid' global variable when
|
||||
It also updates the 'lastSid' global variable when
|
||||
a control message is processed.
|
||||
|
||||
It returns 'true' if the message was a control message, and
|
||||
'false' if it wasn't or if we've already processed this message.
|
||||
*/
|
||||
bool processMessage(String sid, String text, bool ignoreCommands) {
|
||||
|
||||
|
||||
// a flag to indicate whether this was a control message or not
|
||||
bool ledUpdated = false;
|
||||
|
||||
@ -377,7 +377,7 @@ bool processMessage(String sid, String text, bool ignoreCommands) {
|
||||
if (sid != lastSid) {
|
||||
|
||||
if (text.equalsIgnoreCase("LED ON")) {
|
||||
|
||||
|
||||
if (!ignoreCommands) {
|
||||
//turn on the LED
|
||||
digitalWrite(LED_PIN, HIGH);
|
||||
@ -394,7 +394,7 @@ bool processMessage(String sid, String text, bool ignoreCommands) {
|
||||
}
|
||||
|
||||
// If the LED state was updated, remember the Sid if this message.
|
||||
if (ledUpdated)
|
||||
if (ledUpdated)
|
||||
lastSid = sid;
|
||||
}
|
||||
return ledUpdated;
|
||||
@ -428,16 +428,16 @@ int quotedIndexOf(String s, char delim, int start) {
|
||||
by inserting your own Temboo account name and app key information. The contents of the file should
|
||||
look like:
|
||||
|
||||
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
||||
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
||||
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
||||
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
||||
|
||||
You can find your Temboo App Key information on the Temboo website,
|
||||
You can find your Temboo App Key information on the Temboo website,
|
||||
under My Account > Application Keys
|
||||
|
||||
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
|
||||
|
||||
Keeping your account information in a separate file means you can save it once,
|
||||
Keeping your account information in a separate file means you can save it once,
|
||||
then just distribute the main .ino file without worrying that you forgot to delete your credentials.
|
||||
*/
|
||||
|
||||
|
@ -1,26 +1,26 @@
|
||||
/*
|
||||
GetYahooWeatherReport
|
||||
|
||||
|
||||
Demonstrates making a request to the Yahoo! Weather API using Temboo from an Arduino Yun.
|
||||
|
||||
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
||||
|
||||
A Temboo account and application key are necessary to run all Temboo examples.
|
||||
If you don't already have one, you can register for a free Temboo account at
|
||||
|
||||
A Temboo account and application key are necessary to run all Temboo examples.
|
||||
If you don't already have one, you can register for a free Temboo account at
|
||||
http://www.temboo.com
|
||||
|
||||
|
||||
This example assumes basic familiarity with Arduino sketches, and that your Yun is connected
|
||||
to the Internet.
|
||||
|
||||
Looking for another API to use with your Arduino Yun? We've got over 100 in our Library!
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
|
||||
#include <Bridge.h>
|
||||
#include <Temboo.h>
|
||||
#include "TembooAccount.h" // contains Temboo account information
|
||||
// as described in the footer comment below
|
||||
// as described in the footer comment below
|
||||
|
||||
|
||||
// the address for which a weather forecast will be retrieved
|
||||
@ -32,10 +32,10 @@ int maxRuns = 10; // max number of times the Yahoo WeatherByAddress Choreo shou
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
|
||||
// for debugging, wait until a serial console is connected
|
||||
delay(4000);
|
||||
while(!Serial);
|
||||
while (!Serial);
|
||||
Bridge.begin();
|
||||
|
||||
}
|
||||
@ -44,13 +44,13 @@ void loop()
|
||||
{
|
||||
// while we haven't reached the max number of runs...
|
||||
if (numRuns <= maxRuns) {
|
||||
|
||||
|
||||
// print status
|
||||
Serial.println("Running GetWeatherByAddress - Run #" + String(numRuns++) + "...");
|
||||
|
||||
// create a TembooChoreo object to send a Choreo request to Temboo
|
||||
TembooChoreo GetWeatherByAddressChoreo;
|
||||
|
||||
|
||||
// invoke the Temboo client
|
||||
GetWeatherByAddressChoreo.begin();
|
||||
|
||||
@ -58,30 +58,30 @@ void loop()
|
||||
GetWeatherByAddressChoreo.setAccountName(TEMBOO_ACCOUNT);
|
||||
GetWeatherByAddressChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
||||
GetWeatherByAddressChoreo.setAppKey(TEMBOO_APP_KEY);
|
||||
|
||||
|
||||
// set the name of the choreo we want to run
|
||||
GetWeatherByAddressChoreo.setChoreo("/Library/Yahoo/Weather/GetWeatherByAddress");
|
||||
|
||||
|
||||
// set choreo inputs; in this case, the address for which to retrieve weather data
|
||||
// the Temboo client provides standardized calls to 100+ cloud APIs
|
||||
GetWeatherByAddressChoreo.addInput("Address", ADDRESS_FOR_FORECAST);
|
||||
|
||||
// add an output filter to extract the name of the city.
|
||||
GetWeatherByAddressChoreo.addOutputFilter("city", "/rss/channel/yweather:location/@city", "Response");
|
||||
|
||||
|
||||
// add an output filter to extract the current temperature
|
||||
GetWeatherByAddressChoreo.addOutputFilter("temperature", "/rss/channel/item/yweather:condition/@temp", "Response");
|
||||
|
||||
// add an output filter to extract the date and time of the last report.
|
||||
GetWeatherByAddressChoreo.addOutputFilter("date", "/rss/channel/item/yweather:condition/@date", "Response");
|
||||
|
||||
// run the choreo
|
||||
// run the choreo
|
||||
GetWeatherByAddressChoreo.run();
|
||||
|
||||
|
||||
// when the choreo results are available, print them to the serial monitor
|
||||
while(GetWeatherByAddressChoreo.available()) {
|
||||
|
||||
char c = GetWeatherByAddressChoreo.read();
|
||||
while (GetWeatherByAddressChoreo.available()) {
|
||||
|
||||
char c = GetWeatherByAddressChoreo.read();
|
||||
Serial.print(c);
|
||||
}
|
||||
GetWeatherByAddressChoreo.close();
|
||||
@ -101,15 +101,15 @@ void loop()
|
||||
by inserting your own Temboo account name and app key information. The contents of the file should
|
||||
look like:
|
||||
|
||||
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
||||
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
||||
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
||||
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
||||
|
||||
You can find your Temboo App Key information on the Temboo website,
|
||||
You can find your Temboo App Key information on the Temboo website,
|
||||
under My Account > Application Keys
|
||||
|
||||
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
|
||||
|
||||
Keeping your account information in a separate file means you can share the main .ino file without worrying
|
||||
Keeping your account information in a separate file means you can share the main .ino file without worrying
|
||||
that you forgot to delete your credentials.
|
||||
*/
|
||||
|
@ -1,33 +1,33 @@
|
||||
/*
|
||||
ReadATweet
|
||||
|
||||
Demonstrates retrieving the most recent Tweet from a user's home timeline
|
||||
Demonstrates retrieving the most recent Tweet from a user's home timeline
|
||||
using Temboo from an Arduino Yun.
|
||||
|
||||
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
||||
|
||||
A Temboo account and application key are necessary to run all Temboo examples.
|
||||
If you don't already have one, you can register for a free Temboo account at
|
||||
A Temboo account and application key are necessary to run all Temboo examples.
|
||||
If you don't already have one, you can register for a free Temboo account at
|
||||
http://www.temboo.com
|
||||
|
||||
In order to run this sketch, you'll need to register an application using
|
||||
the Twitter dev console at https://dev.twitter.com. After creating the
|
||||
app, you'll find OAuth credentials for that application under the "OAuth Tool" tab.
|
||||
Substitute these values for the placeholders below.
|
||||
the Twitter dev console at https://dev.twitter.com. After creating the
|
||||
app, you'll find OAuth credentials for that application under the "OAuth Tool" tab.
|
||||
Substitute these values for the placeholders below.
|
||||
|
||||
This example assumes basic familiarity with Arduino sketches, and that your Yun
|
||||
This example assumes basic familiarity with Arduino sketches, and that your Yun
|
||||
is connected to the Internet.
|
||||
|
||||
Want to use another social API with your Arduino Yun? We've got Facebook,
|
||||
Want to use another social API with your Arduino Yun? We've got Facebook,
|
||||
Google+, Instagram, Tumblr and more in our Library!
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
|
||||
#include <Bridge.h>
|
||||
#include <Temboo.h>
|
||||
#include "TembooAccount.h" // contains Temboo account information
|
||||
// as described in the footer comment below
|
||||
// as described in the footer comment below
|
||||
|
||||
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
|
||||
|
||||
@ -43,10 +43,10 @@ int maxRuns = 10; // the max number of times the Twitter HomeTimeline Choreo s
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
|
||||
// For debugging, wait until a serial console is connected.
|
||||
delay(4000);
|
||||
while(!Serial);
|
||||
while (!Serial);
|
||||
Bridge.begin();
|
||||
}
|
||||
void loop()
|
||||
@ -54,14 +54,14 @@ void loop()
|
||||
// while we haven't reached the max number of runs...
|
||||
if (numRuns <= maxRuns) {
|
||||
Serial.println("Running ReadATweet - Run #" + String(numRuns++));
|
||||
|
||||
|
||||
TembooChoreo HomeTimelineChoreo;
|
||||
|
||||
// invoke the Temboo client.
|
||||
// NOTE that the client must be reinvoked, and repopulated with
|
||||
// appropriate arguments, each time its run() method is called.
|
||||
HomeTimelineChoreo.begin();
|
||||
|
||||
|
||||
// set Temboo account credentials
|
||||
HomeTimelineChoreo.setAccountName(TEMBOO_ACCOUNT);
|
||||
HomeTimelineChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
||||
@ -69,8 +69,8 @@ void loop()
|
||||
|
||||
// tell the Temboo client which Choreo to run (Twitter > Timelines > HomeTimeline)
|
||||
HomeTimelineChoreo.setChoreo("/Library/Twitter/Timelines/HomeTimeline");
|
||||
|
||||
|
||||
|
||||
|
||||
// set the required choreo inputs
|
||||
// see https://www.temboo.com/library/Library/Twitter/Timelines/HomeTimeline/
|
||||
// for complete details about the inputs for this Choreo
|
||||
@ -78,44 +78,44 @@ void loop()
|
||||
HomeTimelineChoreo.addInput("Count", "1"); // the max number of Tweets to return from each request
|
||||
HomeTimelineChoreo.addInput("AccessToken", TWITTER_ACCESS_TOKEN);
|
||||
HomeTimelineChoreo.addInput("AccessTokenSecret", TWITTER_ACCESS_TOKEN_SECRET);
|
||||
HomeTimelineChoreo.addInput("ConsumerKey", TWITTER_CONSUMER_KEY);
|
||||
HomeTimelineChoreo.addInput("ConsumerKey", TWITTER_CONSUMER_KEY);
|
||||
HomeTimelineChoreo.addInput("ConsumerSecret", TWITTER_CONSUMER_SECRET);
|
||||
|
||||
// next, we'll define two output filters that let us specify the
|
||||
// next, we'll define two output filters that let us specify the
|
||||
// elements of the response from Twitter that we want to receive.
|
||||
// see the examples at http://www.temboo.com/arduino
|
||||
// for more on using output filters
|
||||
|
||||
|
||||
// we want the text of the tweet
|
||||
HomeTimelineChoreo.addOutputFilter("tweet", "/[1]/text", "Response");
|
||||
|
||||
|
||||
// and the name of the author
|
||||
HomeTimelineChoreo.addOutputFilter("author", "/[1]/user/screen_name", "Response");
|
||||
|
||||
|
||||
// tell the Process to run and wait for the results. The
|
||||
// return code will tell us whether the Temboo client
|
||||
// tell the Process to run and wait for the results. The
|
||||
// return code will tell us whether the Temboo client
|
||||
// was able to send our request to the Temboo servers
|
||||
unsigned int returnCode = HomeTimelineChoreo.run();
|
||||
|
||||
// a response code of 0 means success; print the API response
|
||||
if(returnCode == 0) {
|
||||
|
||||
|
||||
// a response code of 0 means success; print the API response
|
||||
if (returnCode == 0) {
|
||||
|
||||
String author; // a String to hold the tweet author's name
|
||||
String tweet; // a String to hold the text of the tweet
|
||||
|
||||
|
||||
// choreo outputs are returned as key/value pairs, delimited with
|
||||
// choreo outputs are returned as key/value pairs, delimited with
|
||||
// newlines and record/field terminator characters, for example:
|
||||
// Name1\n\x1F
|
||||
// Value1\n\x1E
|
||||
// Name2\n\x1F
|
||||
// Value2\n\x1E
|
||||
|
||||
// Value2\n\x1E
|
||||
|
||||
// see the examples at http://www.temboo.com/arduino for more details
|
||||
// we can read this format into separate variables, as follows:
|
||||
|
||||
while(HomeTimelineChoreo.available()) {
|
||||
|
||||
while (HomeTimelineChoreo.available()) {
|
||||
// read the name of the output item
|
||||
String name = HomeTimelineChoreo.readStringUntil('\x1F');
|
||||
name.trim();
|
||||
@ -131,13 +131,13 @@ void loop()
|
||||
author = data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Serial.println("@" + author + " - " + tweet);
|
||||
|
||||
|
||||
} else {
|
||||
// there was an error
|
||||
// print the raw output from the choreo
|
||||
while(HomeTimelineChoreo.available()) {
|
||||
while (HomeTimelineChoreo.available()) {
|
||||
char c = HomeTimelineChoreo.read();
|
||||
Serial.print(c);
|
||||
}
|
||||
@ -159,15 +159,15 @@ void loop()
|
||||
by inserting your own Temboo account name and app key information. The contents of the file should
|
||||
look like:
|
||||
|
||||
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
||||
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
||||
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
||||
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
||||
|
||||
You can find your Temboo App Key information on the Temboo website,
|
||||
You can find your Temboo App Key information on the Temboo website,
|
||||
under My Account > Application Keys
|
||||
|
||||
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
|
||||
|
||||
Keeping your account information in a separate file means you can share the main .ino file without worrying
|
||||
Keeping your account information in a separate file means you can share the main .ino file without worrying
|
||||
that you forgot to delete your credentials.
|
||||
*/
|
||||
|
@ -5,30 +5,30 @@
|
||||
|
||||
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
||||
|
||||
A Temboo account and application key are necessary to run all Temboo examples.
|
||||
If you don't already have one, you can register for a free Temboo account at
|
||||
A Temboo account and application key are necessary to run all Temboo examples.
|
||||
If you don't already have one, you can register for a free Temboo account at
|
||||
http://www.temboo.com
|
||||
|
||||
In order to run this sketch, you'll need to register an application using
|
||||
the Twitter dev console at https://dev.twitter.com. Note that since this
|
||||
the Twitter dev console at https://dev.twitter.com. Note that since this
|
||||
sketch creates a new tweet, your application will need to be configured with
|
||||
read+write permissions. After creating the app, you'll find OAuth credentials
|
||||
for that application under the "OAuth Tool" tab. Substitute these values for
|
||||
the placeholders below.
|
||||
read+write permissions. After creating the app, you'll find OAuth credentials
|
||||
for that application under the "OAuth Tool" tab. Substitute these values for
|
||||
the placeholders below.
|
||||
|
||||
This example assumes basic familiarity with Arduino sketches, and that your Yun is connected
|
||||
to the Internet.
|
||||
|
||||
Want to use another social API with your Arduino Yun? We've got Facebook,
|
||||
Want to use another social API with your Arduino Yun? We've got Facebook,
|
||||
Google+, Instagram, Tumblr and more in our Library!
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
|
||||
#include <Bridge.h>
|
||||
#include <Temboo.h>
|
||||
#include "TembooAccount.h" // contains Temboo account information
|
||||
// as described in the footer comment below
|
||||
// as described in the footer comment below
|
||||
|
||||
|
||||
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
|
||||
@ -48,7 +48,7 @@ void setup() {
|
||||
|
||||
// for debugging, wait until a serial console is connected
|
||||
delay(4000);
|
||||
while(!Serial);
|
||||
while (!Serial);
|
||||
|
||||
Bridge.begin();
|
||||
}
|
||||
@ -59,18 +59,18 @@ void loop()
|
||||
if (numRuns <= maxRuns) {
|
||||
|
||||
Serial.println("Running SendATweet - Run #" + String(numRuns++) + "...");
|
||||
|
||||
|
||||
// define the text of the tweet we want to send
|
||||
String tweetText("My Arduino Yun has been running for " + String(millis()) + " milliseconds.");
|
||||
|
||||
|
||||
|
||||
TembooChoreo StatusesUpdateChoreo;
|
||||
|
||||
// invoke the Temboo client
|
||||
// NOTE that the client must be reinvoked, and repopulated with
|
||||
// appropriate arguments, each time its run() method is called.
|
||||
StatusesUpdateChoreo.begin();
|
||||
|
||||
|
||||
// set Temboo account credentials
|
||||
StatusesUpdateChoreo.setAccountName(TEMBOO_ACCOUNT);
|
||||
StatusesUpdateChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
||||
@ -80,26 +80,26 @@ void loop()
|
||||
StatusesUpdateChoreo.setChoreo("/Library/Twitter/Tweets/StatusesUpdate");
|
||||
|
||||
// set the required choreo inputs
|
||||
// see https://www.temboo.com/library/Library/Twitter/Tweets/StatusesUpdate/
|
||||
// see https://www.temboo.com/library/Library/Twitter/Tweets/StatusesUpdate/
|
||||
// for complete details about the inputs for this Choreo
|
||||
|
||||
|
||||
// add the Twitter account information
|
||||
StatusesUpdateChoreo.addInput("AccessToken", TWITTER_ACCESS_TOKEN);
|
||||
StatusesUpdateChoreo.addInput("AccessTokenSecret", TWITTER_ACCESS_TOKEN_SECRET);
|
||||
StatusesUpdateChoreo.addInput("ConsumerKey", TWITTER_CONSUMER_KEY);
|
||||
StatusesUpdateChoreo.addInput("ConsumerKey", TWITTER_CONSUMER_KEY);
|
||||
StatusesUpdateChoreo.addInput("ConsumerSecret", TWITTER_CONSUMER_SECRET);
|
||||
|
||||
// and the tweet we want to send
|
||||
StatusesUpdateChoreo.addInput("StatusUpdate", tweetText);
|
||||
|
||||
// tell the Process to run and wait for the results. The
|
||||
// return code (returnCode) will tell us whether the Temboo client
|
||||
// tell the Process to run and wait for the results. The
|
||||
// return code (returnCode) will tell us whether the Temboo client
|
||||
// was able to send our request to the Temboo servers
|
||||
unsigned int returnCode = StatusesUpdateChoreo.run();
|
||||
|
||||
// a return code of zero (0) means everything worked
|
||||
if (returnCode == 0) {
|
||||
Serial.println("Success! Tweet sent!");
|
||||
Serial.println("Success! Tweet sent!");
|
||||
} else {
|
||||
// a non-zero return code means there was an error
|
||||
// read and print the error message
|
||||
@ -107,7 +107,7 @@ void loop()
|
||||
char c = StatusesUpdateChoreo.read();
|
||||
Serial.print(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
StatusesUpdateChoreo.close();
|
||||
|
||||
// do nothing for the next 90 seconds
|
||||
@ -124,15 +124,15 @@ void loop()
|
||||
by inserting your own Temboo account name and app key information. The contents of the file should
|
||||
look like:
|
||||
|
||||
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
||||
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
||||
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
||||
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
||||
|
||||
You can find your Temboo App Key information on the Temboo website,
|
||||
You can find your Temboo App Key information on the Temboo website,
|
||||
under My Account > Application Keys
|
||||
|
||||
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
|
||||
|
||||
Keeping your account information in a separate file means you can share the main .ino file without worrying
|
||||
Keeping your account information in a separate file means you can share the main .ino file without worrying
|
||||
that you forgot to delete your credentials.
|
||||
*/
|
||||
|
@ -5,17 +5,17 @@
|
||||
|
||||
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
||||
|
||||
A Temboo account and application key are necessary to run all Temboo examples.
|
||||
If you don't already have one, you can register for a free Temboo account at
|
||||
A Temboo account and application key are necessary to run all Temboo examples.
|
||||
If you don't already have one, you can register for a free Temboo account at
|
||||
http://www.temboo.com
|
||||
|
||||
Since this sketch uses Gmail to send the email, you'll also need a valid
|
||||
Google Gmail account. The sketch needs the username and password you use
|
||||
Since this sketch uses Gmail to send the email, you'll also need a valid
|
||||
Google Gmail account. The sketch needs the username and password you use
|
||||
to log into your Gmail account - substitute the placeholders below for these values.
|
||||
|
||||
This example assumes basic familiarity with Arduino sketches, and that your Yun is connected
|
||||
to the Internet.
|
||||
|
||||
|
||||
Looking for another API to use with your Arduino Yun? We've got over 100 in our Library!
|
||||
|
||||
This example code is in the public domain.
|
||||
@ -24,7 +24,7 @@
|
||||
#include <Bridge.h>
|
||||
#include <Temboo.h>
|
||||
#include "TembooAccount.h" // contains Temboo account information
|
||||
// as described in the footer comment below
|
||||
// as described in the footer comment below
|
||||
|
||||
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
|
||||
|
||||
@ -41,14 +41,14 @@ const String GMAIL_PASSWORD = "xxxxxxxxxx";
|
||||
const String TO_EMAIL_ADDRESS = "xxxxxxxxxx";
|
||||
|
||||
// a flag to indicate whether we've tried to send the email yet or not
|
||||
boolean attempted = false;
|
||||
boolean attempted = false;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
// for debugging, wait until a serial console is connected
|
||||
delay(4000);
|
||||
while(!Serial);
|
||||
while (!Serial);
|
||||
|
||||
Bridge.begin();
|
||||
}
|
||||
@ -59,14 +59,14 @@ void loop()
|
||||
if (!attempted) {
|
||||
|
||||
Serial.println("Running SendAnEmail...");
|
||||
|
||||
|
||||
TembooChoreo SendEmailChoreo;
|
||||
|
||||
// invoke the Temboo client
|
||||
// NOTE that the client must be reinvoked, and repopulated with
|
||||
// appropriate arguments, each time its run() method is called.
|
||||
SendEmailChoreo.begin();
|
||||
|
||||
|
||||
// set Temboo account credentials
|
||||
SendEmailChoreo.setAccountName(TEMBOO_ACCOUNT);
|
||||
SendEmailChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
||||
@ -74,13 +74,13 @@ void loop()
|
||||
|
||||
// identify the Temboo Library choreo to run (Google > Gmail > SendEmail)
|
||||
SendEmailChoreo.setChoreo("/Library/Google/Gmail/SendEmail");
|
||||
|
||||
|
||||
|
||||
// set the required choreo inputs
|
||||
// see https://www.temboo.com/library/Library/Google/Gmail/SendEmail/
|
||||
// see https://www.temboo.com/library/Library/Google/Gmail/SendEmail/
|
||||
// for complete details about the inputs for this Choreo
|
||||
|
||||
// the first input is your Gmail email address.
|
||||
// the first input is your Gmail email address.
|
||||
SendEmailChoreo.addInput("Username", GMAIL_USER_NAME);
|
||||
// next is your Gmail password.
|
||||
SendEmailChoreo.addInput("Password", GMAIL_PASSWORD);
|
||||
@ -89,17 +89,17 @@ void loop()
|
||||
// then a subject line
|
||||
SendEmailChoreo.addInput("Subject", "ALERT: Greenhouse Temperature");
|
||||
|
||||
// next comes the message body, the main content of the email
|
||||
// next comes the message body, the main content of the email
|
||||
SendEmailChoreo.addInput("MessageBody", "Hey! The greenhouse is too cold!");
|
||||
|
||||
// tell the Choreo to run and wait for the results. The
|
||||
// return code (returnCode) will tell us whether the Temboo client
|
||||
// tell the Choreo to run and wait for the results. The
|
||||
// return code (returnCode) will tell us whether the Temboo client
|
||||
// was able to send our request to the Temboo servers
|
||||
unsigned int returnCode = SendEmailChoreo.run();
|
||||
|
||||
// a return code of zero (0) means everything worked
|
||||
if (returnCode == 0) {
|
||||
Serial.println("Success! Email sent!");
|
||||
Serial.println("Success! Email sent!");
|
||||
} else {
|
||||
// a non-zero return code means there was an error
|
||||
// read and print the error message
|
||||
@ -107,9 +107,9 @@ void loop()
|
||||
char c = SendEmailChoreo.read();
|
||||
Serial.print(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
SendEmailChoreo.close();
|
||||
|
||||
|
||||
// set the flag showing we've tried
|
||||
attempted = true;
|
||||
}
|
||||
@ -123,15 +123,15 @@ void loop()
|
||||
by inserting your own Temboo account name and app key information. The contents of the file should
|
||||
look like:
|
||||
|
||||
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
||||
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
||||
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
||||
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
||||
|
||||
You can find your Temboo App Key information on the Temboo website,
|
||||
You can find your Temboo App Key information on the Temboo website,
|
||||
under My Account > Application Keys
|
||||
|
||||
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
|
||||
|
||||
Keeping your account information in a separate file means you can share the main .ino file without worrying
|
||||
Keeping your account information in a separate file means you can share the main .ino file without worrying
|
||||
that you forgot to delete your credentials.
|
||||
*/
|
||||
|
@ -5,35 +5,35 @@
|
||||
|
||||
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
||||
|
||||
A Temboo account and application key are necessary to run all Temboo examples.
|
||||
If you don't already have one, you can register for a free Temboo account at
|
||||
A Temboo account and application key are necessary to run all Temboo examples.
|
||||
If you don't already have one, you can register for a free Temboo account at
|
||||
http://www.temboo.com
|
||||
|
||||
Since this sketch uses Twilio to send the SMS, you'll also need a valid
|
||||
Since this sketch uses Twilio to send the SMS, you'll also need a valid
|
||||
Twilio account. You can create one for free at https://www.twilio.com.
|
||||
|
||||
|
||||
The sketch needs your Twilio phone number, along with
|
||||
the Account SID and Auth Token you get when you register with Twilio.
|
||||
Make sure to use the Account SID and Auth Token from your Twilio Dashboard
|
||||
Make sure to use the Account SID and Auth Token from your Twilio Dashboard
|
||||
(not your test credentials from the Dev Tools panel).
|
||||
|
||||
Also note that if you're using a free Twilio account, you'll need to verify
|
||||
Also note that if you're using a free Twilio account, you'll need to verify
|
||||
the phone number to which messages are being sent by going to twilio.com and following
|
||||
the instructions under the "Numbers > Verified Caller IDs" tab (this restriction
|
||||
doesn't apply if you have a paid Twilio account).
|
||||
|
||||
|
||||
This example assumes basic familiarity with Arduino sketches, and that your Yun is connected
|
||||
to the Internet.
|
||||
|
||||
Looking for another API to use with your Arduino Yun? We've got over 100 in our Library!
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
|
||||
#include <Bridge.h>
|
||||
#include <Temboo.h>
|
||||
#include "TembooAccount.h" // contains Temboo account information
|
||||
// as described in the footer comment below
|
||||
// as described in the footer comment below
|
||||
|
||||
|
||||
|
||||
@ -55,14 +55,14 @@ const String TWILIO_NUMBER = "xxxxxxxxxx";
|
||||
const String RECIPIENT_NUMBER = "xxxxxxxxxx";
|
||||
|
||||
// a flag to indicate whether we've attempted to send the SMS yet or not
|
||||
boolean attempted = false;
|
||||
boolean attempted = false;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
// for debugging, wait until a serial console is connected
|
||||
delay(4000);
|
||||
while(!Serial);
|
||||
while (!Serial);
|
||||
|
||||
Bridge.begin();
|
||||
}
|
||||
@ -73,7 +73,7 @@ void loop()
|
||||
if (!attempted) {
|
||||
|
||||
Serial.println("Running SendAnSMS...");
|
||||
|
||||
|
||||
// we need a Process object to send a Choreo request to Temboo
|
||||
TembooChoreo SendSMSChoreo;
|
||||
|
||||
@ -81,7 +81,7 @@ void loop()
|
||||
// NOTE that the client must be reinvoked and repopulated with
|
||||
// appropriate arguments each time its run() method is called.
|
||||
SendSMSChoreo.begin();
|
||||
|
||||
|
||||
// set Temboo account credentials
|
||||
SendSMSChoreo.setAccountName(TEMBOO_ACCOUNT);
|
||||
SendSMSChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
||||
@ -91,32 +91,32 @@ void loop()
|
||||
SendSMSChoreo.setChoreo("/Library/Twilio/SMSMessages/SendSMS");
|
||||
|
||||
// set the required choreo inputs
|
||||
// see https://www.temboo.com/library/Library/Twilio/SMSMessages/SendSMS/
|
||||
// see https://www.temboo.com/library/Library/Twilio/SMSMessages/SendSMS/
|
||||
// for complete details about the inputs for this Choreo
|
||||
|
||||
// the first input is a your AccountSID
|
||||
SendSMSChoreo.addInput("AccountSID", TWILIO_ACCOUNT_SID);
|
||||
|
||||
|
||||
// next is your Auth Token
|
||||
SendSMSChoreo.addInput("AuthToken", TWILIO_AUTH_TOKEN);
|
||||
|
||||
|
||||
// next is your Twilio phone number
|
||||
SendSMSChoreo.addInput("From", TWILIO_NUMBER);
|
||||
|
||||
|
||||
// next, what number to send the SMS to
|
||||
SendSMSChoreo.addInput("To", RECIPIENT_NUMBER);
|
||||
|
||||
// finally, the text of the message to send
|
||||
SendSMSChoreo.addInput("Body", "Hey, there! This is a message from your Arduino Yun!");
|
||||
|
||||
// tell the Process to run and wait for the results. The
|
||||
// return code (returnCode) will tell us whether the Temboo client
|
||||
|
||||
// tell the Process to run and wait for the results. The
|
||||
// return code (returnCode) will tell us whether the Temboo client
|
||||
// was able to send our request to the Temboo servers
|
||||
unsigned int returnCode = SendSMSChoreo.run();
|
||||
|
||||
// a return code of zero (0) means everything worked
|
||||
if (returnCode == 0) {
|
||||
Serial.println("Success! SMS sent!");
|
||||
Serial.println("Success! SMS sent!");
|
||||
} else {
|
||||
// a non-zero return code means there was an error
|
||||
// read and print the error message
|
||||
@ -124,11 +124,11 @@ void loop()
|
||||
char c = SendSMSChoreo.read();
|
||||
Serial.print(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
SendSMSChoreo.close();
|
||||
|
||||
|
||||
// set the flag indicatine we've tried once.
|
||||
attempted=true;
|
||||
attempted = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -140,15 +140,15 @@ void loop()
|
||||
by inserting your own Temboo account name and app key information. The contents of the file should
|
||||
look like:
|
||||
|
||||
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
||||
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
||||
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
||||
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
||||
|
||||
You can find your Temboo App Key information on the Temboo website,
|
||||
You can find your Temboo App Key information on the Temboo website,
|
||||
under My Account > Application Keys
|
||||
|
||||
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
|
||||
|
||||
Keeping your account information in a separate file means you can share the main .ino file without worrying
|
||||
Keeping your account information in a separate file means you can share the main .ino file without worrying
|
||||
that you forgot to delete your credentials.
|
||||
*/
|
||||
|
@ -5,14 +5,14 @@
|
||||
|
||||
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
||||
|
||||
A Temboo account and application key are necessary to run all Temboo examples.
|
||||
If you don't already have one, you can register for a free Temboo account at
|
||||
A Temboo account and application key are necessary to run all Temboo examples.
|
||||
If you don't already have one, you can register for a free Temboo account at
|
||||
http://www.temboo.com
|
||||
|
||||
Since this sketch uses a Google spreadsheet, you'll also need a
|
||||
Since this sketch uses a Google spreadsheet, you'll also need a
|
||||
Google account: substitute the placeholders below for your Google account values.
|
||||
|
||||
This example assumes basic familiarity with Arduino sketches, and that your
|
||||
This example assumes basic familiarity with Arduino sketches, and that your
|
||||
Yun is connected to the Internet.
|
||||
|
||||
The columns in your spreadsheet must have labels for the Choreo to
|
||||
@ -21,14 +21,14 @@
|
||||
assumes there are two columns. The first column is the time (in milliseconds)
|
||||
that the row was appended, and the second column is a sensor value.
|
||||
In other words, your spreadsheet should look like:
|
||||
|
||||
Time | Sensor Value |
|
||||
|
||||
Time | Sensor Value |
|
||||
------+-----------------
|
||||
| |
|
||||
|
||||
|
||||
NOTE that the first time you run this sketch, you may receive a warning from
|
||||
Google, prompting you to authorize access from a 3rd party system.
|
||||
|
||||
|
||||
Looking for another API to use with your Arduino Yun? We've got over 100 in our Library!
|
||||
|
||||
This example code is in the public domain.
|
||||
@ -38,7 +38,7 @@
|
||||
#include <Bridge.h>
|
||||
#include <Temboo.h>
|
||||
#include "TembooAccount.h" // contains Temboo account information,
|
||||
// as described in the footer comment below
|
||||
// as described in the footer comment below
|
||||
|
||||
|
||||
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
|
||||
@ -57,17 +57,17 @@ const String SPREADSHEET_TITLE = "your-spreadsheet-title";
|
||||
|
||||
const unsigned long RUN_INTERVAL_MILLIS = 60000; // how often to run the Choreo (in milliseconds)
|
||||
|
||||
// the last time we ran the Choreo
|
||||
// the last time we ran the Choreo
|
||||
// (initialized to 60 seconds ago so the
|
||||
// Choreo is run immediately when we start up)
|
||||
unsigned long lastRun = (unsigned long)-60000;
|
||||
unsigned long lastRun = (unsigned long) - 60000;
|
||||
|
||||
void setup() {
|
||||
|
||||
|
||||
// for debugging, wait until a serial console is connected
|
||||
Serial.begin(9600);
|
||||
delay(4000);
|
||||
while(!Serial);
|
||||
while (!Serial);
|
||||
|
||||
Serial.print("Initializing the bridge...");
|
||||
Bridge.begin();
|
||||
@ -84,7 +84,7 @@ void loop()
|
||||
|
||||
// remember 'now' as the last time we ran the choreo
|
||||
lastRun = now;
|
||||
|
||||
|
||||
Serial.println("Getting sensor value...");
|
||||
|
||||
// get the value we want to append to our spreadsheet
|
||||
@ -99,19 +99,19 @@ void loop()
|
||||
// NOTE that the client must be reinvoked and repopulated with
|
||||
// appropriate arguments each time its run() method is called.
|
||||
AppendRowChoreo.begin();
|
||||
|
||||
|
||||
// set Temboo account credentials
|
||||
AppendRowChoreo.setAccountName(TEMBOO_ACCOUNT);
|
||||
AppendRowChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
||||
AppendRowChoreo.setAppKey(TEMBOO_APP_KEY);
|
||||
|
||||
|
||||
// identify the Temboo Library choreo to run (Google > Spreadsheets > AppendRow)
|
||||
AppendRowChoreo.setChoreo("/Library/Google/Spreadsheets/AppendRow");
|
||||
|
||||
|
||||
// set the required Choreo inputs
|
||||
// see https://www.temboo.com/library/Library/Google/Spreadsheets/AppendRow/
|
||||
// see https://www.temboo.com/library/Library/Google/Spreadsheets/AppendRow/
|
||||
// for complete details about the inputs for this Choreo
|
||||
|
||||
|
||||
// your Google username (usually your email address)
|
||||
AppendRowChoreo.addInput("Username", GOOGLE_USERNAME);
|
||||
|
||||
@ -131,7 +131,7 @@ void loop()
|
||||
AppendRowChoreo.addInput("RowData", rowData);
|
||||
|
||||
// run the Choreo and wait for the results
|
||||
// The return code (returnCode) will indicate success or failure
|
||||
// The return code (returnCode) will indicate success or failure
|
||||
unsigned int returnCode = AppendRowChoreo.run();
|
||||
|
||||
// return code of zero (0) means success
|
||||
@ -139,7 +139,7 @@ void loop()
|
||||
Serial.println("Success! Appended " + rowData);
|
||||
Serial.println("");
|
||||
} else {
|
||||
// return code of anything other than zero means failure
|
||||
// return code of anything other than zero means failure
|
||||
// read and display any error messages
|
||||
while (AppendRowChoreo.available()) {
|
||||
char c = AppendRowChoreo.read();
|
||||
@ -151,7 +151,7 @@ void loop()
|
||||
}
|
||||
}
|
||||
|
||||
// this function simulates reading the value of a sensor
|
||||
// this function simulates reading the value of a sensor
|
||||
unsigned long getSensorValue() {
|
||||
return analogRead(A0);
|
||||
}
|
||||
@ -164,15 +164,15 @@ unsigned long getSensorValue() {
|
||||
by inserting your own Temboo account name and app key information. The contents of the file should
|
||||
look like:
|
||||
|
||||
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
||||
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
||||
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
||||
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
||||
|
||||
You can find your Temboo App Key information on the Temboo website,
|
||||
You can find your Temboo App Key information on the Temboo website,
|
||||
under My Account > Application Keys
|
||||
|
||||
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
|
||||
|
||||
Keeping your account information in a separate file means you can share the main .ino file without worrying
|
||||
Keeping your account information in a separate file means you can share the main .ino file without worrying
|
||||
that you forgot to delete your credentials.
|
||||
*/
|
||||
|
@ -1,28 +1,28 @@
|
||||
/*
|
||||
ToxicFacilitiesSearch
|
||||
|
||||
|
||||
Demonstrates making a request to the Envirofacts API using Temboo from an Arduino Yun.
|
||||
This example retrieves the names and addresses of EPA-regulated facilities in the
|
||||
This example retrieves the names and addresses of EPA-regulated facilities in the
|
||||
Toxins Release Inventory (TRI) database within a given zip code.
|
||||
|
||||
|
||||
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
||||
|
||||
A Temboo account and application key are necessary to run all Temboo examples.
|
||||
If you don't already have one, you can register for a free Temboo account at
|
||||
A Temboo account and application key are necessary to run all Temboo examples.
|
||||
If you don't already have one, you can register for a free Temboo account at
|
||||
http://www.temboo.com
|
||||
|
||||
|
||||
This example assumes basic familiarity with Arduino sketches, and that your Yun is connected
|
||||
to the Internet.
|
||||
|
||||
Looking for another API to use with your Arduino Yun? We've got over 100 in our Library!
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
|
||||
#include <Bridge.h>
|
||||
#include <Temboo.h>
|
||||
#include "TembooAccount.h" // contains Temboo account information
|
||||
// as described in the footer comment below
|
||||
// as described in the footer comment below
|
||||
|
||||
// the zip code to search for toxin-emitting facilities
|
||||
String US_ZIP_CODE = "11215";
|
||||
@ -32,10 +32,10 @@ int maxRuns = 10; // max number of times the Envirofacts FacilitiesSearch Chore
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
|
||||
// for debugging, wait until a serial console is connected
|
||||
delay(4000);
|
||||
while(!Serial);
|
||||
while (!Serial);
|
||||
Bridge.begin();
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ void loop()
|
||||
{
|
||||
// while we haven't reached the max number of runs...
|
||||
if (numRuns <= maxRuns) {
|
||||
|
||||
|
||||
// print status
|
||||
Serial.println("Running ToxicFacilitiesSearch - Run #" + String(numRuns++) + "...");
|
||||
|
||||
@ -54,26 +54,26 @@ void loop()
|
||||
// NOTE that the client must be reinvoked and repopulated with
|
||||
// appropriate arguments each time its run() method is called.
|
||||
FacilitiesSearchByZipChoreo.begin();
|
||||
|
||||
|
||||
// set Temboo account credentials
|
||||
FacilitiesSearchByZipChoreo.setAccountName(TEMBOO_ACCOUNT);
|
||||
FacilitiesSearchByZipChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
||||
FacilitiesSearchByZipChoreo.setAppKey(TEMBOO_APP_KEY);
|
||||
|
||||
|
||||
// identify the Temboo Library choreo to run (EnviroFacts > Toxins > FacilitiesSearchByZip)
|
||||
FacilitiesSearchByZipChoreo.setChoreo("/Library/EnviroFacts/Toxins/FacilitiesSearchByZip");
|
||||
|
||||
|
||||
// set choreo inputs; in this case, the US zip code for which to retrieve toxin release data
|
||||
// the Temboo client provides standardized calls to 100+ cloud APIs
|
||||
FacilitiesSearchByZipChoreo.addInput("Zip", US_ZIP_CODE);
|
||||
|
||||
|
||||
// specify two output filters, to help simplify the Envirofacts API results.
|
||||
// see the tutorials on using Temboo SDK output filters at http://www.temboo.com/arduino
|
||||
FacilitiesSearchByZipChoreo.addOutputFilter("fac", "FACILITY_NAME", "Response");
|
||||
|
||||
FacilitiesSearchByZipChoreo.addOutputFilter("addr", "STREET_ADDRESS", "Response");
|
||||
|
||||
// run the choreo
|
||||
// run the choreo
|
||||
unsigned int returnCode = FacilitiesSearchByZipChoreo.run();
|
||||
if (returnCode == 0) {
|
||||
String facilities;
|
||||
@ -83,7 +83,7 @@ void loop()
|
||||
// the output filters we specified will return comma delimited
|
||||
// lists containing the name and street address of the facilities
|
||||
// located in the specified zip code.
|
||||
while(FacilitiesSearchByZipChoreo.available()) {
|
||||
while (FacilitiesSearchByZipChoreo.available()) {
|
||||
String name = FacilitiesSearchByZipChoreo.readStringUntil('\x1F');
|
||||
name.trim();
|
||||
|
||||
@ -97,8 +97,8 @@ void loop()
|
||||
}
|
||||
}
|
||||
FacilitiesSearchByZipChoreo.close();
|
||||
|
||||
// parse the comma delimited lists of facilities to join the
|
||||
|
||||
// parse the comma delimited lists of facilities to join the
|
||||
// name with the address and print it to the serial monitor
|
||||
if (facilities.length() > 0) {
|
||||
int i = -1;
|
||||
@ -118,12 +118,12 @@ void loop()
|
||||
address = addresses.substring(addressStart, i);
|
||||
addressStart = i + 1;
|
||||
}
|
||||
|
||||
|
||||
if (i >= 0) {
|
||||
printResult(facility, address);
|
||||
}
|
||||
|
||||
}while (i >= 0);
|
||||
} while (i >= 0);
|
||||
facility = facilities.substring(facilityStart);
|
||||
address = addresses.substring(addressStart);
|
||||
printResult(facility, address);
|
||||
@ -131,7 +131,7 @@ void loop()
|
||||
Serial.println("No facilities found in zip code " + US_ZIP_CODE);
|
||||
}
|
||||
} else {
|
||||
while(FacilitiesSearchByZipChoreo.available()) {
|
||||
while (FacilitiesSearchByZipChoreo.available()) {
|
||||
char c = FacilitiesSearchByZipChoreo.read();
|
||||
Serial.print(c);
|
||||
}
|
||||
@ -157,15 +157,15 @@ void printResult(String facility, String address) {
|
||||
by inserting your own Temboo account name and app key information. The contents of the file should
|
||||
look like:
|
||||
|
||||
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
||||
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
||||
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
||||
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
||||
|
||||
You can find your Temboo App Key information on the Temboo website,
|
||||
You can find your Temboo App Key information on the Temboo website,
|
||||
under My Account > Application Keys
|
||||
|
||||
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
|
||||
|
||||
Keeping your account information in a separate file means you can share the main .ino file without worrying
|
||||
Keeping your account information in a separate file means you can share the main .ino file without worrying
|
||||
that you forgot to delete your credentials.
|
||||
*/
|
||||
|
@ -4,9 +4,9 @@
|
||||
Demonstrates sending a Facebook status update using Temboo from an Arduino Yun.
|
||||
|
||||
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
||||
|
||||
A Temboo account and application key are necessary to run all Temboo examples.
|
||||
If you don't already have one, you can register for a free Temboo account at
|
||||
|
||||
A Temboo account and application key are necessary to run all Temboo examples.
|
||||
If you don't already have one, you can register for a free Temboo account at
|
||||
http://www.temboo.com
|
||||
|
||||
In order to run this sketch, you'll need to register an application using
|
||||
@ -15,19 +15,19 @@
|
||||
to use our OAuth Wizard (or OAuth Choreos) to obtain a Facebook access token.
|
||||
Substitute your access token for the placeholder value of FACEBOOK_ACCESS_TOKEN below.
|
||||
|
||||
This example assumes basic familiarity with Arduino sketches, and that your Yun
|
||||
This example assumes basic familiarity with Arduino sketches, and that your Yun
|
||||
is connected to the Internet.
|
||||
|
||||
Want to use another social API with your Arduino Yun? We've got Twitter, Google+,
|
||||
|
||||
Want to use another social API with your Arduino Yun? We've got Twitter, Google+,
|
||||
Instagram, Tumblr and more in our Library!
|
||||
|
||||
This example code is in the public domain.
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
|
||||
#include <Bridge.h>
|
||||
#include <Temboo.h>
|
||||
#include "TembooAccount.h" // contains Temboo account information,
|
||||
// as described in the footer comment below
|
||||
// as described in the footer comment below
|
||||
|
||||
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
|
||||
|
||||
@ -43,10 +43,10 @@ int maxRuns = 10; // the max number of times the Facebook SetStatus Choreo shou
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
|
||||
// For debugging, wait until a serial console is connected.
|
||||
delay(4000);
|
||||
while(!Serial);
|
||||
while (!Serial);
|
||||
Bridge.begin();
|
||||
}
|
||||
|
||||
@ -56,19 +56,19 @@ void loop() {
|
||||
|
||||
// print status
|
||||
Serial.println("Running UpdateFacebookStatus - Run #" + String(numRuns++) + "...");
|
||||
|
||||
|
||||
// Define the status message we want to post on Facebook; since Facebook
|
||||
// doesn't allow duplicate status messages, we'll include a changing value.
|
||||
String statusMsg = "My Arduino Yun has been running for " + String(millis()) + " milliseconds!";
|
||||
|
||||
// define the Process that will be used to call the "temboo" client
|
||||
// define the Process that will be used to call the "temboo" client
|
||||
TembooChoreo SetStatusChoreo;
|
||||
|
||||
// invoke the Temboo client
|
||||
// NOTE that the client must be reinvoked and repopulated with
|
||||
// appropriate arguments each time its run() method is called.
|
||||
SetStatusChoreo.begin();
|
||||
|
||||
|
||||
// set Temboo account credentials
|
||||
SetStatusChoreo.setAccountName(TEMBOO_ACCOUNT);
|
||||
SetStatusChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
||||
@ -80,23 +80,23 @@ void loop() {
|
||||
// set the required choreo inputs
|
||||
// see https://www.temboo.com/library/Library/Facebook/Publishing/SetStatus/
|
||||
// for complete details about the inputs for this Choreo
|
||||
|
||||
SetStatusChoreo.addInput("AccessToken", FACEBOOK_ACCESS_TOKEN);
|
||||
|
||||
SetStatusChoreo.addInput("AccessToken", FACEBOOK_ACCESS_TOKEN);
|
||||
SetStatusChoreo.addInput("Message", statusMsg);
|
||||
|
||||
|
||||
// tell the Process to run and wait for the results. The
|
||||
// return code (returnCode) will tell us whether the Temboo client
|
||||
// tell the Process to run and wait for the results. The
|
||||
// return code (returnCode) will tell us whether the Temboo client
|
||||
// was able to send our request to the Temboo servers
|
||||
unsigned int returnCode = SetStatusChoreo.run();
|
||||
|
||||
|
||||
// print the response code and API response.
|
||||
Serial.println("Response code: " + String(returnCode));
|
||||
|
||||
// note that in this case, we're just printing the raw response from Facebook.
|
||||
// see the examples on using Temboo SDK output filters at http://www.temboo.com/arduino
|
||||
// for information on how to filter this data
|
||||
while(SetStatusChoreo.available()) {
|
||||
// for information on how to filter this data
|
||||
while (SetStatusChoreo.available()) {
|
||||
char c = SetStatusChoreo.read();
|
||||
Serial.print(c);
|
||||
}
|
||||
@ -107,7 +107,7 @@ void loop() {
|
||||
Serial.println("Waiting...");
|
||||
Serial.println("");
|
||||
|
||||
delay(30000); // wait 30 seconds between SetStatus calls
|
||||
delay(30000); // wait 30 seconds between SetStatus calls
|
||||
}
|
||||
|
||||
/*
|
||||
@ -118,15 +118,15 @@ void loop() {
|
||||
by inserting your own Temboo account name and app key information. The contents of the file should
|
||||
look like:
|
||||
|
||||
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
||||
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
||||
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
||||
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
||||
|
||||
You can find your Temboo App Key information on the Temboo website,
|
||||
You can find your Temboo App Key information on the Temboo website,
|
||||
under My Account > Application Keys
|
||||
|
||||
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
|
||||
|
||||
Keeping your account information in a separate file means you can share the main .ino file without worrying
|
||||
Keeping your account information in a separate file means you can share the main .ino file without worrying
|
||||
that you forgot to delete your credentials.
|
||||
*/
|
||||
|
@ -1,23 +1,23 @@
|
||||
/*
|
||||
UploadToDropbox
|
||||
|
||||
|
||||
Demonstrates uploading a file to a Dropbox account using Temboo from an Arduino Yun.
|
||||
|
||||
|
||||
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
||||
|
||||
A Temboo account and application key are necessary to run all Temboo examples.
|
||||
If you don't already have one, you can register for a free Temboo account at
|
||||
A Temboo account and application key are necessary to run all Temboo examples.
|
||||
If you don't already have one, you can register for a free Temboo account at
|
||||
http://www.temboo.com
|
||||
|
||||
You'll also need a valid Dropbox app and accompanying OAuth credentials.
|
||||
To create a Dropbox app, visit https://www.dropbox.com/developers/apps and
|
||||
You'll also need a valid Dropbox app and accompanying OAuth credentials.
|
||||
To create a Dropbox app, visit https://www.dropbox.com/developers/apps and
|
||||
do the following:
|
||||
|
||||
|
||||
1. Create a "Dropbox API app"
|
||||
2. Select "Files and datastores"
|
||||
3. Select "Yes - my app only needs access to the files it creates."
|
||||
|
||||
Once you've created your app, follow the instructions at
|
||||
|
||||
Once you've created your app, follow the instructions at
|
||||
https://www.temboo.com/library/Library/Dropbox/OAuth/ to run the Initialize and Finalize
|
||||
OAuth Choreos. These Choreos complete the OAuth handshake and retrieve your Dropbox OAuth access tokens.
|
||||
|
||||
@ -25,14 +25,14 @@
|
||||
to the Internet.
|
||||
|
||||
Looking for another API to use with your Arduino Yun? We've got over 100 in our Library!
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
|
||||
#include <Bridge.h>
|
||||
#include <Temboo.h>
|
||||
#include "TembooAccount.h" // contains Temboo account information
|
||||
// as described in the footer comment below
|
||||
// as described in the footer comment below
|
||||
|
||||
|
||||
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
|
||||
@ -43,7 +43,7 @@
|
||||
// your Dropbox app key, available on the Dropbox developer console after registering an app
|
||||
const String DROPBOX_APP_KEY = "xxxxxxxxxx";
|
||||
|
||||
// your Dropbox app secret, available on the Dropbox developer console after registering an app
|
||||
// your Dropbox app secret, available on the Dropbox developer console after registering an app
|
||||
const String DROPBOX_APP_SECRET = "xxxxxxxxxx";
|
||||
|
||||
// your Dropbox access token, which is returned by the FinalizeOAuth Choreo
|
||||
@ -57,10 +57,10 @@ boolean success = false; // a flag to indicate whether we've uploaded the file y
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
|
||||
// For debugging, wait until a serial console is connected.
|
||||
delay(4000);
|
||||
while(!Serial);
|
||||
while (!Serial);
|
||||
Bridge.begin();
|
||||
}
|
||||
|
||||
@ -68,23 +68,23 @@ void loop()
|
||||
{
|
||||
// only try to upload the file if we haven't already done so
|
||||
if (!success) {
|
||||
|
||||
|
||||
Serial.println("Base64 encoding data to upload...");
|
||||
|
||||
|
||||
// base64 encode the data to upload
|
||||
String base64EncodedData = base64Encode("Hello, Arduino!");
|
||||
|
||||
|
||||
Serial.println("Uploading data to Dropbox...");
|
||||
|
||||
// we need a Process object to send a Choreo request to Temboo
|
||||
// we need a Process object to send a Choreo request to Temboo
|
||||
TembooChoreo UploadFileChoreo;
|
||||
|
||||
// invoke the Temboo client
|
||||
// NOTE that the client must be reinvoked and repopulated with
|
||||
// appropriate arguments each time its run() method is called.
|
||||
UploadFileChoreo.begin();
|
||||
|
||||
|
||||
// set Temboo account credentials
|
||||
UploadFileChoreo.setAccountName(TEMBOO_ACCOUNT);
|
||||
UploadFileChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
||||
@ -92,7 +92,7 @@ void loop()
|
||||
|
||||
// identify the Temboo Library choreo to run (Dropbox > FilesAndMetadata > UploadFile)
|
||||
UploadFileChoreo.setChoreo("/Library/Dropbox/FilesAndMetadata/UploadFile");
|
||||
|
||||
|
||||
// set the required choreo inputs
|
||||
// see https://www.temboo.com/library/Library/Dropbox/FilesAndMetadata/UploadFile/
|
||||
// for complete details about the inputs for this Choreo
|
||||
@ -103,31 +103,31 @@ void loop()
|
||||
// next, the root folder on Dropbox relative to which the file path is specified.
|
||||
// to work with the Dropbox app you created earlier, this should be left as "sandbox"
|
||||
// if your Dropbox app has full access to your files, specify "dropbox"
|
||||
UploadFileChoreo.addInput("Root","sandbox");
|
||||
UploadFileChoreo.addInput("Root", "sandbox");
|
||||
|
||||
// next, the Base64 encoded file data to upload
|
||||
UploadFileChoreo.addInput("FileContents", base64EncodedData);
|
||||
|
||||
|
||||
// finally, the Dropbox OAuth credentials defined above
|
||||
UploadFileChoreo.addInput("AppSecret", DROPBOX_APP_SECRET);
|
||||
UploadFileChoreo.addInput("AccessToken", DROPBOX_ACCESS_TOKEN);
|
||||
UploadFileChoreo.addInput("AccessTokenSecret", DROPBOX_ACCESS_TOKEN_SECRET);
|
||||
UploadFileChoreo.addInput("AppKey", DROPBOX_APP_KEY);
|
||||
|
||||
// tell the Process to run and wait for the results. The
|
||||
// return code (returnCode) will tell us whether the Temboo client
|
||||
// tell the Process to run and wait for the results. The
|
||||
// return code (returnCode) will tell us whether the Temboo client
|
||||
// was able to send our request to the Temboo servers
|
||||
unsigned int returnCode = UploadFileChoreo.run();
|
||||
|
||||
// a return code of zero (0) means everything worked
|
||||
if (returnCode == 0) {
|
||||
Serial.println("Success! File uploaded!");
|
||||
success = true;
|
||||
Serial.println("Success! File uploaded!");
|
||||
success = true;
|
||||
} else {
|
||||
// a non-zero return code means there was an error
|
||||
Serial.println("Uh-oh! Something went wrong!");
|
||||
}
|
||||
|
||||
|
||||
// print out the full response to the serial monitor in all
|
||||
// cases, just for debugging
|
||||
while (UploadFileChoreo.available()) {
|
||||
@ -148,42 +148,42 @@ void loop()
|
||||
by calling a Temboo Utilities Choreo.
|
||||
*/
|
||||
String base64Encode(String toEncode) {
|
||||
|
||||
// we need a Process object to send a Choreo request to Temboo
|
||||
TembooChoreo Base64EncodeChoreo;
|
||||
|
||||
// invoke the Temboo client
|
||||
Base64EncodeChoreo.begin();
|
||||
|
||||
// set Temboo account credentials
|
||||
Base64EncodeChoreo.setAccountName(TEMBOO_ACCOUNT);
|
||||
Base64EncodeChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
||||
Base64EncodeChoreo.setAppKey(TEMBOO_APP_KEY);
|
||||
// we need a Process object to send a Choreo request to Temboo
|
||||
TembooChoreo Base64EncodeChoreo;
|
||||
|
||||
// identify the Temboo Library choreo to run (Utilities > Encoding > Base64Encode)
|
||||
Base64EncodeChoreo.setChoreo("/Library/Utilities/Encoding/Base64Encode");
|
||||
|
||||
// set choreo inputs
|
||||
Base64EncodeChoreo.addInput("Text", toEncode);
|
||||
|
||||
// run the choreo
|
||||
Base64EncodeChoreo.run();
|
||||
|
||||
// read in the choreo results, and return the "Base64EncodedText" output value.
|
||||
// see http://www.temboo.com/arduino for more details on using choreo outputs.
|
||||
while(Base64EncodeChoreo.available()) {
|
||||
// read the name of the output item
|
||||
String name = Base64EncodeChoreo.readStringUntil('\x1F');
|
||||
name.trim();
|
||||
// invoke the Temboo client
|
||||
Base64EncodeChoreo.begin();
|
||||
|
||||
// read the value of the output item
|
||||
String data = Base64EncodeChoreo.readStringUntil('\x1E');
|
||||
data.trim();
|
||||
// set Temboo account credentials
|
||||
Base64EncodeChoreo.setAccountName(TEMBOO_ACCOUNT);
|
||||
Base64EncodeChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
||||
Base64EncodeChoreo.setAppKey(TEMBOO_APP_KEY);
|
||||
|
||||
if(name == "Base64EncodedText") {
|
||||
return data;
|
||||
}
|
||||
// identify the Temboo Library choreo to run (Utilities > Encoding > Base64Encode)
|
||||
Base64EncodeChoreo.setChoreo("/Library/Utilities/Encoding/Base64Encode");
|
||||
|
||||
// set choreo inputs
|
||||
Base64EncodeChoreo.addInput("Text", toEncode);
|
||||
|
||||
// run the choreo
|
||||
Base64EncodeChoreo.run();
|
||||
|
||||
// read in the choreo results, and return the "Base64EncodedText" output value.
|
||||
// see http://www.temboo.com/arduino for more details on using choreo outputs.
|
||||
while (Base64EncodeChoreo.available()) {
|
||||
// read the name of the output item
|
||||
String name = Base64EncodeChoreo.readStringUntil('\x1F');
|
||||
name.trim();
|
||||
|
||||
// read the value of the output item
|
||||
String data = Base64EncodeChoreo.readStringUntil('\x1E');
|
||||
data.trim();
|
||||
|
||||
if (name == "Base64EncodedText") {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -194,15 +194,15 @@ String base64Encode(String toEncode) {
|
||||
by inserting your own Temboo account name and app key information. The contents of the file should
|
||||
look like:
|
||||
|
||||
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
||||
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
||||
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
||||
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
||||
|
||||
You can find your Temboo App Key information on the Temboo website,
|
||||
You can find your Temboo App Key information on the Temboo website,
|
||||
under My Account > Application Keys
|
||||
|
||||
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
|
||||
|
||||
Keeping your account information in a separate file means you can share the main .ino file without worrying
|
||||
Keeping your account information in a separate file means you can share the main .ino file without worrying
|
||||
that you forgot to delete your credentials.
|
||||
*/
|
||||
|
@ -1,41 +1,41 @@
|
||||
/*
|
||||
Temperature web interface
|
||||
|
||||
This example shows how to serve data from an analog input
|
||||
|
||||
This example shows how to serve data from an analog input
|
||||
via the Arduino Yún's built-in webserver using the Bridge library.
|
||||
|
||||
|
||||
The circuit:
|
||||
* TMP36 temperature sensor on analog pin A1
|
||||
* SD card attached to SD card slot of the Arduino Yún
|
||||
|
||||
Prepare your SD card with an empty folder in the SD root
|
||||
named "arduino" and a subfolder of that named "www".
|
||||
This will ensure that the Yún will create a link
|
||||
|
||||
Prepare your SD card with an empty folder in the SD root
|
||||
named "arduino" and a subfolder of that named "www".
|
||||
This will ensure that the Yún will create a link
|
||||
to the SD to the "/mnt/sd" path.
|
||||
|
||||
In this sketch folder is a basic webpage and a copy of zepto.js, a
|
||||
|
||||
In this sketch folder is a basic webpage and a copy of zepto.js, a
|
||||
minimized version of jQuery. When you upload your sketch, these files
|
||||
will be placed in the /arduino/www/TemperatureWebPanel folder on your SD card.
|
||||
|
||||
|
||||
You can then go to http://arduino.local/sd/TemperatureWebPanel
|
||||
to see the output of this sketch.
|
||||
|
||||
You can remove the SD card while the Linux and the
|
||||
|
||||
You can remove the SD card while the Linux and the
|
||||
sketch are running but be careful not to remove it while
|
||||
the system is writing to it.
|
||||
|
||||
|
||||
created 6 July 2013
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
|
||||
http://arduino.cc/en/Tutorial/TemperatureWebPanel
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <Bridge.h>
|
||||
#include <YunServer.h>
|
||||
#include <YunClient.h>
|
||||
#include <YunClient.h>
|
||||
|
||||
// Listen on default port 5555, the webserver on the Yun
|
||||
// will forward there all the HTTP requests for us.
|
||||
@ -47,7 +47,7 @@ void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
// Bridge startup
|
||||
pinMode(13,OUTPUT);
|
||||
pinMode(13, OUTPUT);
|
||||
digitalWrite(13, LOW);
|
||||
Bridge.begin();
|
||||
digitalWrite(13, HIGH);
|
||||
@ -66,7 +66,7 @@ void setup() {
|
||||
// get the time that this sketch started:
|
||||
Process startTime;
|
||||
startTime.runShellCommand("date");
|
||||
while(startTime.available()) {
|
||||
while (startTime.available()) {
|
||||
char c = startTime.read();
|
||||
startString += c;
|
||||
}
|
||||
@ -89,16 +89,16 @@ void loop() {
|
||||
Process time;
|
||||
time.runShellCommand("date");
|
||||
String timeString = "";
|
||||
while(time.available()) {
|
||||
while (time.available()) {
|
||||
char c = time.read();
|
||||
timeString += c;
|
||||
}
|
||||
Serial.println(timeString);
|
||||
int sensorValue = analogRead(A1);
|
||||
// convert the reading to millivolts:
|
||||
float voltage = sensorValue * (5000/ 1024);
|
||||
float voltage = sensorValue * (5000 / 1024);
|
||||
// convert the millivolts to temperature celsius:
|
||||
float temperature = (voltage - 500)/10;
|
||||
float temperature = (voltage - 500) / 10;
|
||||
// print the temperature:
|
||||
client.print("Current time on the Yún: ");
|
||||
client.println(timeString);
|
||||
|
@ -1,16 +1,16 @@
|
||||
/*
|
||||
Time Check
|
||||
|
||||
Time Check
|
||||
|
||||
Gets the time from the linino processor via Bridge
|
||||
then parses out hours, minutes and seconds for the Arduino
|
||||
using an Arduino Yún.
|
||||
|
||||
using an Arduino Yún.
|
||||
|
||||
created 27 May 2013
|
||||
modified 21 June 2013
|
||||
By Tom Igoe
|
||||
By Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
|
||||
http://arduino.cc/en/Tutorial/TimeCheck
|
||||
|
||||
*/
|
||||
@ -24,14 +24,14 @@ int lastSecond = -1; // need an impossible value for comparison
|
||||
|
||||
void setup() {
|
||||
Bridge.begin(); // initialize Bridge
|
||||
Serial.begin(9600); // initialize serial
|
||||
|
||||
while(!Serial); // wait for Serial Monitor to open
|
||||
Serial.begin(9600); // initialize serial
|
||||
|
||||
while (!Serial); // wait for Serial Monitor to open
|
||||
Serial.println("Time Check"); // Title of sketch
|
||||
|
||||
// run an initial date process. Should return:
|
||||
// hh:mm:ss :
|
||||
if (!date.running()) {
|
||||
if (!date.running()) {
|
||||
date.begin("date");
|
||||
date.addParameter("+%T");
|
||||
date.run();
|
||||
@ -40,10 +40,10 @@ void setup() {
|
||||
|
||||
void loop() {
|
||||
|
||||
if(lastSecond != seconds) { // if a second has passed
|
||||
if (lastSecond != seconds) { // if a second has passed
|
||||
// print the time:
|
||||
if (hours <= 9) Serial.print("0"); // adjust for 0-9
|
||||
Serial.print(hours);
|
||||
Serial.print(hours);
|
||||
Serial.print(":");
|
||||
if (minutes <= 9) Serial.print("0"); // adjust for 0-9
|
||||
Serial.print(minutes);
|
||||
@ -52,7 +52,7 @@ void loop() {
|
||||
Serial.println(seconds);
|
||||
|
||||
// restart the date process:
|
||||
if (!date.running()) {
|
||||
if (!date.running()) {
|
||||
date.begin("date");
|
||||
date.addParameter("+%T");
|
||||
date.run();
|
||||
@ -60,24 +60,24 @@ void loop() {
|
||||
}
|
||||
|
||||
//if there's a result from the date process, parse it:
|
||||
while (date.available()>0) {
|
||||
while (date.available() > 0) {
|
||||
// get the result of the date process (should be hh:mm:ss):
|
||||
String timeString = date.readString();
|
||||
String timeString = date.readString();
|
||||
|
||||
// find the colons:
|
||||
int firstColon = timeString.indexOf(":");
|
||||
int secondColon= timeString.lastIndexOf(":");
|
||||
int secondColon = timeString.lastIndexOf(":");
|
||||
|
||||
// get the substrings for hour, minute second:
|
||||
String hourString = timeString.substring(0, firstColon);
|
||||
String minString = timeString.substring(firstColon+1, secondColon);
|
||||
String secString = timeString.substring(secondColon+1);
|
||||
String hourString = timeString.substring(0, firstColon);
|
||||
String minString = timeString.substring(firstColon + 1, secondColon);
|
||||
String secString = timeString.substring(secondColon + 1);
|
||||
|
||||
// convert to ints,saving the previous second:
|
||||
hours = hourString.toInt();
|
||||
minutes = minString.toInt();
|
||||
lastSecond = seconds; // save to do a time comparison
|
||||
seconds = secString.toInt();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
WiFi Status
|
||||
|
||||
WiFi Status
|
||||
|
||||
This sketch runs a script called "pretty-wifi-info.lua"
|
||||
installed on your Yún in folder /usr/bin.
|
||||
It prints information about the status of your wifi connection.
|
||||
@ -11,22 +11,22 @@
|
||||
|
||||
created 18 June 2013
|
||||
By Federico Fissore
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
|
||||
http://arduino.cc/en/Tutorial/YunWiFiStatus
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <Process.h>
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600); // initialize serial communication
|
||||
while(!Serial); // do nothing until the serial monitor is opened
|
||||
|
||||
while (!Serial); // do nothing until the serial monitor is opened
|
||||
|
||||
Serial.println("Starting bridge...\n");
|
||||
pinMode(13,OUTPUT);
|
||||
digitalWrite(13, LOW);
|
||||
pinMode(13, OUTPUT);
|
||||
digitalWrite(13, LOW);
|
||||
Bridge.begin(); // make contact with the linux processor
|
||||
digitalWrite(13, HIGH); // Led on pin 13 turns on when the bridge is ready
|
||||
|
||||
@ -38,15 +38,15 @@ void loop() {
|
||||
|
||||
wifiCheck.runShellCommand("/usr/bin/pretty-wifi-info.lua"); // command you want to run
|
||||
|
||||
// while there's any characters coming back from the
|
||||
// while there's any characters coming back from the
|
||||
// process, print them to the serial monitor:
|
||||
while (wifiCheck.available() > 0) {
|
||||
char c = wifiCheck.read();
|
||||
Serial.print(c);
|
||||
}
|
||||
|
||||
|
||||
Serial.println();
|
||||
|
||||
|
||||
delay(5000);
|
||||
}
|
||||
|
||||
|
@ -1,15 +1,15 @@
|
||||
/*
|
||||
Xively sensor client with Strings
|
||||
|
||||
Xively sensor client with Strings
|
||||
|
||||
This sketch connects an analog sensor to Xively,
|
||||
using an Arduino Yún.
|
||||
|
||||
using an Arduino Yún.
|
||||
|
||||
created 15 March 2010
|
||||
updated 27 May 2013
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
http://arduino.cc/en/Tutorial/YunXivelyClient
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
NOTE: passwords.h is not included with this repo because it contains my passwords.
|
||||
You need to create it for your own version of this application. To do so, make
|
||||
a new tab in Arduino, call it passwords.h, and include the following variables and constants:
|
||||
|
||||
|
||||
#define APIKEY "foo" // replace your pachube api key here
|
||||
#define FEEDID 0000 // replace your feed ID
|
||||
#define USERAGENT "my-project" // user agent is the project name
|
||||
@ -38,7 +38,7 @@ void setup() {
|
||||
Bridge.begin();
|
||||
Serial.begin(9600);
|
||||
|
||||
while(!Serial); // wait for Network Serial to open
|
||||
while (!Serial); // wait for Network Serial to open
|
||||
Serial.println("Xively client");
|
||||
|
||||
// Do a first update immediately
|
||||
@ -94,14 +94,14 @@ void sendData() {
|
||||
xively.addParameter("--data");
|
||||
xively.addParameter(dataString);
|
||||
xively.addParameter("--header");
|
||||
xively.addParameter(apiString);
|
||||
xively.addParameter(apiString);
|
||||
xively.addParameter(url);
|
||||
xively.run();
|
||||
Serial.println("done!");
|
||||
|
||||
// If there's incoming data from the net connection,
|
||||
// send it out the Serial:
|
||||
while (xively.available()>0) {
|
||||
while (xively.available() > 0) {
|
||||
char c = xively.read();
|
||||
Serial.write(c);
|
||||
}
|
||||
|
@ -1,35 +1,35 @@
|
||||
/*
|
||||
Arduino Yun USB-to-Serial
|
||||
|
||||
|
||||
Allows you to use the Yun's 32U4 processor as a
|
||||
serial terminal for the linino processor.
|
||||
|
||||
Upload this to an Arduino Yun via serial (not WiFi)
|
||||
|
||||
Upload this to an Arduino Yun via serial (not WiFi)
|
||||
then open the serial monitor at 115200 to see the boot process
|
||||
of the linino processor. You can also use the serial monitor
|
||||
as a basic command line interface for the linino processor using
|
||||
as a basic command line interface for the linino processor using
|
||||
this sketch.
|
||||
|
||||
|
||||
From the serial monitor the following commands can be issued:
|
||||
|
||||
|
||||
'~' followed by '0' -> Set the UART speed to 57600 baud
|
||||
'~' followed by '1' -> Set the UART speed to 115200 baud
|
||||
'~' followed by '2' -> Set the UART speed to 250000 baud
|
||||
'~' followed by '3' -> Set the UART speed to 500000 baud
|
||||
'~' followeb by '~' -> Sends the bridge's shutdown command to
|
||||
obtain the console.
|
||||
|
||||
|
||||
The circuit:
|
||||
* Arduino Yun
|
||||
|
||||
|
||||
created March 2013
|
||||
by Massimo Banzi
|
||||
modified by Cristian Maglie
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
|
||||
http://arduino.cc/en/Tutorial/YunSerialTerminal
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
@ -75,8 +75,8 @@ void loop() {
|
||||
commandMode = false; // in all cases exit from command mode
|
||||
}
|
||||
}
|
||||
if (Serial1.available()) { // got anything from Linino?
|
||||
char c = (char)Serial1.read(); // read from Linino
|
||||
if (Serial1.available()) { // got anything from Linino?
|
||||
char c = (char)Serial1.read(); // read from Linino
|
||||
Serial.write(c); // write to USB-serial
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ void setup()
|
||||
// write a 0 to all 512 bytes of the EEPROM
|
||||
for (int i = 0; i < 512; i++)
|
||||
EEPROM.write(i, 0);
|
||||
|
||||
|
||||
// turn the LED on when we're done
|
||||
digitalWrite(13, HIGH);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* EEPROM Read
|
||||
*
|
||||
* Reads the value of each byte of the EEPROM and prints it
|
||||
* Reads the value of each byte of the EEPROM and prints it
|
||||
* to the computer.
|
||||
* This example code is in the public domain.
|
||||
*/
|
||||
@ -25,19 +25,19 @@ void loop()
|
||||
{
|
||||
// read a byte from the current address of the EEPROM
|
||||
value = EEPROM.read(address);
|
||||
|
||||
|
||||
Serial.print(address);
|
||||
Serial.print("\t");
|
||||
Serial.print(value, DEC);
|
||||
Serial.println();
|
||||
|
||||
|
||||
// advance to the next address of the EEPROM
|
||||
address = address + 1;
|
||||
|
||||
|
||||
// there are only 512 bytes of EEPROM, from 0 to 511, so if we're
|
||||
// on address 512, wrap around to address 0
|
||||
if (address == 512)
|
||||
address = 0;
|
||||
|
||||
|
||||
delay(500);
|
||||
}
|
||||
|
@ -22,17 +22,17 @@ void loop()
|
||||
// 0 to 1023 and each byte of the EEPROM can only hold a
|
||||
// value from 0 to 255.
|
||||
int val = analogRead(0) / 4;
|
||||
|
||||
|
||||
// write the value to the appropriate byte of the EEPROM.
|
||||
// these values will remain there when the board is
|
||||
// turned off.
|
||||
EEPROM.write(addr, val);
|
||||
|
||||
// advance to the next address. there are 512 bytes in
|
||||
|
||||
// advance to the next address. there are 512 bytes in
|
||||
// the EEPROM, so go back to 0 when we hit 512.
|
||||
addr = addr + 1;
|
||||
if (addr == 512)
|
||||
addr = 0;
|
||||
|
||||
|
||||
delay(100);
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
/*
|
||||
Esplora Accelerometer
|
||||
|
||||
Esplora Accelerometer
|
||||
|
||||
This sketch shows you how to read the values from the accelerometer.
|
||||
To see it in action, open the serial monitor and tilt the board. You'll see
|
||||
the accelerometer values for each axis change when you tilt the board
|
||||
the accelerometer values for each axis change when you tilt the board
|
||||
on that axis.
|
||||
|
||||
|
||||
Created on 22 Dec 2012
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
This example is in the public domain.
|
||||
*/
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600); // initialize serial communications with your computer
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
@ -25,9 +25,9 @@ void loop()
|
||||
int yAxis = Esplora.readAccelerometer(Y_AXIS); // read the Y axis
|
||||
int zAxis = Esplora.readAccelerometer(Z_AXIS); // read the Z axis
|
||||
|
||||
Serial.print("x: "); // print the label for X
|
||||
Serial.print("x: "); // print the label for X
|
||||
Serial.print(xAxis); // print the value for the X axis
|
||||
Serial.print("\ty: "); // print a tab character, then the label for Y
|
||||
Serial.print("\ty: "); // print a tab character, then the label for Y
|
||||
Serial.print(yAxis); // print the value for the Y axis
|
||||
Serial.print("\tz: "); // print a tab character, then the label for Z
|
||||
Serial.println(zAxis); // print the value for the Z axis
|
||||
|
@ -1,16 +1,16 @@
|
||||
|
||||
/*
|
||||
Esplora Blink
|
||||
|
||||
|
||||
This sketch blinks the Esplora's RGB LED. It goes through
|
||||
all three primary colors (red, green, blue), then it
|
||||
all three primary colors (red, green, blue), then it
|
||||
combines them for secondary colors(yellow, cyan, magenta), then
|
||||
it turns on all the colors for white.
|
||||
it turns on all the colors for white.
|
||||
For best results cover the LED with a piece of white paper to see the colors.
|
||||
|
||||
|
||||
Created on 22 Dec 2012
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
This example is in the public domain.
|
||||
*/
|
||||
|
||||
@ -22,19 +22,19 @@ void setup() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Esplora.writeRGB(255,0,0); // make the LED red
|
||||
Esplora.writeRGB(255, 0, 0); // make the LED red
|
||||
delay(1000); // wait 1 second
|
||||
Esplora.writeRGB(0,255,0); // make the LED green
|
||||
Esplora.writeRGB(0, 255, 0); // make the LED green
|
||||
delay(1000); // wait 1 second
|
||||
Esplora.writeRGB(0,0,255); // make the LED blue
|
||||
Esplora.writeRGB(0, 0, 255); // make the LED blue
|
||||
delay(1000); // wait 1 second
|
||||
Esplora.writeRGB(255,255,0); // make the LED yellow
|
||||
Esplora.writeRGB(255, 255, 0); // make the LED yellow
|
||||
delay(1000); // wait 1 second
|
||||
Esplora.writeRGB(0,255,255); // make the LED cyan
|
||||
Esplora.writeRGB(0, 255, 255); // make the LED cyan
|
||||
delay(1000); // wait 1 second
|
||||
Esplora.writeRGB(255,0,255); // make the LED magenta
|
||||
Esplora.writeRGB(255, 0, 255); // make the LED magenta
|
||||
delay(1000); // wait 1 second
|
||||
Esplora.writeRGB(255,255,255);// make the LED white
|
||||
Esplora.writeRGB(255, 255, 255); // make the LED white
|
||||
delay(1000); // wait 1 second
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
/*
|
||||
Esplora Joystick Mouse
|
||||
|
||||
|
||||
This sketch shows you how to read the joystick and use it to control the movement
|
||||
of the cursor on your computer. You're making your Esplora into a mouse!
|
||||
|
||||
|
||||
WARNING: this sketch will take over your mouse movement. If you lose control
|
||||
of your mouse do the following:
|
||||
1) unplug the Esplora.
|
||||
@ -11,13 +11,13 @@
|
||||
3) hold the reset button down while plugging your Esplora back in
|
||||
4) while holding reset, click "Upload"
|
||||
5) when you see the message "Done compiling", release the reset button.
|
||||
|
||||
|
||||
This will stop your Esplora from controlling your mouse while you upload a sketch
|
||||
that doesn't take control of the mouse.
|
||||
|
||||
|
||||
Created on 22 Dec 2012
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
This example is in the public domain.
|
||||
*/
|
||||
|
||||
@ -27,7 +27,7 @@ void setup()
|
||||
{
|
||||
Serial.begin(9600); // initialize serial communication with your computer
|
||||
Mouse.begin(); // take control of the mouse
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
@ -41,10 +41,10 @@ void loop()
|
||||
Serial.print("\tButton: "); // print a tab character and a label for the button
|
||||
Serial.print(button); // print the button value
|
||||
|
||||
int mouseX = map( xValue,-512, 512, 10, -10); // map the X value to a range of movement for the mouse X
|
||||
int mouseY = map( yValue,-512, 512, -10, 10); // map the Y value to a range of movement for the mouse Y
|
||||
int mouseX = map( xValue, -512, 512, 10, -10); // map the X value to a range of movement for the mouse X
|
||||
int mouseY = map( yValue, -512, 512, -10, 10); // map the Y value to a range of movement for the mouse Y
|
||||
Mouse.move(mouseX, mouseY, 0); // move the mouse
|
||||
|
||||
|
||||
delay(10); // a short delay before moving again
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
Makes the RGB LED bright and glow as the joystick or the
|
||||
slider are moved.
|
||||
|
||||
|
||||
Created on 22 november 2012
|
||||
By Enrico Gueli <enrico.gueli@gmail.com>
|
||||
Modified 22 Dec 2012
|
||||
@ -21,12 +21,12 @@ void loop() {
|
||||
int xAxis = Esplora.readJoystickX();
|
||||
int yAxis = Esplora.readJoystickY();
|
||||
int slider = Esplora.readSlider();
|
||||
|
||||
|
||||
// convert the sensor readings to light levels:
|
||||
byte red = map(xAxis, -512, 512, 0, 255);
|
||||
byte green = map(yAxis, -512, 512, 0, 255);
|
||||
byte blue = slider/4;
|
||||
|
||||
byte blue = slider / 4;
|
||||
|
||||
// print the light levels:
|
||||
Serial.print(red);
|
||||
Serial.print(' ');
|
||||
@ -34,9 +34,9 @@ void loop() {
|
||||
Serial.print(' ');
|
||||
Serial.println(blue);
|
||||
|
||||
// write the light levels to the LED.
|
||||
// write the light levels to the LED.
|
||||
Esplora.writeRGB(red, green, blue);
|
||||
|
||||
// add a delay to keep the LED from flickering:
|
||||
// add a delay to keep the LED from flickering:
|
||||
delay(10);
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ void setup() {
|
||||
}
|
||||
|
||||
int lowLight = 400; // the light sensor reading when it's covered
|
||||
int highLight = 1023; // the maximum light sensor reading
|
||||
int highLight = 1023; // the maximum light sensor reading
|
||||
int minGreen = 0; // minimum brightness of the green LED
|
||||
int maxGreen = 100; // maximum brightness of the green LED
|
||||
|
||||
@ -31,13 +31,13 @@ void loop() {
|
||||
int mic = Esplora.readMicrophone();
|
||||
int light = Esplora.readLightSensor();
|
||||
int slider = Esplora.readSlider();
|
||||
|
||||
|
||||
// convert the sensor readings to light levels:
|
||||
byte red = constrain(mic, 0, 255);
|
||||
byte green = constrain(
|
||||
map(light, lowLight, highLight, minGreen, maxGreen),
|
||||
0, 255);
|
||||
byte blue = slider/4;
|
||||
map(light, lowLight, highLight, minGreen, maxGreen),
|
||||
0, 255);
|
||||
byte blue = slider / 4;
|
||||
|
||||
// print the light levels (to see what's going on):
|
||||
Serial.print(red);
|
||||
@ -46,10 +46,10 @@ void loop() {
|
||||
Serial.print(' ');
|
||||
Serial.println(blue);
|
||||
|
||||
// write the light levels to the LED.
|
||||
// write the light levels to the LED.
|
||||
// note that the green value is always 0:
|
||||
Esplora.writeRGB(red, green, blue);
|
||||
|
||||
|
||||
// add a delay to keep the LED from flickering:
|
||||
delay(10);
|
||||
delay(10);
|
||||
}
|
||||
|
@ -1,17 +1,17 @@
|
||||
/*
|
||||
Esplora Led calibration
|
||||
|
||||
|
||||
This sketch shows you how to read and calibrate the light sensor.
|
||||
Because light levels vary from one location to another, you need to calibrate the
|
||||
Because light levels vary from one location to another, you need to calibrate the
|
||||
sensor for each location. To do this, you read the sensor for a few seconds,
|
||||
and save the highest and lowest readings as maximum and minimum.
|
||||
and save the highest and lowest readings as maximum and minimum.
|
||||
Then, when you're using the sensor's reading (for example, to set the brightness
|
||||
of the LED), you map the sensor's reading to a range between the minimum
|
||||
and the maximum.
|
||||
|
||||
|
||||
Created on 22 Dec 2012
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
This example is in the public domain.
|
||||
*/
|
||||
|
||||
@ -43,9 +43,9 @@ void loop() {
|
||||
int brightness = map(light, lightMin, lightMax, 0, 255);
|
||||
// limit the brightness to a range from 0 to 255:
|
||||
brightness = constrain(brightness, 0, 255);
|
||||
// write the brightness to the blue LED.
|
||||
// write the brightness to the blue LED.
|
||||
Esplora.writeBlue(brightness);
|
||||
|
||||
|
||||
// if the calibration's been done, show the sensor and brightness
|
||||
// levels in the serial monitor:
|
||||
if (calibrated == true) {
|
||||
@ -56,7 +56,7 @@ void loop() {
|
||||
Serial.println(brightness);
|
||||
}
|
||||
// add a delay to keep the LED from flickering:
|
||||
delay(10);
|
||||
delay(10);
|
||||
}
|
||||
|
||||
void calibrate() {
|
||||
@ -64,8 +64,8 @@ void calibrate() {
|
||||
Serial.println("While holding switch 1, shine a light on the light sensor, then cover it.");
|
||||
|
||||
// calibrate while switch 1 is pressed:
|
||||
while(Esplora.readButton(1) == LOW) {
|
||||
// read the sensor value:
|
||||
while (Esplora.readButton(1) == LOW) {
|
||||
// read the sensor value:
|
||||
int light = Esplora.readLightSensor();
|
||||
|
||||
// record the maximum sensor value:
|
||||
|
@ -16,19 +16,19 @@
|
||||
// these are the frequencies for the notes from middle C
|
||||
// to one octave above middle C:
|
||||
const int note[] = {
|
||||
262, // C
|
||||
277, // C#
|
||||
294, // D
|
||||
311, // D#
|
||||
330, // E
|
||||
349, // F
|
||||
370, // F#
|
||||
392, // G
|
||||
415, // G#
|
||||
440, // A
|
||||
466, // A#
|
||||
494, // B
|
||||
523 // C next octave
|
||||
262, // C
|
||||
277, // C#
|
||||
294, // D
|
||||
311, // D#
|
||||
330, // E
|
||||
349, // F
|
||||
370, // F#
|
||||
392, // G
|
||||
415, // G#
|
||||
440, // A
|
||||
466, // A#
|
||||
494, // B
|
||||
523 // C next octave
|
||||
};
|
||||
|
||||
void setup() {
|
||||
@ -39,8 +39,8 @@ void loop() {
|
||||
// then play a note:
|
||||
if (Esplora.readButton(SWITCH_DOWN) == LOW) {
|
||||
int slider = Esplora.readSlider();
|
||||
|
||||
// use map() to map the slider's range to the
|
||||
|
||||
// use map() to map the slider's range to the
|
||||
// range of notes you have:
|
||||
byte thisNote = map(slider, 0, 1023, 0, 13);
|
||||
// play the note corresponding to the slider's position:
|
||||
|
@ -1,15 +1,15 @@
|
||||
/*
|
||||
Esplora Sound Sensor
|
||||
|
||||
|
||||
This sketch shows you how to read the microphone sensor. The microphone
|
||||
will range from 0 (total silence) to 1023 (really loud).
|
||||
will range from 0 (total silence) to 1023 (really loud).
|
||||
When you're using the sensor's reading (for example, to set the brightness
|
||||
of the LED), you map the sensor's reading to a range between the minimum
|
||||
and the maximum.
|
||||
|
||||
|
||||
Created on 22 Dec 2012
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
This example is in the public domain.
|
||||
*/
|
||||
|
||||
@ -26,16 +26,16 @@ void loop() {
|
||||
|
||||
// map the sound level to a brightness level for the LED:
|
||||
int brightness = map(loudness, 0, 1023, 0, 255);
|
||||
// write the brightness to the green LED:
|
||||
// write the brightness to the green LED:
|
||||
Esplora.writeGreen(brightness);
|
||||
|
||||
|
||||
// print the microphone levels and the LED levels (to see what's going on):
|
||||
Serial.print("sound level: ");
|
||||
Serial.print(loudness);
|
||||
Serial.print(" Green brightness: ");
|
||||
Serial.println(brightness);
|
||||
|
||||
|
||||
// print the microphone levels and the LED levels (to see what's going on):
|
||||
Serial.print("sound level: ");
|
||||
Serial.print(loudness);
|
||||
Serial.print(" Green brightness: ");
|
||||
Serial.println(brightness);
|
||||
// add a delay to keep the LED from flickering:
|
||||
delay(10);
|
||||
delay(10);
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
/*
|
||||
Esplora Temperature Sensor
|
||||
|
||||
|
||||
This sketch shows you how to read the Esplora's temperature sensor
|
||||
You can read the temperature sensor in Farhenheit or Celsius.
|
||||
|
||||
|
||||
Created on 22 Dec 2012
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
This example is in the public domain.
|
||||
*/
|
||||
#include <Esplora.h>
|
||||
@ -14,7 +14,7 @@
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600); // initialize serial communications with your computer
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
@ -7,7 +7,7 @@
|
||||
By moving the joystick in a direction or by pressing a switch,
|
||||
the PC will "see" that a key is pressed. If the PC is running
|
||||
a game that has keyboard input, the Esplora can control it.
|
||||
|
||||
|
||||
The default configuration is suitable for SuperTuxKart, an
|
||||
open-source racing game. It can be downloaded from
|
||||
http://supertuxkart.sourceforge.net/ .
|
||||
@ -20,11 +20,11 @@
|
||||
#include <Esplora.h>
|
||||
|
||||
/*
|
||||
You're going to handle eight different buttons. You'll use arrays,
|
||||
which are ordered lists of variables with a fixed size. Each array
|
||||
You're going to handle eight different buttons. You'll use arrays,
|
||||
which are ordered lists of variables with a fixed size. Each array
|
||||
has an index (counting from 0) to keep track of the position
|
||||
you're reading in the array, and each position can contain a number.
|
||||
|
||||
|
||||
This code uses three different arrays: one for the buttons you'll read;
|
||||
a second to hold the current states of those buttons; and a third to hold
|
||||
the keystrokes associated with each button.
|
||||
@ -89,14 +89,14 @@ void setup() {
|
||||
Here we continuously check if something happened with the
|
||||
buttons.
|
||||
*/
|
||||
void loop() {
|
||||
|
||||
void loop() {
|
||||
|
||||
// Iterate through all the buttons:
|
||||
for (byte thisButton=0; thisButton<8; thisButton++) {
|
||||
for (byte thisButton = 0; thisButton < 8; thisButton++) {
|
||||
boolean lastState = buttonStates[thisButton];
|
||||
boolean newState = Esplora.readButton(buttons[thisButton]);
|
||||
if (lastState != newState) { // Something changed!
|
||||
/*
|
||||
/*
|
||||
The Keyboard library allows you to "press" and "release" the
|
||||
keys as two distinct actions. These actions can be
|
||||
linked to the buttons we're handling.
|
||||
@ -112,7 +112,7 @@ void loop() {
|
||||
// Store the new button state, so you can sense a difference later:
|
||||
buttonStates[thisButton] = newState;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Wait a little bit (50ms) between a check and another.
|
||||
When a mechanical switch is pressed or released, the
|
||||
|
@ -1,21 +1,21 @@
|
||||
/*
|
||||
Esplora Pong
|
||||
|
||||
|
||||
This sketch connects serially to a Processing sketch to control a Pong game.
|
||||
It sends the position of the slider and the states of three pushbuttons to the
|
||||
Processing sketch serially, separated by commas. The Processing sketch uses that
|
||||
It sends the position of the slider and the states of three pushbuttons to the
|
||||
Processing sketch serially, separated by commas. The Processing sketch uses that
|
||||
data to control the graphics in the sketch.
|
||||
|
||||
|
||||
The slider sets a paddle's height
|
||||
Switch 1 is resets the game
|
||||
Switch 2 resets the ball to the center
|
||||
Switch 3 reverses the players
|
||||
|
||||
|
||||
You can play this game with one or two Esploras.
|
||||
|
||||
|
||||
Created on 22 Dec 2012
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
This example is in the public domain.
|
||||
*/
|
||||
|
||||
|
@ -1,28 +1,28 @@
|
||||
/*
|
||||
Esplora Remote
|
||||
|
||||
|
||||
This sketch allows to test all the Esplora's peripherals.
|
||||
It is also used with the ProcessingStart sketch (for Processing).
|
||||
|
||||
|
||||
When uploaded, you can open the Serial monitor and write one of
|
||||
the following commands (without quotes) to get an answer:
|
||||
|
||||
|
||||
"D": prints the current value of all sensors, separated by a comma.
|
||||
See the dumpInputs() function below to get the meaning of
|
||||
each value.
|
||||
|
||||
|
||||
"Rxxx"
|
||||
"Gxxx"
|
||||
"Bxxx": set the color of the RGB led. For example, write "R255"
|
||||
to turn on the red to full brightness, "G128" to turn
|
||||
the green to half brightness, or "G0" to turn off
|
||||
the green channel.
|
||||
|
||||
|
||||
"Txxxx": play a tone with the buzzer. The number is the
|
||||
frequency, e.g. "T440" plays the central A note.
|
||||
Write "T0" to turn off the buzzer.
|
||||
|
||||
|
||||
|
||||
|
||||
Created on 22 november 2012
|
||||
By Enrico Gueli <enrico.gueli@gmail.com>
|
||||
Modified 23 Dec 2012
|
||||
@ -32,7 +32,7 @@
|
||||
#include <Esplora.h>
|
||||
|
||||
void setup() {
|
||||
while(!Serial); // needed for Leonardo-based board like Esplora
|
||||
while (!Serial); // needed for Leonardo-based board like Esplora
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
@ -48,53 +48,53 @@ void loop() {
|
||||
*/
|
||||
void parseCommand() {
|
||||
char cmd = Serial.read();
|
||||
switch(cmd) {
|
||||
case 'D':
|
||||
dumpInputs();
|
||||
break;
|
||||
case 'R':
|
||||
setRed();
|
||||
break;
|
||||
case 'G':
|
||||
setGreen();
|
||||
break;
|
||||
case 'B':
|
||||
setBlue();
|
||||
break;
|
||||
case 'T':
|
||||
setTone();
|
||||
break;
|
||||
switch (cmd) {
|
||||
case 'D':
|
||||
dumpInputs();
|
||||
break;
|
||||
case 'R':
|
||||
setRed();
|
||||
break;
|
||||
case 'G':
|
||||
setGreen();
|
||||
break;
|
||||
case 'B':
|
||||
setBlue();
|
||||
break;
|
||||
case 'T':
|
||||
setTone();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void dumpInputs() {
|
||||
Serial.print(Esplora.readButton(SWITCH_1));
|
||||
void dumpInputs() {
|
||||
Serial.print(Esplora.readButton(SWITCH_1));
|
||||
Serial.print(',');
|
||||
Serial.print(Esplora.readButton(SWITCH_2));
|
||||
Serial.print(Esplora.readButton(SWITCH_2));
|
||||
Serial.print(',');
|
||||
Serial.print(Esplora.readButton(SWITCH_3));
|
||||
Serial.print(Esplora.readButton(SWITCH_3));
|
||||
Serial.print(',');
|
||||
Serial.print(Esplora.readButton(SWITCH_4));
|
||||
Serial.print(Esplora.readButton(SWITCH_4));
|
||||
Serial.print(',');
|
||||
Serial.print(Esplora.readSlider());
|
||||
Serial.print(Esplora.readSlider());
|
||||
Serial.print(',');
|
||||
Serial.print(Esplora.readLightSensor());
|
||||
Serial.print(Esplora.readLightSensor());
|
||||
Serial.print(',');
|
||||
Serial.print(Esplora.readTemperature(DEGREES_C));
|
||||
Serial.print(Esplora.readTemperature(DEGREES_C));
|
||||
Serial.print(',');
|
||||
Serial.print(Esplora.readMicrophone());
|
||||
Serial.print(Esplora.readMicrophone());
|
||||
Serial.print(',');
|
||||
Serial.print(Esplora.readJoystickSwitch());
|
||||
Serial.print(Esplora.readJoystickSwitch());
|
||||
Serial.print(',');
|
||||
Serial.print(Esplora.readJoystickX());
|
||||
Serial.print(Esplora.readJoystickX());
|
||||
Serial.print(',');
|
||||
Serial.print(Esplora.readJoystickY());
|
||||
Serial.print(Esplora.readJoystickY());
|
||||
Serial.print(',');
|
||||
Serial.print(Esplora.readAccelerometer(X_AXIS));
|
||||
Serial.print(Esplora.readAccelerometer(X_AXIS));
|
||||
Serial.print(',');
|
||||
Serial.print(Esplora.readAccelerometer(Y_AXIS));
|
||||
Serial.print(Esplora.readAccelerometer(Y_AXIS));
|
||||
Serial.print(',');
|
||||
Serial.print(Esplora.readAccelerometer(Z_AXIS));
|
||||
Serial.print(Esplora.readAccelerometer(Z_AXIS));
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
@ -3,18 +3,18 @@
|
||||
|
||||
Acts like a keyboard that prints sensor
|
||||
data in a table-like text, row by row.
|
||||
|
||||
|
||||
At startup, it does nothing. It waits for you to open a
|
||||
spreadsheet (e.g. Google Drive spreadsheet) so it can write
|
||||
data. By pressing Switch 1, it starts printing the table
|
||||
headers and the first row of data. It waits a bit, then it
|
||||
will print another row, and so on.
|
||||
|
||||
|
||||
The amount of time between each row is determined by the slider.
|
||||
If put to full left, the sketch will wait 10 seconds; at
|
||||
full right position, it will wait 5 minutes. An intermediate
|
||||
position will make the sketch wait for some time in-between.
|
||||
|
||||
|
||||
Clicking the Switch 1 at any time will stop the logging.
|
||||
|
||||
The color LED shows what the sketch is doing:
|
||||
@ -87,7 +87,7 @@ void loop() {
|
||||
* check for button presses often enough to not miss any event.
|
||||
*/
|
||||
activeDelay(50);
|
||||
|
||||
|
||||
/*
|
||||
* the justActivated variable may be set to true in the
|
||||
* checkSwitchPress() function. Here we check its status to
|
||||
@ -99,7 +99,7 @@ void loop() {
|
||||
// do next sampling ASAP
|
||||
nextSampleAt = startedAt = millis();
|
||||
}
|
||||
|
||||
|
||||
if (active == true) {
|
||||
if (nextSampleAt < millis()) {
|
||||
// it's time to sample!
|
||||
@ -108,24 +108,24 @@ void loop() {
|
||||
// 10 and 290 seconds.
|
||||
int sampleInterval = map(slider, 0, 1023, 10, 290);
|
||||
nextSampleAt = millis() + sampleInterval * 1000;
|
||||
|
||||
|
||||
logAndPrint();
|
||||
}
|
||||
|
||||
|
||||
// let the RGB led blink green once per second, for 200ms.
|
||||
unsigned int ms = millis() % 1000;
|
||||
if (ms < 200)
|
||||
Esplora.writeGreen(50);
|
||||
else
|
||||
Esplora.writeGreen(0);
|
||||
|
||||
|
||||
Esplora.writeBlue(0);
|
||||
}
|
||||
}
|
||||
else
|
||||
// while not active, keep a reassuring blue color coming
|
||||
// from the Esplora...
|
||||
Esplora.writeBlue(20);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@ -135,7 +135,7 @@ void printHeaders() {
|
||||
Keyboard.print("Time");
|
||||
Keyboard.write(KEY_TAB);
|
||||
activeDelay(300); // Some spreadsheets are slow, e.g. Google
|
||||
// Drive that wants to save every edit.
|
||||
// Drive that wants to save every edit.
|
||||
Keyboard.print("Accel X");
|
||||
Keyboard.write(KEY_TAB);
|
||||
activeDelay(300);
|
||||
@ -149,13 +149,13 @@ void printHeaders() {
|
||||
|
||||
void logAndPrint() {
|
||||
// do all the samplings at once, because keystrokes have delays
|
||||
unsigned long timeSecs = (millis() - startedAt) /1000;
|
||||
unsigned long timeSecs = (millis() - startedAt) / 1000;
|
||||
int xAxis = Esplora.readAccelerometer(X_AXIS);
|
||||
int yAxis = Esplora.readAccelerometer(Y_AXIS);
|
||||
int zAxis = Esplora.readAccelerometer(Z_AXIS);
|
||||
|
||||
|
||||
Esplora.writeRed(100);
|
||||
|
||||
|
||||
Keyboard.print(timeSecs);
|
||||
Keyboard.write(KEY_TAB);
|
||||
activeDelay(300);
|
||||
@ -169,7 +169,7 @@ void logAndPrint() {
|
||||
Keyboard.println();
|
||||
activeDelay(300);
|
||||
Keyboard.write(KEY_HOME);
|
||||
|
||||
|
||||
Esplora.writeRed(0);
|
||||
}
|
||||
|
||||
@ -204,9 +204,9 @@ void checkSwitchPress() {
|
||||
if (startBtn == HIGH) { // button released
|
||||
active = !active;
|
||||
if (active)
|
||||
justActivated = true;
|
||||
justActivated = true;
|
||||
}
|
||||
|
||||
|
||||
lastStartBtn = startBtn;
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
/*
|
||||
SCP1000 Barometric Pressure Sensor Display
|
||||
|
||||
|
||||
Serves the output of a Barometric Pressure Sensor as a web page.
|
||||
Uses the SPI library. For details on the sensor, see:
|
||||
http://www.sparkfun.com/commerce/product_info.php?products_id=8161
|
||||
http://www.vti.fi/en/support/obsolete_products/pressure_sensors/
|
||||
|
||||
|
||||
This sketch adapted from Nathan Seidle's SCP1000 example for PIC:
|
||||
http://www.sparkfun.com/datasheets/Sensors/SCP1000-Testing.zip
|
||||
|
||||
|
||||
Circuit:
|
||||
SCP1000 sensor attached to pins 6,7, and 11 - 13:
|
||||
DRDY: pin 6
|
||||
@ -16,7 +16,7 @@
|
||||
MOSI: pin 11
|
||||
MISO: pin 12
|
||||
SCK: pin 13
|
||||
|
||||
|
||||
created 31 July 2010
|
||||
by Tom Igoe
|
||||
*/
|
||||
@ -28,16 +28,17 @@
|
||||
|
||||
// assign a MAC address for the ethernet controller.
|
||||
// fill in your address here:
|
||||
byte mac[] = {
|
||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
|
||||
byte mac[] = {
|
||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
|
||||
};
|
||||
// assign an IP address for the controller:
|
||||
IPAddress ip(192,168,1,20);
|
||||
IPAddress gateway(192,168,1,1);
|
||||
IPAddress ip(192, 168, 1, 20);
|
||||
IPAddress gateway(192, 168, 1, 1);
|
||||
IPAddress subnet(255, 255, 255, 0);
|
||||
|
||||
|
||||
// Initialize the Ethernet server library
|
||||
// with the IP address and port you want to use
|
||||
// with the IP address and port you want to use
|
||||
// (port 80 is default for HTTP):
|
||||
EthernetServer server(80);
|
||||
|
||||
@ -49,7 +50,7 @@ const int TEMPERATURE = 0x21; //16 bit temperature reading
|
||||
|
||||
// pins used for the connection with the sensor
|
||||
// the others you need are controlled by the SPI library):
|
||||
const int dataReadyPin = 6;
|
||||
const int dataReadyPin = 6;
|
||||
const int chipSelectPin = 7;
|
||||
|
||||
float temperature = 0.0;
|
||||
@ -83,9 +84,9 @@ void setup() {
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
void loop() {
|
||||
// check for a reading no more than once a second.
|
||||
if (millis() - lastReadingTime > 1000){
|
||||
if (millis() - lastReadingTime > 1000) {
|
||||
// if there's a reading ready, read it:
|
||||
// don't do anything until the data ready pin is high:
|
||||
if (digitalRead(dataReadyPin) == HIGH) {
|
||||
@ -109,13 +110,13 @@ void getData() {
|
||||
temperature = (float)tempData / 20.0;
|
||||
|
||||
//Read the pressure data highest 3 bits:
|
||||
byte pressureDataHigh = readRegister(0x1F, 1);
|
||||
byte pressureDataHigh = readRegister(0x1F, 1);
|
||||
pressureDataHigh &= 0b00000111; //you only needs bits 2 to 0
|
||||
|
||||
//Read the pressure data lower 16 bits:
|
||||
unsigned int pressureDataLow = readRegister(0x20, 2);
|
||||
unsigned int pressureDataLow = readRegister(0x20, 2);
|
||||
//combine the two parts into one 19-bit number:
|
||||
pressure = ((pressureDataHigh << 16) | pressureDataLow)/4;
|
||||
pressure = ((pressureDataHigh << 16) | pressureDataLow) / 4;
|
||||
|
||||
Serial.print("Temperature: ");
|
||||
Serial.print(temperature);
|
||||
@ -149,13 +150,13 @@ void listenForEthernetClients() {
|
||||
client.println("<br />");
|
||||
client.print("Pressure: " + String(pressure));
|
||||
client.print(" Pa");
|
||||
client.println("<br />");
|
||||
client.println("<br />");
|
||||
break;
|
||||
}
|
||||
if (c == '\n') {
|
||||
// you're starting a new line
|
||||
currentLineIsBlank = true;
|
||||
}
|
||||
}
|
||||
else if (c != '\r') {
|
||||
// you've gotten a character on the current line
|
||||
currentLineIsBlank = false;
|
||||
@ -167,7 +168,7 @@ void listenForEthernetClients() {
|
||||
// close the connection:
|
||||
client.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Send a write command to SCP1000
|
||||
@ -179,20 +180,20 @@ void writeRegister(byte registerName, byte registerValue) {
|
||||
registerName |= 0b00000010; //Write command
|
||||
|
||||
// take the chip select low to select the device:
|
||||
digitalWrite(chipSelectPin, LOW);
|
||||
digitalWrite(chipSelectPin, LOW);
|
||||
|
||||
SPI.transfer(registerName); //Send register location
|
||||
SPI.transfer(registerValue); //Send value to record into register
|
||||
|
||||
// take the chip select high to de-select:
|
||||
digitalWrite(chipSelectPin, HIGH);
|
||||
digitalWrite(chipSelectPin, HIGH);
|
||||
}
|
||||
|
||||
|
||||
//Read register from the SCP1000:
|
||||
unsigned int readRegister(byte registerName, int numBytes) {
|
||||
byte inByte = 0; // incoming from the SPI read
|
||||
unsigned int result = 0; // result to return
|
||||
unsigned int result = 0; // result to return
|
||||
|
||||
// SCP1000 expects the register name in the upper 6 bits
|
||||
// of the byte:
|
||||
@ -201,22 +202,22 @@ unsigned int readRegister(byte registerName, int numBytes) {
|
||||
registerName &= 0b11111100; //Read command
|
||||
|
||||
// take the chip select low to select the device:
|
||||
digitalWrite(chipSelectPin, LOW);
|
||||
digitalWrite(chipSelectPin, LOW);
|
||||
// send the device the register you want to read:
|
||||
int command = SPI.transfer(registerName);
|
||||
int command = SPI.transfer(registerName);
|
||||
// send a value of 0 to read the first byte returned:
|
||||
inByte = SPI.transfer(0x00);
|
||||
|
||||
inByte = SPI.transfer(0x00);
|
||||
|
||||
result = inByte;
|
||||
// if there's more than one byte returned,
|
||||
// if there's more than one byte returned,
|
||||
// shift the first byte then get the second byte:
|
||||
if (numBytes > 1){
|
||||
if (numBytes > 1) {
|
||||
result = inByte << 8;
|
||||
inByte = SPI.transfer(0x00);
|
||||
result = result |inByte;
|
||||
inByte = SPI.transfer(0x00);
|
||||
result = result | inByte;
|
||||
}
|
||||
// take the chip select high to de-select:
|
||||
digitalWrite(chipSelectPin, HIGH);
|
||||
digitalWrite(chipSelectPin, HIGH);
|
||||
// return the result:
|
||||
return(result);
|
||||
}
|
||||
|
@ -1,20 +1,20 @@
|
||||
/*
|
||||
Chat Server
|
||||
|
||||
|
||||
A simple server that distributes any incoming messages to all
|
||||
connected clients. To use telnet to your device's IP address and type.
|
||||
You can see the client's input in the serial monitor as well.
|
||||
Using an Arduino Wiznet Ethernet shield.
|
||||
|
||||
Using an Arduino Wiznet Ethernet shield.
|
||||
|
||||
Circuit:
|
||||
* Ethernet shield attached to pins 10, 11, 12, 13
|
||||
* Analog inputs attached to pins A0 through A5 (optional)
|
||||
|
||||
|
||||
created 18 Dec 2009
|
||||
by David A. Mellis
|
||||
modified 9 Apr 2012
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
@ -23,10 +23,11 @@
|
||||
// Enter a MAC address and IP address for your controller below.
|
||||
// The IP address will be dependent on your local network.
|
||||
// gateway and subnet are optional:
|
||||
byte mac[] = {
|
||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
||||
IPAddress ip(192,168,1, 177);
|
||||
IPAddress gateway(192,168,1, 1);
|
||||
byte mac[] = {
|
||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
|
||||
};
|
||||
IPAddress ip(192, 168, 1, 177);
|
||||
IPAddress gateway(192, 168, 1, 1);
|
||||
IPAddress subnet(255, 255, 0, 0);
|
||||
|
||||
|
||||
@ -39,9 +40,9 @@ void setup() {
|
||||
Ethernet.begin(mac, ip, gateway, subnet);
|
||||
// start listening for clients
|
||||
server.begin();
|
||||
// Open serial communications and wait for port to open:
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
@ -58,11 +59,11 @@ void loop() {
|
||||
if (client) {
|
||||
if (!alreadyConnected) {
|
||||
// clead out the input buffer:
|
||||
client.flush();
|
||||
client.flush();
|
||||
Serial.println("We have a new client");
|
||||
client.println("Hello, client!");
|
||||
client.println("Hello, client!");
|
||||
alreadyConnected = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (client.available() > 0) {
|
||||
// read the bytes incoming from the client:
|
||||
|
@ -1,27 +1,27 @@
|
||||
/*
|
||||
Cosm sensor client
|
||||
|
||||
|
||||
This sketch connects an analog sensor to Cosm (http://www.cosm.com)
|
||||
using a Wiznet Ethernet shield. You can use the Arduino Ethernet shield, or
|
||||
the Adafruit Ethernet shield, either one will work, as long as it's got
|
||||
a Wiznet Ethernet module on board.
|
||||
|
||||
This example has been updated to use version 2.0 of the cosm.com API.
|
||||
|
||||
This example has been updated to use version 2.0 of the cosm.com API.
|
||||
To make it work, create a feed with a datastream, and give it the ID
|
||||
sensor1. Or change the code below to match your feed.
|
||||
|
||||
|
||||
|
||||
|
||||
Circuit:
|
||||
* Analog sensor attached to analog in 0
|
||||
* Ethernet shield attached to pins 10, 11, 12, 13
|
||||
|
||||
|
||||
created 15 March 2010
|
||||
updated 14 May 2012
|
||||
by Tom Igoe with input from Usman Haque and Joe Saavedra
|
||||
|
||||
|
||||
http://arduino.cc/en/Tutorial/CosmClient
|
||||
This code is in the public domain.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
@ -34,12 +34,13 @@ http://arduino.cc/en/Tutorial/CosmClient
|
||||
// assign a MAC address for the ethernet controller.
|
||||
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
|
||||
// fill in your address here:
|
||||
byte mac[] = {
|
||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
|
||||
byte mac[] = {
|
||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
|
||||
};
|
||||
|
||||
// fill in an available IP address on your network here,
|
||||
// for manual configuration:
|
||||
IPAddress ip(10,0,1,20);
|
||||
IPAddress ip(10, 0, 1, 20);
|
||||
|
||||
// initialize the library instance:
|
||||
EthernetClient client;
|
||||
@ -51,14 +52,14 @@ char server[] = "api.cosm.com"; // name address for cosm API
|
||||
|
||||
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
|
||||
boolean lastConnected = false; // state of the connection last time through the main loop
|
||||
const unsigned long postingInterval = 10L*1000L; // delay between updates to cosm.com
|
||||
// the "L" is needed to use long type numbers
|
||||
const unsigned long postingInterval = 10L * 1000L; // delay between updates to cosm.com
|
||||
// the "L" is needed to use long type numbers
|
||||
|
||||
|
||||
void setup() {
|
||||
// start serial port:
|
||||
Serial.begin(9600);
|
||||
// start the Ethernet connection:
|
||||
// start the Ethernet connection:
|
||||
if (Ethernet.begin(mac) == 0) {
|
||||
Serial.println("Failed to configure Ethernet using DHCP");
|
||||
// DHCP failed, so use a fixed IP address:
|
||||
@ -68,7 +69,7 @@ void setup() {
|
||||
|
||||
void loop() {
|
||||
// read the analog sensor:
|
||||
int sensorReading = analogRead(A0);
|
||||
int sensorReading = analogRead(A0);
|
||||
|
||||
// if there's incoming data from the net connection.
|
||||
// send it out the serial port. This is for debugging
|
||||
@ -88,7 +89,7 @@ void loop() {
|
||||
|
||||
// if you're not connected, and ten seconds have passed since
|
||||
// your last connection, then connect again and send data:
|
||||
if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
|
||||
if (!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
|
||||
sendData(sensorReading);
|
||||
}
|
||||
// store the state of the connection for next time through
|
||||
@ -125,8 +126,8 @@ void sendData(int thisData) {
|
||||
// here's the actual content of the PUT request:
|
||||
client.print("sensor1,");
|
||||
client.println(thisData);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
// if you couldn't make a connection:
|
||||
Serial.println("connection failed");
|
||||
@ -134,7 +135,7 @@ void sendData(int thisData) {
|
||||
Serial.println("disconnecting.");
|
||||
client.stop();
|
||||
}
|
||||
// note the time that the connection was made or attempted:
|
||||
// note the time that the connection was made or attempted:
|
||||
lastConnectionTime = millis();
|
||||
}
|
||||
|
||||
@ -147,12 +148,12 @@ void sendData(int thisData) {
|
||||
int getLength(int someValue) {
|
||||
// there's at least one byte:
|
||||
int digits = 1;
|
||||
// continually divide the value by ten,
|
||||
// continually divide the value by ten,
|
||||
// adding one to the digit count for each
|
||||
// time you divide, until you're at 0:
|
||||
int dividend = someValue /10;
|
||||
int dividend = someValue / 10;
|
||||
while (dividend > 0) {
|
||||
dividend = dividend /10;
|
||||
dividend = dividend / 10;
|
||||
digits++;
|
||||
}
|
||||
// return the number of digits:
|
||||
|
@ -1,29 +1,29 @@
|
||||
/*
|
||||
Cosm sensor client with Strings
|
||||
|
||||
|
||||
This sketch connects an analog sensor to Cosm (http://www.cosm.com)
|
||||
using a Wiznet Ethernet shield. You can use the Arduino Ethernet shield, or
|
||||
the Adafruit Ethernet shield, either one will work, as long as it's got
|
||||
a Wiznet Ethernet module on board.
|
||||
|
||||
This example has been updated to use version 2.0 of the Cosm.com API.
|
||||
|
||||
This example has been updated to use version 2.0 of the Cosm.com API.
|
||||
To make it work, create a feed with two datastreams, and give them the IDs
|
||||
sensor1 and sensor2. Or change the code below to match your feed.
|
||||
|
||||
|
||||
This example uses the String library, which is part of the Arduino core from
|
||||
version 0019.
|
||||
|
||||
version 0019.
|
||||
|
||||
Circuit:
|
||||
* Analog sensor attached to analog in 0
|
||||
* Ethernet shield attached to pins 10, 11, 12, 13
|
||||
|
||||
|
||||
created 15 March 2010
|
||||
updated 14 May 2012
|
||||
by Tom Igoe with input from Usman Haque and Joe Saavedra
|
||||
|
||||
|
||||
http://arduino.cc/en/Tutorial/CosmClientString
|
||||
This code is in the public domain.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
@ -36,12 +36,13 @@
|
||||
|
||||
// assign a MAC address for the ethernet controller.
|
||||
// fill in your address here:
|
||||
byte mac[] = {
|
||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
|
||||
|
||||
byte mac[] = {
|
||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
|
||||
};
|
||||
|
||||
// fill in an available IP address on your network here,
|
||||
// for manual configuration:
|
||||
IPAddress ip(10,0,1,20);
|
||||
IPAddress ip(10, 0, 1, 20);
|
||||
|
||||
// initialize the library instance:
|
||||
EthernetClient client;
|
||||
@ -53,8 +54,8 @@ char server[] = "api.cosm.com"; // name address for Cosm API
|
||||
|
||||
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
|
||||
boolean lastConnected = false; // state of the connection last time through the main loop
|
||||
const unsigned long postingInterval = 10L*1000L; // delay between updates to Cosm.com
|
||||
// the "L" is needed to use long type numbers
|
||||
const unsigned long postingInterval = 10L * 1000L; // delay between updates to Cosm.com
|
||||
// the "L" is needed to use long type numbers
|
||||
void setup() {
|
||||
// start serial port:
|
||||
Serial.begin(9600);
|
||||
@ -70,7 +71,7 @@ void setup() {
|
||||
|
||||
void loop() {
|
||||
// read the analog sensor:
|
||||
int sensorReading = analogRead(A0);
|
||||
int sensorReading = analogRead(A0);
|
||||
// convert the data to a String to send it:
|
||||
|
||||
String dataString = "sensor1,";
|
||||
@ -99,8 +100,8 @@ void loop() {
|
||||
}
|
||||
|
||||
// if you're not connected, and ten seconds have passed since
|
||||
// your last connection, then connect again and send data:
|
||||
if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
|
||||
// your last connection, then connect again and send data:
|
||||
if (!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
|
||||
sendData(dataString);
|
||||
}
|
||||
// store the state of the connection for next time through
|
||||
@ -132,7 +133,7 @@ void sendData(String thisData) {
|
||||
|
||||
// here's the actual content of the PUT request:
|
||||
client.println(thisData);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// if you couldn't make a connection:
|
||||
Serial.println("connection failed");
|
||||
|
@ -1,17 +1,17 @@
|
||||
/*
|
||||
DHCP-based IP printer
|
||||
|
||||
|
||||
This sketch uses the DHCP extensions to the Ethernet library
|
||||
to get an IP address via DHCP and print the address obtained.
|
||||
using an Arduino Wiznet Ethernet shield.
|
||||
|
||||
using an Arduino Wiznet Ethernet shield.
|
||||
|
||||
Circuit:
|
||||
* Ethernet shield attached to pins 10, 11, 12, 13
|
||||
|
||||
|
||||
created 12 April 2011
|
||||
modified 9 Apr 2012
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
@ -19,19 +19,20 @@
|
||||
|
||||
// Enter a MAC address for your controller below.
|
||||
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
|
||||
byte mac[] = {
|
||||
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
|
||||
byte mac[] = {
|
||||
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
|
||||
};
|
||||
|
||||
// Initialize the Ethernet client library
|
||||
// with the IP address and port of the server
|
||||
// with the IP address and port of the server
|
||||
// that you want to connect to (port 80 is default for HTTP):
|
||||
EthernetClient client;
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
// this check is only needed on the Leonardo:
|
||||
while (!Serial) {
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
@ -39,7 +40,7 @@ void setup() {
|
||||
if (Ethernet.begin(mac) == 0) {
|
||||
Serial.println("Failed to configure Ethernet using DHCP");
|
||||
// no point in carrying on, so do nothing forevermore:
|
||||
for(;;)
|
||||
for (;;)
|
||||
;
|
||||
}
|
||||
// print your local IP address:
|
||||
@ -47,7 +48,7 @@ void setup() {
|
||||
for (byte thisByte = 0; thisByte < 4; thisByte++) {
|
||||
// print the value of each byte of the IP address:
|
||||
Serial.print(Ethernet.localIP()[thisByte], DEC);
|
||||
Serial.print(".");
|
||||
Serial.print(".");
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
@ -1,21 +1,21 @@
|
||||
/*
|
||||
DHCP Chat Server
|
||||
|
||||
|
||||
A simple server that distributes any incoming messages to all
|
||||
connected clients. To use telnet to your device's IP address and type.
|
||||
You can see the client's input in the serial monitor as well.
|
||||
Using an Arduino Wiznet Ethernet shield.
|
||||
|
||||
Using an Arduino Wiznet Ethernet shield.
|
||||
|
||||
THis version attempts to get an IP address using DHCP
|
||||
|
||||
|
||||
Circuit:
|
||||
* Ethernet shield attached to pins 10, 11, 12, 13
|
||||
|
||||
|
||||
created 21 May 2011
|
||||
modified 9 Apr 2012
|
||||
by Tom Igoe
|
||||
Based on ChatServer example by David A. Mellis
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
@ -24,10 +24,11 @@
|
||||
// Enter a MAC address and IP address for your controller below.
|
||||
// The IP address will be dependent on your local network.
|
||||
// gateway and subnet are optional:
|
||||
byte mac[] = {
|
||||
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
|
||||
IPAddress ip(192,168,1, 177);
|
||||
IPAddress gateway(192,168,1, 1);
|
||||
byte mac[] = {
|
||||
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
|
||||
};
|
||||
IPAddress ip(192, 168, 1, 177);
|
||||
IPAddress gateway(192, 168, 1, 1);
|
||||
IPAddress subnet(255, 255, 0, 0);
|
||||
|
||||
// telnet defaults to port 23
|
||||
@ -38,7 +39,7 @@ void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
// this check is only needed on the Leonardo:
|
||||
while (!Serial) {
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
@ -56,12 +57,12 @@ void setup() {
|
||||
for (byte thisByte = 0; thisByte < 4; thisByte++) {
|
||||
// print the value of each byte of the IP address:
|
||||
Serial.print(ip[thisByte], DEC);
|
||||
Serial.print(".");
|
||||
Serial.print(".");
|
||||
}
|
||||
Serial.println();
|
||||
// start listening for clients
|
||||
server.begin();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@ -72,7 +73,7 @@ void loop() {
|
||||
if (client) {
|
||||
if (!gotAMessage) {
|
||||
Serial.println("We have a new client");
|
||||
client.println("Hello, client!");
|
||||
client.println("Hello, client!");
|
||||
gotAMessage = true;
|
||||
}
|
||||
|
||||
|
@ -1,27 +1,27 @@
|
||||
/*
|
||||
Pachube sensor client
|
||||
|
||||
|
||||
This sketch connects an analog sensor to Pachube (http://www.pachube.com)
|
||||
using a Wiznet Ethernet shield. You can use the Arduino Ethernet shield, or
|
||||
the Adafruit Ethernet shield, either one will work, as long as it's got
|
||||
a Wiznet Ethernet module on board.
|
||||
|
||||
This example has been updated to use version 2.0 of the Pachube.com API.
|
||||
|
||||
This example has been updated to use version 2.0 of the Pachube.com API.
|
||||
To make it work, create a feed with a datastream, and give it the ID
|
||||
sensor1. Or change the code below to match your feed.
|
||||
|
||||
|
||||
|
||||
|
||||
Circuit:
|
||||
* Analog sensor attached to analog in 0
|
||||
* Ethernet shield attached to pins 10, 11, 12, 13
|
||||
|
||||
|
||||
created 15 March 2010
|
||||
modified 9 Apr 2012
|
||||
by Tom Igoe with input from Usman Haque and Joe Saavedra
|
||||
|
||||
|
||||
http://arduino.cc/en/Tutorial/PachubeClient
|
||||
This code is in the public domain.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
@ -34,33 +34,34 @@ http://arduino.cc/en/Tutorial/PachubeClient
|
||||
// assign a MAC address for the ethernet controller.
|
||||
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
|
||||
// fill in your address here:
|
||||
byte mac[] = {
|
||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
|
||||
byte mac[] = {
|
||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
|
||||
};
|
||||
|
||||
// fill in an available IP address on your network here,
|
||||
// for manual configuration:
|
||||
IPAddress ip(10,0,1,20);
|
||||
IPAddress ip(10, 0, 1, 20);
|
||||
// initialize the library instance:
|
||||
EthernetClient client;
|
||||
|
||||
// if you don't want to use DNS (and reduce your sketch size)
|
||||
// use the numeric IP instead of the name for the server:
|
||||
IPAddress server(216,52,233,122); // numeric IP for api.pachube.com
|
||||
IPAddress server(216, 52, 233, 122); // numeric IP for api.pachube.com
|
||||
//char server[] = "api.pachube.com"; // name address for pachube API
|
||||
|
||||
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
|
||||
boolean lastConnected = false; // state of the connection last time through the main loop
|
||||
const unsigned long postingInterval = 10*1000; //delay between updates to Pachube.com
|
||||
const unsigned long postingInterval = 10 * 1000; //delay between updates to Pachube.com
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
|
||||
// start the Ethernet connection:
|
||||
// start the Ethernet connection:
|
||||
if (Ethernet.begin(mac) == 0) {
|
||||
Serial.println("Failed to configure Ethernet using DHCP");
|
||||
// DHCP failed, so use a fixed IP address:
|
||||
@ -70,7 +71,7 @@ void setup() {
|
||||
|
||||
void loop() {
|
||||
// read the analog sensor:
|
||||
int sensorReading = analogRead(A0);
|
||||
int sensorReading = analogRead(A0);
|
||||
|
||||
// if there's incoming data from the net connection.
|
||||
// send it out the serial port. This is for debugging
|
||||
@ -90,7 +91,7 @@ void loop() {
|
||||
|
||||
// if you're not connected, and ten seconds have passed since
|
||||
// your last connection, then connect again and send data:
|
||||
if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
|
||||
if (!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
|
||||
sendData(sensorReading);
|
||||
}
|
||||
// store the state of the connection for next time through
|
||||
@ -127,8 +128,8 @@ void sendData(int thisData) {
|
||||
// here's the actual content of the PUT request:
|
||||
client.print("sensor1,");
|
||||
client.println(thisData);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
// if you couldn't make a connection:
|
||||
Serial.println("connection failed");
|
||||
@ -136,7 +137,7 @@ void sendData(int thisData) {
|
||||
Serial.println("disconnecting.");
|
||||
client.stop();
|
||||
}
|
||||
// note the time that the connection was made or attempted:
|
||||
// note the time that the connection was made or attempted:
|
||||
lastConnectionTime = millis();
|
||||
}
|
||||
|
||||
@ -149,12 +150,12 @@ void sendData(int thisData) {
|
||||
int getLength(int someValue) {
|
||||
// there's at least one byte:
|
||||
int digits = 1;
|
||||
// continually divide the value by ten,
|
||||
// continually divide the value by ten,
|
||||
// adding one to the digit count for each
|
||||
// time you divide, until you're at 0:
|
||||
int dividend = someValue /10;
|
||||
int dividend = someValue / 10;
|
||||
while (dividend > 0) {
|
||||
dividend = dividend /10;
|
||||
dividend = dividend / 10;
|
||||
digits++;
|
||||
}
|
||||
// return the number of digits:
|
||||
|
@ -1,29 +1,29 @@
|
||||
/*
|
||||
Cosm sensor client with Strings
|
||||
|
||||
|
||||
This sketch connects an analog sensor to Cosm (http://www.cosm.com)
|
||||
using a Wiznet Ethernet shield. You can use the Arduino Ethernet shield, or
|
||||
the Adafruit Ethernet shield, either one will work, as long as it's got
|
||||
a Wiznet Ethernet module on board.
|
||||
|
||||
This example has been updated to use version 2.0 of the Cosm.com API.
|
||||
|
||||
This example has been updated to use version 2.0 of the Cosm.com API.
|
||||
To make it work, create a feed with two datastreams, and give them the IDs
|
||||
sensor1 and sensor2. Or change the code below to match your feed.
|
||||
|
||||
|
||||
This example uses the String library, which is part of the Arduino core from
|
||||
version 0019.
|
||||
|
||||
version 0019.
|
||||
|
||||
Circuit:
|
||||
* Analog sensor attached to analog in 0
|
||||
* Ethernet shield attached to pins 10, 11, 12, 13
|
||||
|
||||
|
||||
created 15 March 2010
|
||||
modified 9 Apr 2012
|
||||
by Tom Igoe with input from Usman Haque and Joe Saavedra
|
||||
|
||||
|
||||
http://arduino.cc/en/Tutorial/CosmClientString
|
||||
This code is in the public domain.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
@ -37,27 +37,28 @@
|
||||
|
||||
// assign a MAC address for the ethernet controller.
|
||||
// fill in your address here:
|
||||
byte mac[] = {
|
||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
|
||||
byte mac[] = {
|
||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
|
||||
};
|
||||
|
||||
// fill in an available IP address on your network here,
|
||||
// for manual configuration:
|
||||
IPAddress ip(10,0,1,20);
|
||||
IPAddress ip(10, 0, 1, 20);
|
||||
|
||||
// initialize the library instance:
|
||||
EthernetClient client;
|
||||
|
||||
// if you don't want to use DNS (and reduce your sketch size)
|
||||
// use the numeric IP instead of the name for the server:
|
||||
IPAddress server(216,52,233,121); // numeric IP for api.cosm.com
|
||||
IPAddress server(216, 52, 233, 121); // numeric IP for api.cosm.com
|
||||
//char server[] = "api.cosm.com"; // name address for Cosm API
|
||||
|
||||
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
|
||||
boolean lastConnected = false; // state of the connection last time through the main loop
|
||||
const unsigned long postingInterval = 10*1000; //delay between updates to Cosm.com
|
||||
const unsigned long postingInterval = 10 * 1000; //delay between updates to Cosm.com
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
@ -76,7 +77,7 @@ void setup() {
|
||||
|
||||
void loop() {
|
||||
// read the analog sensor:
|
||||
int sensorReading = analogRead(A0);
|
||||
int sensorReading = analogRead(A0);
|
||||
// convert the data to a String to send it:
|
||||
|
||||
String dataString = "sensor1,";
|
||||
@ -105,8 +106,8 @@ void loop() {
|
||||
}
|
||||
|
||||
// if you're not connected, and ten seconds have passed since
|
||||
// your last connection, then connect again and send data:
|
||||
if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
|
||||
// your last connection, then connect again and send data:
|
||||
if (!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
|
||||
sendData(dataString);
|
||||
}
|
||||
// store the state of the connection for next time through
|
||||
@ -138,7 +139,7 @@ void sendData(String thisData) {
|
||||
|
||||
// here's the actual content of the PUT request:
|
||||
client.println(thisData);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// if you couldn't make a connection:
|
||||
Serial.println("connection failed");
|
||||
|
@ -1,21 +1,21 @@
|
||||
/*
|
||||
Telnet client
|
||||
|
||||
|
||||
This sketch connects to a a telnet server (http://www.google.com)
|
||||
using an Arduino Wiznet Ethernet shield. You'll need a telnet server
|
||||
using an Arduino Wiznet Ethernet shield. You'll need a telnet server
|
||||
to test this with.
|
||||
Processing's ChatServer example (part of the network library) works well,
|
||||
Processing's ChatServer example (part of the network library) works well,
|
||||
running on port 10002. It can be found as part of the examples
|
||||
in the Processing application, available at
|
||||
in the Processing application, available at
|
||||
http://processing.org/
|
||||
|
||||
|
||||
Circuit:
|
||||
* Ethernet shield attached to pins 10, 11, 12, 13
|
||||
|
||||
|
||||
created 14 Sep 2010
|
||||
modified 9 Apr 2012
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
@ -23,15 +23,16 @@
|
||||
|
||||
// Enter a MAC address and IP address for your controller below.
|
||||
// The IP address will be dependent on your local network:
|
||||
byte mac[] = {
|
||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
||||
IPAddress ip(192,168,1,177);
|
||||
byte mac[] = {
|
||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
|
||||
};
|
||||
IPAddress ip(192, 168, 1, 177);
|
||||
|
||||
// Enter the IP address of the server you're connecting to:
|
||||
IPAddress server(1,1,1,1);
|
||||
IPAddress server(1, 1, 1, 1);
|
||||
|
||||
// Initialize the Ethernet client library
|
||||
// with the IP address and port of the server
|
||||
// with the IP address and port of the server
|
||||
// that you want to connect to (port 23 is default for telnet;
|
||||
// if you're using Processing's ChatServer, use port 10002):
|
||||
EthernetClient client;
|
||||
@ -39,9 +40,9 @@ EthernetClient client;
|
||||
void setup() {
|
||||
// start the Ethernet connection:
|
||||
Ethernet.begin(mac, ip);
|
||||
// Open serial communications and wait for port to open:
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
@ -53,7 +54,7 @@ void setup() {
|
||||
// if you get a connection, report back via serial:
|
||||
if (client.connect(server, 10002)) {
|
||||
Serial.println("connected");
|
||||
}
|
||||
}
|
||||
else {
|
||||
// if you didn't get a connection to the server:
|
||||
Serial.println("connection failed");
|
||||
@ -62,7 +63,7 @@ void setup() {
|
||||
|
||||
void loop()
|
||||
{
|
||||
// if there are incoming bytes available
|
||||
// if there are incoming bytes available
|
||||
// from the server, read them and print them:
|
||||
if (client.available()) {
|
||||
char c = client.read();
|
||||
@ -74,7 +75,7 @@ void loop()
|
||||
while (Serial.available() > 0) {
|
||||
char inChar = Serial.read();
|
||||
if (client.connected()) {
|
||||
client.print(inChar);
|
||||
client.print(inChar);
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,7 +85,7 @@ void loop()
|
||||
Serial.println("disconnecting.");
|
||||
client.stop();
|
||||
// do nothing:
|
||||
while(true);
|
||||
while (true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,13 +2,13 @@
|
||||
UDPSendReceive.pde:
|
||||
This sketch receives UDP message strings, prints them to the serial port
|
||||
and sends an "acknowledge" string back to the sender
|
||||
|
||||
A Processing sketch is included at the end of file that can be used to send
|
||||
|
||||
A Processing sketch is included at the end of file that can be used to send
|
||||
and received messages for testing with a computer.
|
||||
|
||||
|
||||
created 21 Aug 2010
|
||||
by Michael Margolis
|
||||
|
||||
|
||||
This code is in the public domain.
|
||||
*/
|
||||
|
||||
@ -20,8 +20,9 @@
|
||||
|
||||
// Enter a MAC address and IP address for your controller below.
|
||||
// The IP address will be dependent on your local network:
|
||||
byte mac[] = {
|
||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
||||
byte mac[] = {
|
||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
|
||||
};
|
||||
IPAddress ip(192, 168, 1, 177);
|
||||
|
||||
unsigned int localPort = 8888; // local port to listen on
|
||||
@ -35,7 +36,7 @@ EthernetUDP Udp;
|
||||
|
||||
void setup() {
|
||||
// start the Ethernet and UDP:
|
||||
Ethernet.begin(mac,ip);
|
||||
Ethernet.begin(mac, ip);
|
||||
Udp.begin(localPort);
|
||||
|
||||
Serial.begin(9600);
|
||||
@ -44,13 +45,13 @@ void setup() {
|
||||
void loop() {
|
||||
// if there's data available, read a packet
|
||||
int packetSize = Udp.parsePacket();
|
||||
if(packetSize)
|
||||
if (packetSize)
|
||||
{
|
||||
Serial.print("Received packet of size ");
|
||||
Serial.println(packetSize);
|
||||
Serial.print("From ");
|
||||
IPAddress remote = Udp.remoteIP();
|
||||
for (int i =0; i < 4; i++)
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
Serial.print(remote[i], DEC);
|
||||
if (i < 3)
|
||||
@ -62,7 +63,7 @@ void loop() {
|
||||
Serial.println(Udp.remotePort());
|
||||
|
||||
// read the packet into packetBufffer
|
||||
Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
|
||||
Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
|
||||
Serial.println("Contents:");
|
||||
Serial.println(packetBuffer);
|
||||
|
||||
@ -78,40 +79,40 @@ void loop() {
|
||||
/*
|
||||
Processing sketch to run with this example
|
||||
=====================================================
|
||||
|
||||
// Processing UDP example to send and receive string data from Arduino
|
||||
|
||||
// Processing UDP example to send and receive string data from Arduino
|
||||
// press any key to send the "Hello Arduino" message
|
||||
|
||||
|
||||
|
||||
|
||||
import hypermedia.net.*;
|
||||
|
||||
|
||||
UDP udp; // define the UDP object
|
||||
|
||||
|
||||
|
||||
|
||||
void setup() {
|
||||
udp = new UDP( this, 6000 ); // create a new datagram connection on port 6000
|
||||
//udp.log( true ); // <-- printout the connection activity
|
||||
udp.listen( true ); // and wait for incoming message
|
||||
udp.listen( true ); // and wait for incoming message
|
||||
}
|
||||
|
||||
|
||||
void draw()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void keyPressed() {
|
||||
String ip = "192.168.1.177"; // the remote IP address
|
||||
int port = 8888; // the destination port
|
||||
|
||||
|
||||
udp.send("Hello World", ip, port ); // the message to send
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void receive( byte[] data ) { // <-- default handler
|
||||
//void receive( byte[] data, String ip, int port ) { // <-- extended handler
|
||||
|
||||
for(int i=0; i < data.length; i++)
|
||||
print(char(data[i]));
|
||||
println();
|
||||
|
||||
for(int i=0; i < data.length; i++)
|
||||
print(char(data[i]));
|
||||
println();
|
||||
}
|
||||
*/
|
||||
|
||||
|
@ -1,46 +1,47 @@
|
||||
/*
|
||||
|
||||
Udp NTP Client
|
||||
|
||||
|
||||
Get the time from a Network Time Protocol (NTP) time server
|
||||
Demonstrates use of UDP sendPacket and ReceivePacket
|
||||
For more on NTP time servers and the messages needed to communicate with them,
|
||||
Demonstrates use of UDP sendPacket and ReceivePacket
|
||||
For more on NTP time servers and the messages needed to communicate with them,
|
||||
see http://en.wikipedia.org/wiki/Network_Time_Protocol
|
||||
|
||||
created 4 Sep 2010
|
||||
|
||||
created 4 Sep 2010
|
||||
by Michael Margolis
|
||||
modified 9 Apr 2012
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
This code is in the public domain.
|
||||
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
#include <EthernetUdp.h>
|
||||
|
||||
// Enter a MAC address for your controller below.
|
||||
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
|
||||
byte mac[] = {
|
||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
||||
byte mac[] = {
|
||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
|
||||
};
|
||||
|
||||
unsigned int localPort = 8888; // local port to listen for UDP packets
|
||||
|
||||
IPAddress timeServer(192, 43, 244, 18); // time.nist.gov NTP server
|
||||
|
||||
const int NTP_PACKET_SIZE= 48; // NTP time stamp is in the first 48 bytes of the message
|
||||
const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message
|
||||
|
||||
byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets
|
||||
byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets
|
||||
|
||||
// A UDP instance to let us send and receive packets over UDP
|
||||
EthernetUDP Udp;
|
||||
|
||||
void setup()
|
||||
void setup()
|
||||
{
|
||||
// Open serial communications and wait for port to open:
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
@ -49,7 +50,7 @@ void setup()
|
||||
if (Ethernet.begin(mac) == 0) {
|
||||
Serial.println("Failed to configure Ethernet using DHCP");
|
||||
// no point in carrying on, so do nothing forevermore:
|
||||
for(;;)
|
||||
for (;;)
|
||||
;
|
||||
}
|
||||
Udp.begin(localPort);
|
||||
@ -59,58 +60,58 @@ void loop()
|
||||
{
|
||||
sendNTPpacket(timeServer); // send an NTP packet to a time server
|
||||
|
||||
// wait to see if a reply is available
|
||||
delay(1000);
|
||||
if ( Udp.parsePacket() ) {
|
||||
// wait to see if a reply is available
|
||||
delay(1000);
|
||||
if ( Udp.parsePacket() ) {
|
||||
// We've received a packet, read the data from it
|
||||
Udp.read(packetBuffer,NTP_PACKET_SIZE); // read the packet into the buffer
|
||||
Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer
|
||||
|
||||
//the timestamp starts at byte 40 of the received packet and is four bytes,
|
||||
// or two words, long. First, esxtract the two words:
|
||||
|
||||
unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
|
||||
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
|
||||
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
|
||||
// combine the four bytes (two words) into a long integer
|
||||
// this is NTP time (seconds since Jan 1 1900):
|
||||
unsigned long secsSince1900 = highWord << 16 | lowWord;
|
||||
unsigned long secsSince1900 = highWord << 16 | lowWord;
|
||||
Serial.print("Seconds since Jan 1 1900 = " );
|
||||
Serial.println(secsSince1900);
|
||||
Serial.println(secsSince1900);
|
||||
|
||||
// now convert NTP time into everyday time:
|
||||
Serial.print("Unix time = ");
|
||||
// Unix time starts on Jan 1 1970. In seconds, that's 2208988800:
|
||||
const unsigned long seventyYears = 2208988800UL;
|
||||
const unsigned long seventyYears = 2208988800UL;
|
||||
// subtract seventy years:
|
||||
unsigned long epoch = secsSince1900 - seventyYears;
|
||||
unsigned long epoch = secsSince1900 - seventyYears;
|
||||
// print Unix time:
|
||||
Serial.println(epoch);
|
||||
Serial.println(epoch);
|
||||
|
||||
|
||||
// print the hour, minute and second:
|
||||
Serial.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT)
|
||||
Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day)
|
||||
Serial.print(':');
|
||||
Serial.print(':');
|
||||
if ( ((epoch % 3600) / 60) < 10 ) {
|
||||
// In the first 10 minutes of each hour, we'll want a leading '0'
|
||||
Serial.print('0');
|
||||
}
|
||||
Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute)
|
||||
Serial.print(':');
|
||||
Serial.print(':');
|
||||
if ( (epoch % 60) < 10 ) {
|
||||
// In the first 10 seconds of each minute, we'll want a leading '0'
|
||||
Serial.print('0');
|
||||
}
|
||||
Serial.println(epoch %60); // print the second
|
||||
Serial.println(epoch % 60); // print the second
|
||||
}
|
||||
// wait ten seconds before asking for the time again
|
||||
delay(10000);
|
||||
delay(10000);
|
||||
}
|
||||
|
||||
// send an NTP request to the time server at the given address
|
||||
// send an NTP request to the time server at the given address
|
||||
unsigned long sendNTPpacket(IPAddress& address)
|
||||
{
|
||||
// set all bytes in the buffer to 0
|
||||
memset(packetBuffer, 0, NTP_PACKET_SIZE);
|
||||
memset(packetBuffer, 0, NTP_PACKET_SIZE);
|
||||
// Initialize values needed to form NTP request
|
||||
// (see URL above for details on the packets)
|
||||
packetBuffer[0] = 0b11100011; // LI, Version, Mode
|
||||
@ -118,16 +119,16 @@ unsigned long sendNTPpacket(IPAddress& address)
|
||||
packetBuffer[2] = 6; // Polling Interval
|
||||
packetBuffer[3] = 0xEC; // Peer Clock Precision
|
||||
// 8 bytes of zero for Root Delay & Root Dispersion
|
||||
packetBuffer[12] = 49;
|
||||
packetBuffer[12] = 49;
|
||||
packetBuffer[13] = 0x4E;
|
||||
packetBuffer[14] = 49;
|
||||
packetBuffer[15] = 52;
|
||||
|
||||
// all NTP fields have been given values, now
|
||||
// you can send a packet requesting a timestamp:
|
||||
// you can send a packet requesting a timestamp:
|
||||
Udp.beginPacket(address, 123); //NTP requests are to port 123
|
||||
Udp.write(packetBuffer,NTP_PACKET_SIZE);
|
||||
Udp.endPacket();
|
||||
Udp.write(packetBuffer, NTP_PACKET_SIZE);
|
||||
Udp.endPacket();
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,17 +1,17 @@
|
||||
/*
|
||||
Web client
|
||||
|
||||
|
||||
This sketch connects to a website (http://www.google.com)
|
||||
using an Arduino Wiznet Ethernet shield.
|
||||
|
||||
using an Arduino Wiznet Ethernet shield.
|
||||
|
||||
Circuit:
|
||||
* Ethernet shield attached to pins 10, 11, 12, 13
|
||||
|
||||
|
||||
created 18 Dec 2009
|
||||
by David A. Mellis
|
||||
modified 9 Apr 2012
|
||||
by Tom Igoe, based on work by Adrian McEwen
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
@ -26,17 +26,17 @@ byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
||||
char server[] = "www.google.com"; // name address for Google (using DNS)
|
||||
|
||||
// Set the static IP address to use if the DHCP fails to assign
|
||||
IPAddress ip(192,168,0,177);
|
||||
IPAddress ip(192, 168, 0, 177);
|
||||
|
||||
// Initialize the Ethernet client library
|
||||
// with the IP address and port of the server
|
||||
// with the IP address and port of the server
|
||||
// that you want to connect to (port 80 is default for HTTP):
|
||||
EthernetClient client;
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ void setup() {
|
||||
client.println("Host: www.google.com");
|
||||
client.println("Connection: close");
|
||||
client.println();
|
||||
}
|
||||
}
|
||||
else {
|
||||
// kf you didn't get a connection to the server:
|
||||
Serial.println("connection failed");
|
||||
@ -68,7 +68,7 @@ void setup() {
|
||||
|
||||
void loop()
|
||||
{
|
||||
// if there are incoming bytes available
|
||||
// if there are incoming bytes available
|
||||
// from the server, read them and print them:
|
||||
if (client.available()) {
|
||||
char c = client.read();
|
||||
@ -82,7 +82,7 @@ void loop()
|
||||
client.stop();
|
||||
|
||||
// do nothing forevermore:
|
||||
while(true);
|
||||
while (true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,23 +1,23 @@
|
||||
/*
|
||||
Repeating Web client
|
||||
|
||||
|
||||
This sketch connects to a a web server and makes a request
|
||||
using a Wiznet Ethernet shield. You can use the Arduino Ethernet shield, or
|
||||
the Adafruit Ethernet shield, either one will work, as long as it's got
|
||||
a Wiznet Ethernet module on board.
|
||||
|
||||
|
||||
This example uses DNS, by assigning the Ethernet client with a MAC address,
|
||||
IP address, and DNS address.
|
||||
|
||||
|
||||
Circuit:
|
||||
* Ethernet shield attached to pins 10, 11, 12, 13
|
||||
|
||||
|
||||
created 19 Apr 2012
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
http://arduino.cc/en/Tutorial/WebClientRepeating
|
||||
This code is in the public domain.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
@ -25,14 +25,15 @@
|
||||
|
||||
// assign a MAC address for the ethernet controller.
|
||||
// fill in your address here:
|
||||
byte mac[] = {
|
||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
|
||||
byte mac[] = {
|
||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
|
||||
};
|
||||
// fill in an available IP address on your network here,
|
||||
// for manual configuration:
|
||||
IPAddress ip(10,0,0,20);
|
||||
IPAddress ip(10, 0, 0, 20);
|
||||
|
||||
// fill in your Domain Name Server address here:
|
||||
IPAddress myDns(1,1,1,1);
|
||||
IPAddress myDns(1, 1, 1, 1);
|
||||
|
||||
// initialize the library instance:
|
||||
EthernetClient client;
|
||||
@ -41,8 +42,8 @@ char server[] = "www.arduino.cc";
|
||||
|
||||
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
|
||||
boolean lastConnected = false; // state of the connection last time through the main loop
|
||||
const unsigned long postingInterval = 60L*1000L; // delay between updates, in milliseconds
|
||||
// the "L" is needed to use long type numbers
|
||||
const unsigned long postingInterval = 60L * 1000L; // delay between updates, in milliseconds
|
||||
// the "L" is needed to use long type numbers
|
||||
|
||||
void setup() {
|
||||
// start serial port:
|
||||
@ -75,7 +76,7 @@ void loop() {
|
||||
|
||||
// if you're not connected, and ten seconds have passed since
|
||||
// your last connection, then connect again and send data:
|
||||
if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
|
||||
if (!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
|
||||
httpRequest();
|
||||
}
|
||||
// store the state of the connection for next time through
|
||||
@ -97,7 +98,7 @@ void httpRequest() {
|
||||
|
||||
// note the time that the connection was made:
|
||||
lastConnectionTime = millis();
|
||||
}
|
||||
}
|
||||
else {
|
||||
// if you couldn't make a connection:
|
||||
Serial.println("connection failed");
|
||||
|
@ -1,18 +1,18 @@
|
||||
/*
|
||||
Web Server
|
||||
|
||||
|
||||
A simple web server that shows the value of the analog input pins.
|
||||
using an Arduino Wiznet Ethernet shield.
|
||||
|
||||
using an Arduino Wiznet Ethernet shield.
|
||||
|
||||
Circuit:
|
||||
* Ethernet shield attached to pins 10, 11, 12, 13
|
||||
* Analog inputs attached to pins A0 through A5 (optional)
|
||||
|
||||
|
||||
created 18 Dec 2009
|
||||
by David A. Mellis
|
||||
modified 9 Apr 2012
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
@ -20,19 +20,20 @@
|
||||
|
||||
// Enter a MAC address and IP address for your controller below.
|
||||
// The IP address will be dependent on your local network:
|
||||
byte mac[] = {
|
||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
||||
IPAddress ip(192,168,1,177);
|
||||
byte mac[] = {
|
||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
|
||||
};
|
||||
IPAddress ip(192, 168, 1, 177);
|
||||
|
||||
// Initialize the Ethernet server library
|
||||
// with the IP address and port you want to use
|
||||
// with the IP address and port you want to use
|
||||
// (port 80 is default for HTTP):
|
||||
EthernetServer server(80);
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
@ -64,7 +65,7 @@ void loop() {
|
||||
client.println("HTTP/1.1 200 OK");
|
||||
client.println("Content-Type: text/html");
|
||||
client.println("Connection: close"); // the connection will be closed after completion of the response
|
||||
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
|
||||
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
|
||||
client.println();
|
||||
client.println("<!DOCTYPE HTML>");
|
||||
client.println("<html>");
|
||||
@ -75,7 +76,7 @@ void loop() {
|
||||
client.print(analogChannel);
|
||||
client.print(" is ");
|
||||
client.print(sensorReading);
|
||||
client.println("<br />");
|
||||
client.println("<br />");
|
||||
}
|
||||
client.println("</html>");
|
||||
break;
|
||||
@ -83,7 +84,7 @@ void loop() {
|
||||
if (c == '\n') {
|
||||
// you're starting a new line
|
||||
currentLineIsBlank = true;
|
||||
}
|
||||
}
|
||||
else if (c != '\r') {
|
||||
// you've gotten a character on the current line
|
||||
currentLineIsBlank = false;
|
||||
|
@ -9,7 +9,7 @@
|
||||
* http://firmata.org/wiki/Download
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This firmware reads all inputs and sends them as fast as it can. It was
|
||||
* inspired by the ease-of-use of the Arduino2Max program.
|
||||
*
|
||||
@ -35,7 +35,7 @@ int samplingInterval = 19; // how often to run the main loop (in ms)
|
||||
void sendPort(byte portNumber, byte portValue)
|
||||
{
|
||||
portValue = portValue & portStatus[portNumber];
|
||||
if(previousPINs[portNumber] != portValue) {
|
||||
if (previousPINs[portNumber] != portValue) {
|
||||
Firmata.sendDigitalPort(portNumber, portValue);
|
||||
previousPINs[portNumber] = portValue;
|
||||
}
|
||||
@ -47,13 +47,13 @@ void setup()
|
||||
|
||||
Firmata.setFirmwareVersion(0, 1);
|
||||
|
||||
for(pin = 0; pin < TOTAL_PINS; pin++) {
|
||||
for (pin = 0; pin < TOTAL_PINS; pin++) {
|
||||
if IS_PIN_DIGITAL(pin) pinMode(PIN_TO_DIGITAL(pin), INPUT);
|
||||
}
|
||||
|
||||
for (port=0; port<TOTAL_PORTS; port++) {
|
||||
for (port = 0; port < TOTAL_PORTS; port++) {
|
||||
status = 0;
|
||||
for (i=0; i<8; i++) {
|
||||
for (i = 0; i < 8; i++) {
|
||||
if (IS_PIN_DIGITAL(port * 8 + i)) status |= (1 << i);
|
||||
}
|
||||
portStatus[port] = status;
|
||||
@ -66,21 +66,21 @@ void loop()
|
||||
{
|
||||
byte i;
|
||||
|
||||
for (i=0; i<TOTAL_PORTS; i++) {
|
||||
sendPort(i, readPort(i, 0xff));
|
||||
for (i = 0; i < TOTAL_PORTS; i++) {
|
||||
sendPort(i, readPort(i, 0xff));
|
||||
}
|
||||
/* make sure that the FTDI buffer doesn't go over 60 bytes, otherwise you
|
||||
get long, random delays. So only read analogs every 20ms or so */
|
||||
currentMillis = millis();
|
||||
if(currentMillis - previousMillis > samplingInterval) {
|
||||
if (currentMillis - previousMillis > samplingInterval) {
|
||||
previousMillis += samplingInterval;
|
||||
while(Firmata.available()) {
|
||||
while (Firmata.available()) {
|
||||
Firmata.processInput();
|
||||
}
|
||||
for(pin = 0; pin < TOTAL_ANALOG_PINS; pin++) {
|
||||
for (pin = 0; pin < TOTAL_ANALOG_PINS; pin++) {
|
||||
analogValue = analogRead(pin);
|
||||
if(analogValue != previousAnalogValues[pin]) {
|
||||
Firmata.sendAnalog(pin, analogValue);
|
||||
if (analogValue != previousAnalogValues[pin]) {
|
||||
Firmata.sendAnalog(pin, analogValue);
|
||||
previousAnalogValues[pin] = analogValue;
|
||||
}
|
||||
}
|
||||
|
@ -32,63 +32,63 @@ unsigned long previousMillis; // for comparison with currentMillis
|
||||
|
||||
|
||||
/*==============================================================================
|
||||
* FUNCTIONS
|
||||
* FUNCTIONS
|
||||
*============================================================================*/
|
||||
|
||||
void analogWriteCallback(byte pin, int value)
|
||||
{
|
||||
switch(pin) {
|
||||
switch (pin) {
|
||||
case 9: servo9.write(value); break;
|
||||
case 10: servo10.write(value); break;
|
||||
case 3:
|
||||
case 5:
|
||||
case 6:
|
||||
case 3:
|
||||
case 5:
|
||||
case 6:
|
||||
case 11: // PWM pins
|
||||
analogWrite(pin, value);
|
||||
break;
|
||||
}
|
||||
analogWrite(pin, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
// sets bits in a bit array (int) to toggle the reporting of the analogIns
|
||||
void reportAnalogCallback(byte pin, int value)
|
||||
{
|
||||
if(value == 0) {
|
||||
analogInputsToReport = analogInputsToReport &~ (1 << pin);
|
||||
}
|
||||
else { // everything but 0 enables reporting of that pin
|
||||
analogInputsToReport = analogInputsToReport | (1 << pin);
|
||||
}
|
||||
// TODO: save status to EEPROM here, if changed
|
||||
if (value == 0) {
|
||||
analogInputsToReport = analogInputsToReport &~ (1 << pin);
|
||||
}
|
||||
else { // everything but 0 enables reporting of that pin
|
||||
analogInputsToReport = analogInputsToReport | (1 << pin);
|
||||
}
|
||||
// TODO: save status to EEPROM here, if changed
|
||||
}
|
||||
|
||||
/*==============================================================================
|
||||
* SETUP()
|
||||
*============================================================================*/
|
||||
void setup()
|
||||
void setup()
|
||||
{
|
||||
Firmata.setFirmwareVersion(0, 2);
|
||||
Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
|
||||
Firmata.attach(REPORT_ANALOG, reportAnalogCallback);
|
||||
Firmata.setFirmwareVersion(0, 2);
|
||||
Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
|
||||
Firmata.attach(REPORT_ANALOG, reportAnalogCallback);
|
||||
|
||||
servo9.attach(9);
|
||||
servo10.attach(10);
|
||||
Firmata.begin(57600);
|
||||
servo9.attach(9);
|
||||
servo10.attach(10);
|
||||
Firmata.begin(57600);
|
||||
}
|
||||
|
||||
/*==============================================================================
|
||||
* LOOP()
|
||||
*============================================================================*/
|
||||
void loop()
|
||||
void loop()
|
||||
{
|
||||
while(Firmata.available())
|
||||
Firmata.processInput();
|
||||
currentMillis = millis();
|
||||
if(currentMillis - previousMillis > 20) {
|
||||
previousMillis += 20; // run this every 20ms
|
||||
for(analogPin=0;analogPin<TOTAL_ANALOG_PINS;analogPin++) {
|
||||
if( analogInputsToReport & (1 << analogPin) )
|
||||
Firmata.sendAnalog(analogPin, analogRead(analogPin));
|
||||
}
|
||||
while (Firmata.available())
|
||||
Firmata.processInput();
|
||||
currentMillis = millis();
|
||||
if (currentMillis - previousMillis > 20) {
|
||||
previousMillis += 20; // run this every 20ms
|
||||
for (analogPin = 0; analogPin < TOTAL_ANALOG_PINS; analogPin++) {
|
||||
if ( analogInputsToReport & (1 << analogPin) )
|
||||
Firmata.sendAnalog(analogPin, analogRead(analogPin));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,28 +17,28 @@
|
||||
|
||||
void stringCallback(char *myString)
|
||||
{
|
||||
Firmata.sendString(myString);
|
||||
Firmata.sendString(myString);
|
||||
}
|
||||
|
||||
|
||||
void sysexCallback(byte command, byte argc, byte*argv)
|
||||
{
|
||||
Firmata.sendSysex(command, argc, argv);
|
||||
Firmata.sendSysex(command, argc, argv);
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Firmata.setFirmwareVersion(0, 1);
|
||||
Firmata.attach(STRING_DATA, stringCallback);
|
||||
Firmata.attach(START_SYSEX, sysexCallback);
|
||||
Firmata.begin(57600);
|
||||
Firmata.setFirmwareVersion(0, 1);
|
||||
Firmata.attach(STRING_DATA, stringCallback);
|
||||
Firmata.attach(START_SYSEX, sysexCallback);
|
||||
Firmata.begin(57600);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
while(Firmata.available()) {
|
||||
Firmata.processInput();
|
||||
}
|
||||
while (Firmata.available()) {
|
||||
Firmata.processInput();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -11,16 +11,16 @@
|
||||
|
||||
/*
|
||||
Copyright (C) 2006-2008 Hans-Christoph Steiner. All rights reserved.
|
||||
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
|
||||
See file LICENSE.txt for further informations on licensing terms.
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This is an old version of StandardFirmata (v2.0). It is kept here because
|
||||
* its the last version that works on an ATMEGA8 chip. Also, it can be used
|
||||
* for host software that has not been updated to a newer version of the
|
||||
@ -50,34 +50,34 @@ unsigned long previousMillis; // for comparison with currentMillis
|
||||
|
||||
|
||||
/*==============================================================================
|
||||
* FUNCTIONS
|
||||
* FUNCTIONS
|
||||
*============================================================================*/
|
||||
|
||||
void outputPort(byte portNumber, byte portValue)
|
||||
{
|
||||
portValue = portValue &~ portStatus[portNumber];
|
||||
if(previousPINs[portNumber] != portValue) {
|
||||
Firmata.sendDigitalPort(portNumber, portValue);
|
||||
previousPINs[portNumber] = portValue;
|
||||
Firmata.sendDigitalPort(portNumber, portValue);
|
||||
}
|
||||
if (previousPINs[portNumber] != portValue) {
|
||||
Firmata.sendDigitalPort(portNumber, portValue);
|
||||
previousPINs[portNumber] = portValue;
|
||||
Firmata.sendDigitalPort(portNumber, portValue);
|
||||
}
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* check all the active digital inputs for change of state, then add any events
|
||||
* to the Serial output queue using Serial.print() */
|
||||
void checkDigitalInputs(void)
|
||||
void checkDigitalInputs(void)
|
||||
{
|
||||
byte i, tmp;
|
||||
for(i=0; i < TOTAL_PORTS; i++) {
|
||||
if(reportPINs[i]) {
|
||||
switch(i) {
|
||||
case 0: outputPort(0, PIND &~ B00000011); break; // ignore Rx/Tx 0/1
|
||||
case 1: outputPort(1, PINB); break;
|
||||
case 2: outputPort(2, PINC); break;
|
||||
}
|
||||
}
|
||||
byte i, tmp;
|
||||
for (i = 0; i < TOTAL_PORTS; i++) {
|
||||
if (reportPINs[i]) {
|
||||
switch (i) {
|
||||
case 0: outputPort(0, PIND &~ B00000011); break; // ignore Rx/Tx 0/1
|
||||
case 1: outputPort(1, PINB); break;
|
||||
case 2: outputPort(2, PINC); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -85,61 +85,61 @@ void checkDigitalInputs(void)
|
||||
* two bit-arrays that track Digital I/O and PWM status
|
||||
*/
|
||||
void setPinModeCallback(byte pin, int mode) {
|
||||
byte port = 0;
|
||||
byte offset = 0;
|
||||
byte port = 0;
|
||||
byte offset = 0;
|
||||
|
||||
if (pin < 8) {
|
||||
port = 0;
|
||||
offset = 0;
|
||||
} else if (pin < 14) {
|
||||
port = 1;
|
||||
offset = 8;
|
||||
} else if (pin < 22) {
|
||||
port = 2;
|
||||
offset = 14;
|
||||
}
|
||||
if (pin < 8) {
|
||||
port = 0;
|
||||
offset = 0;
|
||||
} else if (pin < 14) {
|
||||
port = 1;
|
||||
offset = 8;
|
||||
} else if (pin < 22) {
|
||||
port = 2;
|
||||
offset = 14;
|
||||
}
|
||||
|
||||
if(pin > 1) { // ignore RxTx (pins 0 and 1)
|
||||
pinStatus[pin] = mode;
|
||||
switch(mode) {
|
||||
case INPUT:
|
||||
pinMode(pin, INPUT);
|
||||
portStatus[port] = portStatus[port] &~ (1 << (pin - offset));
|
||||
break;
|
||||
case OUTPUT:
|
||||
digitalWrite(pin, LOW); // disable PWM
|
||||
case PWM:
|
||||
pinMode(pin, OUTPUT);
|
||||
portStatus[port] = portStatus[port] | (1 << (pin - offset));
|
||||
break;
|
||||
if (pin > 1) { // ignore RxTx (pins 0 and 1)
|
||||
pinStatus[pin] = mode;
|
||||
switch (mode) {
|
||||
case INPUT:
|
||||
pinMode(pin, INPUT);
|
||||
portStatus[port] = portStatus[port] &~ (1 << (pin - offset));
|
||||
break;
|
||||
case OUTPUT:
|
||||
digitalWrite(pin, LOW); // disable PWM
|
||||
case PWM:
|
||||
pinMode(pin, OUTPUT);
|
||||
portStatus[port] = portStatus[port] | (1 << (pin - offset));
|
||||
break;
|
||||
//case ANALOG: // TODO figure this out
|
||||
default:
|
||||
Firmata.sendString("");
|
||||
}
|
||||
// TODO: save status to EEPROM here, if changed
|
||||
default:
|
||||
Firmata.sendString("");
|
||||
}
|
||||
// TODO: save status to EEPROM here, if changed
|
||||
}
|
||||
}
|
||||
|
||||
void analogWriteCallback(byte pin, int value)
|
||||
{
|
||||
setPinModeCallback(pin,PWM);
|
||||
analogWrite(pin, value);
|
||||
setPinModeCallback(pin, PWM);
|
||||
analogWrite(pin, value);
|
||||
}
|
||||
|
||||
void digitalWriteCallback(byte port, int value)
|
||||
{
|
||||
switch(port) {
|
||||
switch (port) {
|
||||
case 0: // pins 2-7 (don't change Rx/Tx, pins 0 and 1)
|
||||
// 0xFF03 == B1111111100000011 0x03 == B00000011
|
||||
PORTD = (value &~ 0xFF03) | (PORTD & 0x03);
|
||||
break;
|
||||
case 1: // pins 8-13 (14,15 are disabled for the crystal)
|
||||
PORTB = (byte)value;
|
||||
break;
|
||||
// 0xFF03 == B1111111100000011 0x03 == B00000011
|
||||
PORTD = (value &~ 0xFF03) | (PORTD & 0x03);
|
||||
break;
|
||||
case 1: // pins 8-13 (14,15 are disabled for the crystal)
|
||||
PORTB = (byte)value;
|
||||
break;
|
||||
case 2: // analog pins used as digital
|
||||
PORTC = (byte)value;
|
||||
break;
|
||||
}
|
||||
PORTC = (byte)value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -149,91 +149,91 @@ void digitalWriteCallback(byte port, int value)
|
||||
//}
|
||||
void reportAnalogCallback(byte pin, int value)
|
||||
{
|
||||
if(value == 0) {
|
||||
analogInputsToReport = analogInputsToReport &~ (1 << pin);
|
||||
}
|
||||
else { // everything but 0 enables reporting of that pin
|
||||
analogInputsToReport = analogInputsToReport | (1 << pin);
|
||||
}
|
||||
// TODO: save status to EEPROM here, if changed
|
||||
if (value == 0) {
|
||||
analogInputsToReport = analogInputsToReport &~ (1 << pin);
|
||||
}
|
||||
else { // everything but 0 enables reporting of that pin
|
||||
analogInputsToReport = analogInputsToReport | (1 << pin);
|
||||
}
|
||||
// TODO: save status to EEPROM here, if changed
|
||||
}
|
||||
|
||||
void reportDigitalCallback(byte port, int value)
|
||||
{
|
||||
reportPINs[port] = (byte)value;
|
||||
if(port == 2) // turn off analog reporting when used as digital
|
||||
analogInputsToReport = 0;
|
||||
reportPINs[port] = (byte)value;
|
||||
if (port == 2) // turn off analog reporting when used as digital
|
||||
analogInputsToReport = 0;
|
||||
}
|
||||
|
||||
/*==============================================================================
|
||||
* SETUP()
|
||||
*============================================================================*/
|
||||
void setup()
|
||||
void setup()
|
||||
{
|
||||
byte i;
|
||||
byte i;
|
||||
|
||||
Firmata.setFirmwareVersion(2, 0);
|
||||
Firmata.setFirmwareVersion(2, 0);
|
||||
|
||||
Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
|
||||
Firmata.attach(DIGITAL_MESSAGE, digitalWriteCallback);
|
||||
Firmata.attach(REPORT_ANALOG, reportAnalogCallback);
|
||||
Firmata.attach(REPORT_DIGITAL, reportDigitalCallback);
|
||||
Firmata.attach(SET_PIN_MODE, setPinModeCallback);
|
||||
Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
|
||||
Firmata.attach(DIGITAL_MESSAGE, digitalWriteCallback);
|
||||
Firmata.attach(REPORT_ANALOG, reportAnalogCallback);
|
||||
Firmata.attach(REPORT_DIGITAL, reportDigitalCallback);
|
||||
Firmata.attach(SET_PIN_MODE, setPinModeCallback);
|
||||
|
||||
portStatus[0] = B00000011; // ignore Tx/RX pins
|
||||
portStatus[1] = B11000000; // ignore 14/15 pins
|
||||
portStatus[2] = B00000000;
|
||||
portStatus[0] = B00000011; // ignore Tx/RX pins
|
||||
portStatus[1] = B11000000; // ignore 14/15 pins
|
||||
portStatus[2] = B00000000;
|
||||
|
||||
// for(i=0; i<TOTAL_PINS; ++i) { // TODO make this work with analogs
|
||||
for(i=0; i<14; ++i) {
|
||||
setPinModeCallback(i,OUTPUT);
|
||||
}
|
||||
// set all outputs to 0 to make sure internal pull-up resistors are off
|
||||
PORTB = 0; // pins 8-15
|
||||
PORTC = 0; // analog port
|
||||
PORTD = 0; // pins 0-7
|
||||
// for(i=0; i<TOTAL_PINS; ++i) { // TODO make this work with analogs
|
||||
for (i = 0; i < 14; ++i) {
|
||||
setPinModeCallback(i, OUTPUT);
|
||||
}
|
||||
// set all outputs to 0 to make sure internal pull-up resistors are off
|
||||
PORTB = 0; // pins 8-15
|
||||
PORTC = 0; // analog port
|
||||
PORTD = 0; // pins 0-7
|
||||
|
||||
// TODO rethink the init, perhaps it should report analog on default
|
||||
for(i=0; i<TOTAL_PORTS; ++i) {
|
||||
reportPINs[i] = false;
|
||||
}
|
||||
// TODO: load state from EEPROM here
|
||||
// TODO rethink the init, perhaps it should report analog on default
|
||||
for (i = 0; i < TOTAL_PORTS; ++i) {
|
||||
reportPINs[i] = false;
|
||||
}
|
||||
// TODO: load state from EEPROM here
|
||||
|
||||
/* send digital inputs here, if enabled, to set the initial state on the
|
||||
* host computer, since once in the loop(), this firmware will only send
|
||||
* digital data on change. */
|
||||
if(reportPINs[0]) outputPort(0, PIND &~ B00000011); // ignore Rx/Tx 0/1
|
||||
if(reportPINs[1]) outputPort(1, PINB);
|
||||
if(reportPINs[2]) outputPort(2, PINC);
|
||||
/* send digital inputs here, if enabled, to set the initial state on the
|
||||
* host computer, since once in the loop(), this firmware will only send
|
||||
* digital data on change. */
|
||||
if (reportPINs[0]) outputPort(0, PIND &~ B00000011); // ignore Rx/Tx 0/1
|
||||
if (reportPINs[1]) outputPort(1, PINB);
|
||||
if (reportPINs[2]) outputPort(2, PINC);
|
||||
|
||||
Firmata.begin(115200);
|
||||
Firmata.begin(115200);
|
||||
}
|
||||
|
||||
/*==============================================================================
|
||||
* LOOP()
|
||||
*============================================================================*/
|
||||
void loop()
|
||||
void loop()
|
||||
{
|
||||
/* DIGITALREAD - as fast as possible, check for changes and output them to the
|
||||
* FTDI buffer using Serial.print() */
|
||||
checkDigitalInputs();
|
||||
currentMillis = millis();
|
||||
if(currentMillis - previousMillis > 20) {
|
||||
previousMillis += 20; // run this every 20ms
|
||||
/* SERIALREAD - Serial.read() uses a 128 byte circular buffer, so handle
|
||||
* all serialReads at once, i.e. empty the buffer */
|
||||
while(Firmata.available())
|
||||
Firmata.processInput();
|
||||
/* SEND FTDI WRITE BUFFER - make sure that the FTDI buffer doesn't go over
|
||||
* 60 bytes. use a timer to sending an event character every 4 ms to
|
||||
* trigger the buffer to dump. */
|
||||
|
||||
/* ANALOGREAD - right after the event character, do all of the
|
||||
* analogReads(). These only need to be done every 4ms. */
|
||||
for(analogPin=0;analogPin<TOTAL_ANALOG_PINS;analogPin++) {
|
||||
if( analogInputsToReport & (1 << analogPin) ) {
|
||||
Firmata.sendAnalog(analogPin, analogRead(analogPin));
|
||||
}
|
||||
}
|
||||
/* DIGITALREAD - as fast as possible, check for changes and output them to the
|
||||
* FTDI buffer using Serial.print() */
|
||||
checkDigitalInputs();
|
||||
currentMillis = millis();
|
||||
if (currentMillis - previousMillis > 20) {
|
||||
previousMillis += 20; // run this every 20ms
|
||||
/* SERIALREAD - Serial.read() uses a 128 byte circular buffer, so handle
|
||||
* all serialReads at once, i.e. empty the buffer */
|
||||
while (Firmata.available())
|
||||
Firmata.processInput();
|
||||
/* SEND FTDI WRITE BUFFER - make sure that the FTDI buffer doesn't go over
|
||||
* 60 bytes. use a timer to sending an event character every 4 ms to
|
||||
* trigger the buffer to dump. */
|
||||
|
||||
/* ANALOGREAD - right after the event character, do all of the
|
||||
* analogReads(). These only need to be done every 4ms. */
|
||||
for (analogPin = 0; analogPin < TOTAL_ANALOG_PINS; analogPin++) {
|
||||
if ( analogInputsToReport & (1 << analogPin) ) {
|
||||
Firmata.sendAnalog(analogPin, analogRead(analogPin));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,14 +9,14 @@
|
||||
* http://firmata.org/wiki/Download
|
||||
*/
|
||||
|
||||
/* This firmware supports as many servos as possible using the Servo library
|
||||
/* This firmware supports as many servos as possible using the Servo library
|
||||
* included in Arduino 0017
|
||||
*
|
||||
* TODO add message to configure minPulse/maxPulse/degrees
|
||||
*
|
||||
* This example code is in the public domain.
|
||||
*/
|
||||
|
||||
|
||||
#include <Servo.h>
|
||||
#include <Firmata.h>
|
||||
|
||||
@ -24,30 +24,30 @@ Servo servos[MAX_SERVOS];
|
||||
|
||||
void analogWriteCallback(byte pin, int value)
|
||||
{
|
||||
if (IS_PIN_SERVO(pin)) {
|
||||
servos[PIN_TO_SERVO(pin)].write(value);
|
||||
}
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
byte pin;
|
||||
|
||||
Firmata.setFirmwareVersion(0, 2);
|
||||
Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
|
||||
|
||||
for (pin = 0; pin < TOTAL_PINS; pin++) {
|
||||
if (IS_PIN_SERVO(pin)) {
|
||||
servos[PIN_TO_SERVO(pin)].write(value);
|
||||
servos[PIN_TO_SERVO(pin)].attach(PIN_TO_DIGITAL(pin));
|
||||
}
|
||||
}
|
||||
|
||||
Firmata.begin(57600);
|
||||
}
|
||||
|
||||
void setup()
|
||||
void loop()
|
||||
{
|
||||
byte pin;
|
||||
|
||||
Firmata.setFirmwareVersion(0, 2);
|
||||
Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
|
||||
|
||||
for (pin=0; pin < TOTAL_PINS; pin++) {
|
||||
if (IS_PIN_SERVO(pin)) {
|
||||
servos[PIN_TO_SERVO(pin)].attach(PIN_TO_DIGITAL(pin));
|
||||
}
|
||||
}
|
||||
|
||||
Firmata.begin(57600);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
while(Firmata.available())
|
||||
Firmata.processInput();
|
||||
while (Firmata.available())
|
||||
Firmata.processInput();
|
||||
}
|
||||
|
||||
|
@ -19,28 +19,28 @@ byte analogPin = 0;
|
||||
|
||||
void analogWriteCallback(byte pin, int value)
|
||||
{
|
||||
if (IS_PIN_PWM(pin)) {
|
||||
pinMode(PIN_TO_DIGITAL(pin), OUTPUT);
|
||||
analogWrite(PIN_TO_PWM(pin), value);
|
||||
}
|
||||
if (IS_PIN_PWM(pin)) {
|
||||
pinMode(PIN_TO_DIGITAL(pin), OUTPUT);
|
||||
analogWrite(PIN_TO_PWM(pin), value);
|
||||
}
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Firmata.setFirmwareVersion(0, 1);
|
||||
Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
|
||||
Firmata.begin(57600);
|
||||
Firmata.setFirmwareVersion(0, 1);
|
||||
Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
|
||||
Firmata.begin(57600);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
while(Firmata.available()) {
|
||||
Firmata.processInput();
|
||||
}
|
||||
// do one analogRead per loop, so if PC is sending a lot of
|
||||
// analog write messages, we will only delay 1 analogRead
|
||||
Firmata.sendAnalog(analogPin, analogRead(analogPin));
|
||||
analogPin = analogPin + 1;
|
||||
if (analogPin >= TOTAL_ANALOG_PINS) analogPin = 0;
|
||||
while (Firmata.available()) {
|
||||
Firmata.processInput();
|
||||
}
|
||||
// do one analogRead per loop, so if PC is sending a lot of
|
||||
// analog write messages, we will only delay 1 analogRead
|
||||
Firmata.sendAnalog(analogPin, analogRead(analogPin));
|
||||
analogPin = analogPin + 1;
|
||||
if (analogPin >= TOTAL_ANALOG_PINS) analogPin = 0;
|
||||
}
|
||||
|
||||
|
@ -16,57 +16,57 @@
|
||||
#include <Firmata.h>
|
||||
|
||||
byte previousPIN[TOTAL_PORTS]; // PIN means PORT for input
|
||||
byte previousPORT[TOTAL_PORTS];
|
||||
byte previousPORT[TOTAL_PORTS];
|
||||
|
||||
void outputPort(byte portNumber, byte portValue)
|
||||
{
|
||||
// only send the data when it changes, otherwise you get too many messages!
|
||||
if (previousPIN[portNumber] != portValue) {
|
||||
Firmata.sendDigitalPort(portNumber, portValue);
|
||||
previousPIN[portNumber] = portValue;
|
||||
}
|
||||
// only send the data when it changes, otherwise you get too many messages!
|
||||
if (previousPIN[portNumber] != portValue) {
|
||||
Firmata.sendDigitalPort(portNumber, portValue);
|
||||
previousPIN[portNumber] = portValue;
|
||||
}
|
||||
}
|
||||
|
||||
void setPinModeCallback(byte pin, int mode) {
|
||||
if (IS_PIN_DIGITAL(pin)) {
|
||||
pinMode(PIN_TO_DIGITAL(pin), mode);
|
||||
}
|
||||
if (IS_PIN_DIGITAL(pin)) {
|
||||
pinMode(PIN_TO_DIGITAL(pin), mode);
|
||||
}
|
||||
}
|
||||
|
||||
void digitalWriteCallback(byte port, int value)
|
||||
{
|
||||
byte i;
|
||||
byte currentPinValue, previousPinValue;
|
||||
byte i;
|
||||
byte currentPinValue, previousPinValue;
|
||||
|
||||
if (port < TOTAL_PORTS && value != previousPORT[port]) {
|
||||
for(i=0; i<8; i++) {
|
||||
currentPinValue = (byte) value & (1 << i);
|
||||
previousPinValue = previousPORT[port] & (1 << i);
|
||||
if(currentPinValue != previousPinValue) {
|
||||
digitalWrite(i + (port*8), currentPinValue);
|
||||
}
|
||||
}
|
||||
previousPORT[port] = value;
|
||||
if (port < TOTAL_PORTS && value != previousPORT[port]) {
|
||||
for (i = 0; i < 8; i++) {
|
||||
currentPinValue = (byte) value & (1 << i);
|
||||
previousPinValue = previousPORT[port] & (1 << i);
|
||||
if (currentPinValue != previousPinValue) {
|
||||
digitalWrite(i + (port * 8), currentPinValue);
|
||||
}
|
||||
}
|
||||
previousPORT[port] = value;
|
||||
}
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Firmata.setFirmwareVersion(0, 1);
|
||||
Firmata.attach(DIGITAL_MESSAGE, digitalWriteCallback);
|
||||
Firmata.attach(SET_PIN_MODE, setPinModeCallback);
|
||||
Firmata.begin(57600);
|
||||
Firmata.setFirmwareVersion(0, 1);
|
||||
Firmata.attach(DIGITAL_MESSAGE, digitalWriteCallback);
|
||||
Firmata.attach(SET_PIN_MODE, setPinModeCallback);
|
||||
Firmata.begin(57600);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
byte i;
|
||||
byte i;
|
||||
|
||||
for (i=0; i<TOTAL_PORTS; i++) {
|
||||
outputPort(i, readPort(i, 0xff));
|
||||
}
|
||||
for (i = 0; i < TOTAL_PORTS; i++) {
|
||||
outputPort(i, readPort(i, 0xff));
|
||||
}
|
||||
|
||||
while(Firmata.available()) {
|
||||
Firmata.processInput();
|
||||
}
|
||||
while (Firmata.available()) {
|
||||
Firmata.processInput();
|
||||
}
|
||||
}
|
||||
|
@ -14,18 +14,18 @@
|
||||
Copyright (C) 2010-2011 Paul Stoffregen. All rights reserved.
|
||||
Copyright (C) 2009 Shigeru Kobayashi. All rights reserved.
|
||||
Copyright (C) 2009-2011 Jeff Hoefs. All rights reserved.
|
||||
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
|
||||
See file LICENSE.txt for further informations on licensing terms.
|
||||
|
||||
formatted using the GNU C formatting and indenting
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* TODO: use Program Control to load stored profiles from EEPROM
|
||||
*/
|
||||
|
||||
@ -90,14 +90,14 @@ Servo servos[MAX_SERVOS];
|
||||
void readAndReportData(byte address, int theRegister, byte numBytes) {
|
||||
// allow I2C requests that don't require a register read
|
||||
// for example, some devices using an interrupt pin to signify new data available
|
||||
// do not always require the register read so upon interrupt you call Wire.requestFrom()
|
||||
// do not always require the register read so upon interrupt you call Wire.requestFrom()
|
||||
if (theRegister != REGISTER_NOT_SPECIFIED) {
|
||||
Wire.beginTransmission(address);
|
||||
#if ARDUINO >= 100
|
||||
#if ARDUINO >= 100
|
||||
Wire.write((byte)theRegister);
|
||||
#else
|
||||
#else
|
||||
Wire.send((byte)theRegister);
|
||||
#endif
|
||||
#endif
|
||||
Wire.endTransmission();
|
||||
// do not set a value of 0
|
||||
if (i2cReadDelayTime > 0) {
|
||||
@ -111,22 +111,22 @@ void readAndReportData(byte address, int theRegister, byte numBytes) {
|
||||
Wire.requestFrom(address, numBytes); // all bytes are returned in requestFrom
|
||||
|
||||
// check to be sure correct number of bytes were returned by slave
|
||||
if(numBytes == Wire.available()) {
|
||||
if (numBytes == Wire.available()) {
|
||||
i2cRxData[0] = address;
|
||||
i2cRxData[1] = theRegister;
|
||||
for (int i = 0; i < numBytes; i++) {
|
||||
#if ARDUINO >= 100
|
||||
#if ARDUINO >= 100
|
||||
i2cRxData[2 + i] = Wire.read();
|
||||
#else
|
||||
#else
|
||||
i2cRxData[2 + i] = Wire.receive();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(numBytes > Wire.available()) {
|
||||
if (numBytes > Wire.available()) {
|
||||
Firmata.sendString("I2C Read Error: Too many bytes received");
|
||||
} else {
|
||||
Firmata.sendString("I2C Read Error: Too few bytes received");
|
||||
Firmata.sendString("I2C Read Error: Too few bytes received");
|
||||
}
|
||||
}
|
||||
|
||||
@ -139,7 +139,7 @@ void outputPort(byte portNumber, byte portValue, byte forceSend)
|
||||
// pins not configured as INPUT are cleared to zeros
|
||||
portValue = portValue & portConfigInputs[portNumber];
|
||||
// only send if the value is different than previously sent
|
||||
if(forceSend || previousPINs[portNumber] != portValue) {
|
||||
if (forceSend || previousPINs[portNumber] != portValue) {
|
||||
Firmata.sendDigitalPort(portNumber, portValue);
|
||||
previousPINs[portNumber] = portValue;
|
||||
}
|
||||
@ -190,60 +190,60 @@ void setPinModeCallback(byte pin, int mode)
|
||||
}
|
||||
if (IS_PIN_DIGITAL(pin)) {
|
||||
if (mode == INPUT) {
|
||||
portConfigInputs[pin/8] |= (1 << (pin & 7));
|
||||
portConfigInputs[pin / 8] |= (1 << (pin & 7));
|
||||
} else {
|
||||
portConfigInputs[pin/8] &= ~(1 << (pin & 7));
|
||||
portConfigInputs[pin / 8] &= ~(1 << (pin & 7));
|
||||
}
|
||||
}
|
||||
pinState[pin] = 0;
|
||||
switch(mode) {
|
||||
case ANALOG:
|
||||
if (IS_PIN_ANALOG(pin)) {
|
||||
switch (mode) {
|
||||
case ANALOG:
|
||||
if (IS_PIN_ANALOG(pin)) {
|
||||
if (IS_PIN_DIGITAL(pin)) {
|
||||
pinMode(PIN_TO_DIGITAL(pin), INPUT); // disable output driver
|
||||
digitalWrite(PIN_TO_DIGITAL(pin), LOW); // disable internal pull-ups
|
||||
}
|
||||
pinConfig[pin] = ANALOG;
|
||||
}
|
||||
break;
|
||||
case INPUT:
|
||||
if (IS_PIN_DIGITAL(pin)) {
|
||||
pinMode(PIN_TO_DIGITAL(pin), INPUT); // disable output driver
|
||||
digitalWrite(PIN_TO_DIGITAL(pin), LOW); // disable internal pull-ups
|
||||
pinConfig[pin] = INPUT;
|
||||
}
|
||||
pinConfig[pin] = ANALOG;
|
||||
}
|
||||
break;
|
||||
case INPUT:
|
||||
if (IS_PIN_DIGITAL(pin)) {
|
||||
pinMode(PIN_TO_DIGITAL(pin), INPUT); // disable output driver
|
||||
digitalWrite(PIN_TO_DIGITAL(pin), LOW); // disable internal pull-ups
|
||||
pinConfig[pin] = INPUT;
|
||||
}
|
||||
break;
|
||||
case OUTPUT:
|
||||
if (IS_PIN_DIGITAL(pin)) {
|
||||
digitalWrite(PIN_TO_DIGITAL(pin), LOW); // disable PWM
|
||||
pinMode(PIN_TO_DIGITAL(pin), OUTPUT);
|
||||
pinConfig[pin] = OUTPUT;
|
||||
}
|
||||
break;
|
||||
case PWM:
|
||||
if (IS_PIN_PWM(pin)) {
|
||||
pinMode(PIN_TO_PWM(pin), OUTPUT);
|
||||
analogWrite(PIN_TO_PWM(pin), 0);
|
||||
pinConfig[pin] = PWM;
|
||||
}
|
||||
break;
|
||||
case SERVO:
|
||||
if (IS_PIN_SERVO(pin)) {
|
||||
pinConfig[pin] = SERVO;
|
||||
if (!servos[PIN_TO_SERVO(pin)].attached()) {
|
||||
break;
|
||||
case OUTPUT:
|
||||
if (IS_PIN_DIGITAL(pin)) {
|
||||
digitalWrite(PIN_TO_DIGITAL(pin), LOW); // disable PWM
|
||||
pinMode(PIN_TO_DIGITAL(pin), OUTPUT);
|
||||
pinConfig[pin] = OUTPUT;
|
||||
}
|
||||
break;
|
||||
case PWM:
|
||||
if (IS_PIN_PWM(pin)) {
|
||||
pinMode(PIN_TO_PWM(pin), OUTPUT);
|
||||
analogWrite(PIN_TO_PWM(pin), 0);
|
||||
pinConfig[pin] = PWM;
|
||||
}
|
||||
break;
|
||||
case SERVO:
|
||||
if (IS_PIN_SERVO(pin)) {
|
||||
pinConfig[pin] = SERVO;
|
||||
if (!servos[PIN_TO_SERVO(pin)].attached()) {
|
||||
servos[PIN_TO_SERVO(pin)].attach(PIN_TO_DIGITAL(pin));
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case I2C:
|
||||
if (IS_PIN_I2C(pin)) {
|
||||
// mark the pin as i2c
|
||||
// the user must call I2C_CONFIG to enable I2C for a device
|
||||
pinConfig[pin] = I2C;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Firmata.sendString("Unknown pin mode"); // TODO: put error msgs in EEPROM
|
||||
break;
|
||||
case I2C:
|
||||
if (IS_PIN_I2C(pin)) {
|
||||
// mark the pin as i2c
|
||||
// the user must call I2C_CONFIG to enable I2C for a device
|
||||
pinConfig[pin] = I2C;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Firmata.sendString("Unknown pin mode"); // TODO: put error msgs in EEPROM
|
||||
}
|
||||
// TODO: save status to EEPROM here, if changed
|
||||
}
|
||||
@ -251,30 +251,30 @@ void setPinModeCallback(byte pin, int mode)
|
||||
void analogWriteCallback(byte pin, int value)
|
||||
{
|
||||
if (pin < TOTAL_PINS) {
|
||||
switch(pinConfig[pin]) {
|
||||
case SERVO:
|
||||
if (IS_PIN_SERVO(pin))
|
||||
servos[PIN_TO_SERVO(pin)].write(value);
|
||||
switch (pinConfig[pin]) {
|
||||
case SERVO:
|
||||
if (IS_PIN_SERVO(pin))
|
||||
servos[PIN_TO_SERVO(pin)].write(value);
|
||||
pinState[pin] = value;
|
||||
break;
|
||||
case PWM:
|
||||
if (IS_PIN_PWM(pin))
|
||||
analogWrite(PIN_TO_PWM(pin), value);
|
||||
break;
|
||||
case PWM:
|
||||
if (IS_PIN_PWM(pin))
|
||||
analogWrite(PIN_TO_PWM(pin), value);
|
||||
pinState[pin] = value;
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void digitalWriteCallback(byte port, int value)
|
||||
{
|
||||
byte pin, lastPin, mask=1, pinWriteMask=0;
|
||||
byte pin, lastPin, mask = 1, pinWriteMask = 0;
|
||||
|
||||
if (port < TOTAL_PORTS) {
|
||||
// create a mask of the pins on this port that are writable.
|
||||
lastPin = port*8+8;
|
||||
lastPin = port * 8 + 8;
|
||||
if (lastPin > TOTAL_PINS) lastPin = TOTAL_PINS;
|
||||
for (pin=port*8; pin < lastPin; pin++) {
|
||||
for (pin = port * 8; pin < lastPin; pin++) {
|
||||
// do not disturb non-digital pins (eg, Rx & Tx)
|
||||
if (IS_PIN_DIGITAL(pin)) {
|
||||
// only write to OUTPUT and INPUT (enables pullup)
|
||||
@ -299,7 +299,7 @@ void digitalWriteCallback(byte port, int value)
|
||||
void reportAnalogCallback(byte analogPin, int value)
|
||||
{
|
||||
if (analogPin < TOTAL_ANALOG_PINS) {
|
||||
if(value == 0) {
|
||||
if (value == 0) {
|
||||
analogInputsToReport = analogInputsToReport &~ (1 << analogPin);
|
||||
} else {
|
||||
analogInputsToReport = analogInputsToReport | (1 << analogPin);
|
||||
@ -331,214 +331,214 @@ void sysexCallback(byte command, byte argc, byte *argv)
|
||||
byte slaveAddress;
|
||||
byte slaveRegister;
|
||||
byte data;
|
||||
unsigned int delayTime;
|
||||
|
||||
switch(command) {
|
||||
case I2C_REQUEST:
|
||||
mode = argv[1] & I2C_READ_WRITE_MODE_MASK;
|
||||
if (argv[1] & I2C_10BIT_ADDRESS_MODE_MASK) {
|
||||
Firmata.sendString("10-bit addressing mode is not yet supported");
|
||||
return;
|
||||
}
|
||||
else {
|
||||
slaveAddress = argv[0];
|
||||
}
|
||||
unsigned int delayTime;
|
||||
|
||||
switch(mode) {
|
||||
case I2C_WRITE:
|
||||
Wire.beginTransmission(slaveAddress);
|
||||
for (byte i = 2; i < argc; i += 2) {
|
||||
data = argv[i] + (argv[i + 1] << 7);
|
||||
#if ARDUINO >= 100
|
||||
Wire.write(data);
|
||||
#else
|
||||
Wire.send(data);
|
||||
#endif
|
||||
}
|
||||
Wire.endTransmission();
|
||||
delayMicroseconds(70);
|
||||
break;
|
||||
case I2C_READ:
|
||||
if (argc == 6) {
|
||||
// a slave register is specified
|
||||
slaveRegister = argv[2] + (argv[3] << 7);
|
||||
data = argv[4] + (argv[5] << 7); // bytes to read
|
||||
readAndReportData(slaveAddress, (int)slaveRegister, data);
|
||||
switch (command) {
|
||||
case I2C_REQUEST:
|
||||
mode = argv[1] & I2C_READ_WRITE_MODE_MASK;
|
||||
if (argv[1] & I2C_10BIT_ADDRESS_MODE_MASK) {
|
||||
Firmata.sendString("10-bit addressing mode is not yet supported");
|
||||
return;
|
||||
}
|
||||
else {
|
||||
// a slave register is NOT specified
|
||||
data = argv[2] + (argv[3] << 7); // bytes to read
|
||||
readAndReportData(slaveAddress, (int)REGISTER_NOT_SPECIFIED, data);
|
||||
slaveAddress = argv[0];
|
||||
}
|
||||
break;
|
||||
case I2C_READ_CONTINUOUSLY:
|
||||
if ((queryIndex + 1) >= MAX_QUERIES) {
|
||||
// too many queries, just ignore
|
||||
Firmata.sendString("too many queries");
|
||||
break;
|
||||
}
|
||||
queryIndex++;
|
||||
query[queryIndex].addr = slaveAddress;
|
||||
query[queryIndex].reg = argv[2] + (argv[3] << 7);
|
||||
query[queryIndex].bytes = argv[4] + (argv[5] << 7);
|
||||
break;
|
||||
case I2C_STOP_READING:
|
||||
byte queryIndexToSkip;
|
||||
// if read continuous mode is enabled for only 1 i2c device, disable
|
||||
// read continuous reporting for that device
|
||||
if (queryIndex <= 0) {
|
||||
queryIndex = -1;
|
||||
} else {
|
||||
// if read continuous mode is enabled for multiple devices,
|
||||
// determine which device to stop reading and remove it's data from
|
||||
// the array, shifiting other array data to fill the space
|
||||
for (byte i = 0; i < queryIndex + 1; i++) {
|
||||
if (query[i].addr = slaveAddress) {
|
||||
queryIndexToSkip = i;
|
||||
|
||||
switch (mode) {
|
||||
case I2C_WRITE:
|
||||
Wire.beginTransmission(slaveAddress);
|
||||
for (byte i = 2; i < argc; i += 2) {
|
||||
data = argv[i] + (argv[i + 1] << 7);
|
||||
#if ARDUINO >= 100
|
||||
Wire.write(data);
|
||||
#else
|
||||
Wire.send(data);
|
||||
#endif
|
||||
}
|
||||
Wire.endTransmission();
|
||||
delayMicroseconds(70);
|
||||
break;
|
||||
case I2C_READ:
|
||||
if (argc == 6) {
|
||||
// a slave register is specified
|
||||
slaveRegister = argv[2] + (argv[3] << 7);
|
||||
data = argv[4] + (argv[5] << 7); // bytes to read
|
||||
readAndReportData(slaveAddress, (int)slaveRegister, data);
|
||||
}
|
||||
else {
|
||||
// a slave register is NOT specified
|
||||
data = argv[2] + (argv[3] << 7); // bytes to read
|
||||
readAndReportData(slaveAddress, (int)REGISTER_NOT_SPECIFIED, data);
|
||||
}
|
||||
break;
|
||||
case I2C_READ_CONTINUOUSLY:
|
||||
if ((queryIndex + 1) >= MAX_QUERIES) {
|
||||
// too many queries, just ignore
|
||||
Firmata.sendString("too many queries");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (byte i = queryIndexToSkip; i<queryIndex + 1; i++) {
|
||||
if (i < MAX_QUERIES) {
|
||||
query[i].addr = query[i+1].addr;
|
||||
query[i].reg = query[i+1].addr;
|
||||
query[i].bytes = query[i+1].bytes;
|
||||
queryIndex++;
|
||||
query[queryIndex].addr = slaveAddress;
|
||||
query[queryIndex].reg = argv[2] + (argv[3] << 7);
|
||||
query[queryIndex].bytes = argv[4] + (argv[5] << 7);
|
||||
break;
|
||||
case I2C_STOP_READING:
|
||||
byte queryIndexToSkip;
|
||||
// if read continuous mode is enabled for only 1 i2c device, disable
|
||||
// read continuous reporting for that device
|
||||
if (queryIndex <= 0) {
|
||||
queryIndex = -1;
|
||||
} else {
|
||||
// if read continuous mode is enabled for multiple devices,
|
||||
// determine which device to stop reading and remove it's data from
|
||||
// the array, shifiting other array data to fill the space
|
||||
for (byte i = 0; i < queryIndex + 1; i++) {
|
||||
if (query[i].addr = slaveAddress) {
|
||||
queryIndexToSkip = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (byte i = queryIndexToSkip; i < queryIndex + 1; i++) {
|
||||
if (i < MAX_QUERIES) {
|
||||
query[i].addr = query[i + 1].addr;
|
||||
query[i].reg = query[i + 1].addr;
|
||||
query[i].bytes = query[i + 1].bytes;
|
||||
}
|
||||
}
|
||||
queryIndex--;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case I2C_CONFIG:
|
||||
delayTime = (argv[0] + (argv[1] << 7));
|
||||
|
||||
if (delayTime > 0) {
|
||||
i2cReadDelayTime = delayTime;
|
||||
}
|
||||
|
||||
if (!isI2CEnabled) {
|
||||
enableI2CPins();
|
||||
}
|
||||
|
||||
break;
|
||||
case SERVO_CONFIG:
|
||||
if (argc > 4) {
|
||||
// these vars are here for clarity, they'll optimized away by the compiler
|
||||
byte pin = argv[0];
|
||||
int minPulse = argv[1] + (argv[2] << 7);
|
||||
int maxPulse = argv[3] + (argv[4] << 7);
|
||||
|
||||
if (IS_PIN_SERVO(pin)) {
|
||||
if (servos[PIN_TO_SERVO(pin)].attached())
|
||||
servos[PIN_TO_SERVO(pin)].detach();
|
||||
servos[PIN_TO_SERVO(pin)].attach(PIN_TO_DIGITAL(pin), minPulse, maxPulse);
|
||||
setPinModeCallback(pin, SERVO);
|
||||
}
|
||||
queryIndex--;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
case SAMPLING_INTERVAL:
|
||||
if (argc > 1) {
|
||||
samplingInterval = argv[0] + (argv[1] << 7);
|
||||
if (samplingInterval < MINIMUM_SAMPLING_INTERVAL) {
|
||||
samplingInterval = MINIMUM_SAMPLING_INTERVAL;
|
||||
}
|
||||
} else {
|
||||
//Firmata.sendString("Not enough data");
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case I2C_CONFIG:
|
||||
delayTime = (argv[0] + (argv[1] << 7));
|
||||
|
||||
if(delayTime > 0) {
|
||||
i2cReadDelayTime = delayTime;
|
||||
}
|
||||
|
||||
if (!isI2CEnabled) {
|
||||
enableI2CPins();
|
||||
}
|
||||
|
||||
break;
|
||||
case SERVO_CONFIG:
|
||||
if(argc > 4) {
|
||||
// these vars are here for clarity, they'll optimized away by the compiler
|
||||
byte pin = argv[0];
|
||||
int minPulse = argv[1] + (argv[2] << 7);
|
||||
int maxPulse = argv[3] + (argv[4] << 7);
|
||||
|
||||
if (IS_PIN_SERVO(pin)) {
|
||||
if (servos[PIN_TO_SERVO(pin)].attached())
|
||||
servos[PIN_TO_SERVO(pin)].detach();
|
||||
servos[PIN_TO_SERVO(pin)].attach(PIN_TO_DIGITAL(pin), minPulse, maxPulse);
|
||||
setPinModeCallback(pin, SERVO);
|
||||
case EXTENDED_ANALOG:
|
||||
if (argc > 1) {
|
||||
int val = argv[1];
|
||||
if (argc > 2) val |= (argv[2] << 7);
|
||||
if (argc > 3) val |= (argv[3] << 14);
|
||||
analogWriteCallback(argv[0], val);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SAMPLING_INTERVAL:
|
||||
if (argc > 1) {
|
||||
samplingInterval = argv[0] + (argv[1] << 7);
|
||||
if (samplingInterval < MINIMUM_SAMPLING_INTERVAL) {
|
||||
samplingInterval = MINIMUM_SAMPLING_INTERVAL;
|
||||
}
|
||||
} else {
|
||||
//Firmata.sendString("Not enough data");
|
||||
}
|
||||
break;
|
||||
case EXTENDED_ANALOG:
|
||||
if (argc > 1) {
|
||||
int val = argv[1];
|
||||
if (argc > 2) val |= (argv[2] << 7);
|
||||
if (argc > 3) val |= (argv[3] << 14);
|
||||
analogWriteCallback(argv[0], val);
|
||||
}
|
||||
break;
|
||||
case CAPABILITY_QUERY:
|
||||
Firmata.write(START_SYSEX);
|
||||
Firmata.write(CAPABILITY_RESPONSE);
|
||||
for (byte pin=0; pin < TOTAL_PINS; pin++) {
|
||||
if (IS_PIN_DIGITAL(pin)) {
|
||||
Firmata.write((byte)INPUT);
|
||||
Firmata.write(1);
|
||||
Firmata.write((byte)OUTPUT);
|
||||
Firmata.write(1);
|
||||
}
|
||||
if (IS_PIN_ANALOG(pin)) {
|
||||
Firmata.write(ANALOG);
|
||||
Firmata.write(10);
|
||||
}
|
||||
if (IS_PIN_PWM(pin)) {
|
||||
Firmata.write(PWM);
|
||||
Firmata.write(8);
|
||||
}
|
||||
if (IS_PIN_SERVO(pin)) {
|
||||
Firmata.write(SERVO);
|
||||
Firmata.write(14);
|
||||
}
|
||||
if (IS_PIN_I2C(pin)) {
|
||||
Firmata.write(I2C);
|
||||
Firmata.write(1); // to do: determine appropriate value
|
||||
}
|
||||
Firmata.write(127);
|
||||
}
|
||||
Firmata.write(END_SYSEX);
|
||||
break;
|
||||
case PIN_STATE_QUERY:
|
||||
if (argc > 0) {
|
||||
byte pin=argv[0];
|
||||
break;
|
||||
case CAPABILITY_QUERY:
|
||||
Firmata.write(START_SYSEX);
|
||||
Firmata.write(PIN_STATE_RESPONSE);
|
||||
Firmata.write(pin);
|
||||
if (pin < TOTAL_PINS) {
|
||||
Firmata.write((byte)pinConfig[pin]);
|
||||
Firmata.write((byte)pinState[pin] & 0x7F);
|
||||
if (pinState[pin] & 0xFF80) Firmata.write((byte)(pinState[pin] >> 7) & 0x7F);
|
||||
if (pinState[pin] & 0xC000) Firmata.write((byte)(pinState[pin] >> 14) & 0x7F);
|
||||
Firmata.write(CAPABILITY_RESPONSE);
|
||||
for (byte pin = 0; pin < TOTAL_PINS; pin++) {
|
||||
if (IS_PIN_DIGITAL(pin)) {
|
||||
Firmata.write((byte)INPUT);
|
||||
Firmata.write(1);
|
||||
Firmata.write((byte)OUTPUT);
|
||||
Firmata.write(1);
|
||||
}
|
||||
if (IS_PIN_ANALOG(pin)) {
|
||||
Firmata.write(ANALOG);
|
||||
Firmata.write(10);
|
||||
}
|
||||
if (IS_PIN_PWM(pin)) {
|
||||
Firmata.write(PWM);
|
||||
Firmata.write(8);
|
||||
}
|
||||
if (IS_PIN_SERVO(pin)) {
|
||||
Firmata.write(SERVO);
|
||||
Firmata.write(14);
|
||||
}
|
||||
if (IS_PIN_I2C(pin)) {
|
||||
Firmata.write(I2C);
|
||||
Firmata.write(1); // to do: determine appropriate value
|
||||
}
|
||||
Firmata.write(127);
|
||||
}
|
||||
Firmata.write(END_SYSEX);
|
||||
}
|
||||
break;
|
||||
case ANALOG_MAPPING_QUERY:
|
||||
Firmata.write(START_SYSEX);
|
||||
Firmata.write(ANALOG_MAPPING_RESPONSE);
|
||||
for (byte pin=0; pin < TOTAL_PINS; pin++) {
|
||||
Firmata.write(IS_PIN_ANALOG(pin) ? PIN_TO_ANALOG(pin) : 127);
|
||||
}
|
||||
Firmata.write(END_SYSEX);
|
||||
break;
|
||||
break;
|
||||
case PIN_STATE_QUERY:
|
||||
if (argc > 0) {
|
||||
byte pin = argv[0];
|
||||
Firmata.write(START_SYSEX);
|
||||
Firmata.write(PIN_STATE_RESPONSE);
|
||||
Firmata.write(pin);
|
||||
if (pin < TOTAL_PINS) {
|
||||
Firmata.write((byte)pinConfig[pin]);
|
||||
Firmata.write((byte)pinState[pin] & 0x7F);
|
||||
if (pinState[pin] & 0xFF80) Firmata.write((byte)(pinState[pin] >> 7) & 0x7F);
|
||||
if (pinState[pin] & 0xC000) Firmata.write((byte)(pinState[pin] >> 14) & 0x7F);
|
||||
}
|
||||
Firmata.write(END_SYSEX);
|
||||
}
|
||||
break;
|
||||
case ANALOG_MAPPING_QUERY:
|
||||
Firmata.write(START_SYSEX);
|
||||
Firmata.write(ANALOG_MAPPING_RESPONSE);
|
||||
for (byte pin = 0; pin < TOTAL_PINS; pin++) {
|
||||
Firmata.write(IS_PIN_ANALOG(pin) ? PIN_TO_ANALOG(pin) : 127);
|
||||
}
|
||||
Firmata.write(END_SYSEX);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void enableI2CPins()
|
||||
{
|
||||
byte i;
|
||||
// is there a faster way to do this? would probaby require importing
|
||||
// is there a faster way to do this? would probaby require importing
|
||||
// Arduino.h to get SCL and SDA pins
|
||||
for (i=0; i < TOTAL_PINS; i++) {
|
||||
if(IS_PIN_I2C(i)) {
|
||||
for (i = 0; i < TOTAL_PINS; i++) {
|
||||
if (IS_PIN_I2C(i)) {
|
||||
// mark pins as i2c so they are ignore in non i2c data requests
|
||||
setPinModeCallback(i, I2C);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
isI2CEnabled = true;
|
||||
|
||||
|
||||
isI2CEnabled = true;
|
||||
|
||||
// is there enough time before the first I2C request to call this here?
|
||||
Wire.begin();
|
||||
}
|
||||
|
||||
/* disable the i2c pins so they can be used for other functions */
|
||||
void disableI2CPins() {
|
||||
isI2CEnabled = false;
|
||||
// disable read continuous mode for all devices
|
||||
queryIndex = -1;
|
||||
// uncomment the following if or when the end() method is added to Wire library
|
||||
// Wire.end();
|
||||
isI2CEnabled = false;
|
||||
// disable read continuous mode for all devices
|
||||
queryIndex = -1;
|
||||
// uncomment the following if or when the end() method is added to Wire library
|
||||
// Wire.end();
|
||||
}
|
||||
|
||||
/*==============================================================================
|
||||
@ -550,16 +550,16 @@ void systemResetCallback()
|
||||
// initialize a defalt state
|
||||
// TODO: option to load config from EEPROM instead of default
|
||||
if (isI2CEnabled) {
|
||||
disableI2CPins();
|
||||
disableI2CPins();
|
||||
}
|
||||
for (byte i=0; i < TOTAL_PORTS; i++) {
|
||||
for (byte i = 0; i < TOTAL_PORTS; i++) {
|
||||
reportPINs[i] = false; // by default, reporting off
|
||||
portConfigInputs[i] = 0; // until activated
|
||||
previousPINs[i] = 0;
|
||||
}
|
||||
// pins with analog capability default to analog input
|
||||
// otherwise, pins default to digital output
|
||||
for (byte i=0; i < TOTAL_PINS; i++) {
|
||||
for (byte i = 0; i < TOTAL_PINS; i++) {
|
||||
if (IS_PIN_ANALOG(i)) {
|
||||
// turns off pullup, configures everything
|
||||
setPinModeCallback(i, ANALOG);
|
||||
@ -582,7 +582,7 @@ void systemResetCallback()
|
||||
*/
|
||||
}
|
||||
|
||||
void setup()
|
||||
void setup()
|
||||
{
|
||||
Firmata.setFirmwareVersion(FIRMATA_MAJOR_VERSION, FIRMATA_MINOR_VERSION);
|
||||
|
||||
@ -601,17 +601,17 @@ void setup()
|
||||
/*==============================================================================
|
||||
* LOOP()
|
||||
*============================================================================*/
|
||||
void loop()
|
||||
void loop()
|
||||
{
|
||||
byte pin, analogPin;
|
||||
|
||||
/* DIGITALREAD - as fast as possible, check for changes and output them to the
|
||||
* FTDI buffer using Serial.print() */
|
||||
checkDigitalInputs();
|
||||
checkDigitalInputs();
|
||||
|
||||
/* SERIALREAD - processing incoming messagse as soon as possible, while still
|
||||
* checking digital inputs. */
|
||||
while(Firmata.available())
|
||||
while (Firmata.available())
|
||||
Firmata.processInput();
|
||||
|
||||
/* SEND FTDI WRITE BUFFER - make sure that the FTDI buffer doesn't go over
|
||||
@ -622,7 +622,7 @@ void loop()
|
||||
if (currentMillis - previousMillis > samplingInterval) {
|
||||
previousMillis += samplingInterval;
|
||||
/* ANALOGREAD - do all analogReads() at the configured sampling interval */
|
||||
for(pin=0; pin<TOTAL_PINS; pin++) {
|
||||
for (pin = 0; pin < TOTAL_PINS; pin++) {
|
||||
if (IS_PIN_ANALOG(pin) && pinConfig[pin] == ANALOG) {
|
||||
analogPin = PIN_TO_ANALOG(pin);
|
||||
if (analogInputsToReport & (1 << analogPin)) {
|
||||
|
@ -1,26 +1,26 @@
|
||||
/*
|
||||
GSM Pachube client
|
||||
|
||||
|
||||
This sketch connects an analog sensor to Pachube (http://www.pachube.com)
|
||||
using a Telefonica GSM/GPRS shield.
|
||||
|
||||
This example has been updated to use version 2.0 of the Pachube.com API.
|
||||
This example has been updated to use version 2.0 of the Pachube.com API.
|
||||
To make it work, create a feed with a datastream, and give it the ID
|
||||
sensor1. Or change the code below to match your feed.
|
||||
|
||||
|
||||
Circuit:
|
||||
* Analog sensor attached to analog in 0
|
||||
* GSM shield attached to an Arduino
|
||||
* SIM card with a data plan
|
||||
|
||||
|
||||
created 4 March 2012
|
||||
by Tom Igoe
|
||||
and adapted for GSM shield by David Del Peral
|
||||
|
||||
|
||||
This code is in the public domain.
|
||||
|
||||
|
||||
http://arduino.cc/en/Tutorial/GSMExamplesPachubeClient
|
||||
|
||||
|
||||
*/
|
||||
|
||||
// libraries
|
||||
@ -51,7 +51,7 @@ char server[] = "api.pachube.com"; // name address for pachube API
|
||||
|
||||
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
|
||||
boolean lastConnected = false; // state of the connection last time through the main loop
|
||||
const unsigned long postingInterval = 10*1000; //delay between updates to Pachube.com
|
||||
const unsigned long postingInterval = 10 * 1000; //delay between updates to Pachube.com
|
||||
|
||||
void setup()
|
||||
{
|
||||
@ -60,16 +60,16 @@ void setup()
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
|
||||
// connection state
|
||||
boolean notConnected = true;
|
||||
|
||||
|
||||
// After starting the modem with GSM.begin()
|
||||
// attach the shield to the GPRS network with the APN, login and password
|
||||
while(notConnected)
|
||||
while (notConnected)
|
||||
{
|
||||
if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
|
||||
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
|
||||
if ((gsmAccess.begin(PINNUMBER) == GSM_READY) &
|
||||
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY))
|
||||
notConnected = false;
|
||||
else
|
||||
{
|
||||
@ -80,17 +80,17 @@ void setup()
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
{
|
||||
// read the analog sensor:
|
||||
int sensorReading = analogRead(A0);
|
||||
int sensorReading = analogRead(A0);
|
||||
|
||||
// if there's incoming data from the net connection.
|
||||
// send it out the serial port. This is for debugging
|
||||
// purposes only:
|
||||
if (client.available())
|
||||
{
|
||||
char c = client.read();
|
||||
Serial.print(c);
|
||||
char c = client.read();
|
||||
Serial.print(c);
|
||||
}
|
||||
|
||||
// if there's no net connection, but there was one last time
|
||||
@ -99,14 +99,14 @@ void loop()
|
||||
{
|
||||
client.stop();
|
||||
}
|
||||
|
||||
|
||||
// if you're not connected, and ten seconds have passed since
|
||||
// your last connection, then connect again and send data:
|
||||
if(!client.connected() && ((millis() - lastConnectionTime) > postingInterval))
|
||||
if (!client.connected() && ((millis() - lastConnectionTime) > postingInterval))
|
||||
{
|
||||
sendData(sensorReading);
|
||||
sendData(sensorReading);
|
||||
}
|
||||
|
||||
|
||||
// store the state of the connection for next time through
|
||||
// the loop:
|
||||
lastConnected = client.connected();
|
||||
@ -121,7 +121,7 @@ void sendData(int thisData)
|
||||
if (client.connect(server, 80))
|
||||
{
|
||||
Serial.println("connecting...");
|
||||
|
||||
|
||||
// send the HTTP PUT request:
|
||||
client.print("PUT /v2/feeds/");
|
||||
client.print(FEEDID);
|
||||
@ -142,11 +142,11 @@ void sendData(int thisData)
|
||||
client.println("Content-Type: text/csv");
|
||||
client.println("Connection: close");
|
||||
client.println();
|
||||
|
||||
|
||||
// here's the actual content of the PUT request:
|
||||
client.print("sensor1,");
|
||||
client.println(thisData);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// if you couldn't make a connection:
|
||||
@ -169,17 +169,17 @@ int getLength(int someValue)
|
||||
{
|
||||
// there's at least one byte:
|
||||
int digits = 1;
|
||||
|
||||
// continually divide the value by ten,
|
||||
|
||||
// continually divide the value by ten,
|
||||
// adding one to the digit count for each
|
||||
// time you divide, until you're at 0:
|
||||
int dividend = someValue /10;
|
||||
int dividend = someValue / 10;
|
||||
while (dividend > 0)
|
||||
{
|
||||
dividend = dividend /10;
|
||||
dividend = dividend / 10;
|
||||
digits++;
|
||||
}
|
||||
|
||||
|
||||
// return the number of digits:
|
||||
return digits;
|
||||
}
|
||||
|
@ -1,27 +1,27 @@
|
||||
/*
|
||||
Pachube client with Strings
|
||||
|
||||
|
||||
This sketch connects two analog sensors to Pachube (http://www.pachube.com)
|
||||
through a Telefonica GSM/GPRS shield.
|
||||
|
||||
This example has been updated to use version 2.0 of the Pachube.com API.
|
||||
|
||||
This example has been updated to use version 2.0 of the Pachube.com API.
|
||||
To make it work, create a feed with two datastreams, and give them the IDs
|
||||
sensor1 and sensor2. Or change the code below to match your feed.
|
||||
|
||||
|
||||
This example uses the String library, which is part of the Arduino core from
|
||||
version 0019.
|
||||
|
||||
version 0019.
|
||||
|
||||
Circuit:
|
||||
* Analog sensors attached to A0 and A1
|
||||
* GSM shield attached to an Arduino
|
||||
* SIM card with a data plan
|
||||
|
||||
|
||||
created 8 March 2012
|
||||
by Tom Igoe
|
||||
and adapted for GSM shield by David Del Peral
|
||||
|
||||
|
||||
This code is in the public domain.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
// Include the GSM library
|
||||
@ -52,7 +52,7 @@ char server[] = "api.pachube.com"; // name address for Pachube API
|
||||
|
||||
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
|
||||
boolean lastConnected = false; // state of the connection last time through the main loop
|
||||
const unsigned long postingInterval = 10*1000; // delay between updates to Pachube.com
|
||||
const unsigned long postingInterval = 10 * 1000; // delay between updates to Pachube.com
|
||||
|
||||
void setup()
|
||||
{
|
||||
@ -61,16 +61,16 @@ void setup()
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
|
||||
// connection state
|
||||
boolean notConnected = true;
|
||||
|
||||
|
||||
// After starting the modem with GSM.begin()
|
||||
// attach the shield to the GPRS network with the APN, login and password
|
||||
while(notConnected)
|
||||
// attach the shield to the GPRS network with the APN, login and password
|
||||
while (notConnected)
|
||||
{
|
||||
if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
|
||||
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
|
||||
if ((gsmAccess.begin(PINNUMBER) == GSM_READY) &
|
||||
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY))
|
||||
notConnected = false;
|
||||
else
|
||||
{
|
||||
@ -85,13 +85,13 @@ void setup()
|
||||
void loop()
|
||||
{
|
||||
// read the sensor on A0
|
||||
int sensorReading = analogRead(A0);
|
||||
|
||||
int sensorReading = analogRead(A0);
|
||||
|
||||
// convert the data to a String
|
||||
String dataString = "sensor1,";
|
||||
dataString += sensorReading;
|
||||
|
||||
// you can append multiple readings to this String to
|
||||
// you can append multiple readings to this String to
|
||||
// send the pachube feed multiple values
|
||||
int otherSensorReading = analogRead(A1);
|
||||
dataString += "\nsensor2,";
|
||||
@ -117,7 +117,7 @@ void loop()
|
||||
|
||||
// if you're not connected, and ten seconds have passed since
|
||||
// your last connection, then connect again and send data
|
||||
if(!client.connected() && (millis() - lastConnectionTime > postingInterval))
|
||||
if (!client.connected() && (millis() - lastConnectionTime > postingInterval))
|
||||
{
|
||||
sendData(dataString);
|
||||
}
|
||||
@ -133,7 +133,7 @@ void sendData(String thisData)
|
||||
if (client.connect(server, 80))
|
||||
{
|
||||
Serial.println("connecting...");
|
||||
|
||||
|
||||
// send the HTTP PUT request:
|
||||
client.print("PUT /v2/feeds/");
|
||||
client.print(FEEDID);
|
||||
@ -150,10 +150,10 @@ void sendData(String thisData)
|
||||
client.println("Content-Type: text/csv");
|
||||
client.println("Connection: close");
|
||||
client.println();
|
||||
|
||||
|
||||
// here's the actual content of the PUT request
|
||||
client.println(thisData);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// if you couldn't make a connection
|
||||
|
@ -1,19 +1,19 @@
|
||||
/*
|
||||
Web client
|
||||
|
||||
|
||||
This sketch connects to a website through a GSM shield. Specifically,
|
||||
this example downloads the URL "http://arduino.cc/asciilogo.txt" and
|
||||
this example downloads the URL "http://arduino.cc/asciilogo.txt" and
|
||||
prints it to the Serial monitor.
|
||||
|
||||
|
||||
Circuit:
|
||||
* GSM shield attached to an Arduino
|
||||
* SIM card with a data plan
|
||||
|
||||
|
||||
created 8 Mar 2012
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
http://arduino.cc/en/Tutorial/GSMExamplesWebClient
|
||||
|
||||
|
||||
*/
|
||||
|
||||
// libraries
|
||||
@ -30,7 +30,7 @@
|
||||
// initialize the library instance
|
||||
GSMClient client;
|
||||
GPRS gprs;
|
||||
GSM gsmAccess;
|
||||
GSM gsmAccess;
|
||||
|
||||
// URL, path & port (for example: arduino.cc)
|
||||
char server[] = "arduino.cc";
|
||||
@ -51,10 +51,10 @@ void setup()
|
||||
|
||||
// After starting the modem with GSM.begin()
|
||||
// attach the shield to the GPRS network with the APN, login and password
|
||||
while(notConnected)
|
||||
while (notConnected)
|
||||
{
|
||||
if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
|
||||
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
|
||||
if ((gsmAccess.begin(PINNUMBER) == GSM_READY) &
|
||||
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY))
|
||||
notConnected = false;
|
||||
else
|
||||
{
|
||||
@ -77,7 +77,7 @@ void setup()
|
||||
client.println(server);
|
||||
client.println("Connection: close");
|
||||
client.println();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// if you didn't get a connection to the server:
|
||||
@ -87,7 +87,7 @@ void setup()
|
||||
|
||||
void loop()
|
||||
{
|
||||
// if there are incoming bytes available
|
||||
// if there are incoming bytes available
|
||||
// from the server, read them and print them:
|
||||
if (client.available())
|
||||
{
|
||||
@ -103,7 +103,7 @@ void loop()
|
||||
client.stop();
|
||||
|
||||
// do nothing forevermore:
|
||||
for(;;)
|
||||
for (;;)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
/*
|
||||
GSM Web Server
|
||||
|
||||
|
||||
A simple web server that shows the value of the analog input pins.
|
||||
using a GSM shield.
|
||||
|
||||
Circuit:
|
||||
* GSM shield attached
|
||||
* Analog inputs attached to pins A0 through A5 (optional)
|
||||
|
||||
|
||||
created 8 Mar 2012
|
||||
by Tom Igoe
|
||||
*/
|
||||
@ -30,7 +30,7 @@ GSM gsmAccess; // include a 'true' parameter for debug enabled
|
||||
GSMServer server(80); // port 80 (http default)
|
||||
|
||||
// timeout
|
||||
const unsigned long __TIMEOUT__ = 10*1000;
|
||||
const unsigned long __TIMEOUT__ = 10 * 1000;
|
||||
|
||||
void setup()
|
||||
{
|
||||
@ -39,16 +39,16 @@ void setup()
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
|
||||
// connection state
|
||||
boolean notConnected = true;
|
||||
|
||||
|
||||
// Start GSM shield
|
||||
// If your SIM has PIN, pass it as a parameter of begin() in quotes
|
||||
while(notConnected)
|
||||
while (notConnected)
|
||||
{
|
||||
if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
|
||||
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
|
||||
if ((gsmAccess.begin(PINNUMBER) == GSM_READY) &
|
||||
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY))
|
||||
notConnected = false;
|
||||
else
|
||||
{
|
||||
@ -56,12 +56,12 @@ void setup()
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Serial.println("Connected to GPRS network");
|
||||
|
||||
|
||||
// start server
|
||||
server.begin();
|
||||
|
||||
|
||||
//Get IP.
|
||||
IPAddress LocalIP = gprs.getIPAddress();
|
||||
Serial.println("Server IP address=");
|
||||
@ -77,21 +77,21 @@ void loop() {
|
||||
|
||||
|
||||
if (client)
|
||||
{
|
||||
{
|
||||
while (client.connected())
|
||||
{
|
||||
if (client.available())
|
||||
{
|
||||
Serial.println("Receiving request!");
|
||||
bool sendResponse = false;
|
||||
while(char c=client.read()) {
|
||||
while (char c = client.read()) {
|
||||
if (c == '\n') sendResponse = true;
|
||||
}
|
||||
|
||||
// if you've gotten to the end of the line (received a newline
|
||||
// character)
|
||||
if (sendResponse)
|
||||
{
|
||||
// if you've gotten to the end of the line (received a newline
|
||||
// character)
|
||||
if (sendResponse)
|
||||
{
|
||||
// send a standard http response header
|
||||
client.println("HTTP/1.1 200 OK");
|
||||
client.println("Content-Type: text/html");
|
||||
@ -103,7 +103,7 @@ void loop() {
|
||||
client.print(analogChannel);
|
||||
client.print(" is ");
|
||||
client.print(analogRead(analogChannel));
|
||||
client.println("<br />");
|
||||
client.println("<br />");
|
||||
}
|
||||
client.println("</html>");
|
||||
//necessary delay
|
||||
|
@ -1,21 +1,21 @@
|
||||
/*
|
||||
Make Voice Call
|
||||
|
||||
|
||||
This sketch, for the Arduino GSM shield, puts a voice call to
|
||||
a remote phone number that you enter through the serial monitor.
|
||||
To make it work, open the serial monitor, and when you see the
|
||||
READY message, type a phone number. Make sure the serial monitor
|
||||
To make it work, open the serial monitor, and when you see the
|
||||
READY message, type a phone number. Make sure the serial monitor
|
||||
is set to send a just newline when you press return.
|
||||
|
||||
|
||||
Circuit:
|
||||
* GSM shield
|
||||
* Voice circuit.
|
||||
* GSM shield
|
||||
* Voice circuit.
|
||||
With no voice circuit the call will send nor receive any sound
|
||||
|
||||
|
||||
|
||||
|
||||
created Mar 2012
|
||||
by Javier Zorzano
|
||||
|
||||
|
||||
This example is in the public domain.
|
||||
*/
|
||||
|
||||
@ -42,15 +42,15 @@ void setup()
|
||||
}
|
||||
|
||||
Serial.println("Make Voice Call");
|
||||
|
||||
|
||||
// connection state
|
||||
boolean notConnected = true;
|
||||
|
||||
|
||||
// Start GSM shield
|
||||
// If your SIM has PIN, pass it as a parameter of begin() in quotes
|
||||
while(notConnected)
|
||||
while (notConnected)
|
||||
{
|
||||
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
|
||||
if (gsmAccess.begin(PINNUMBER) == GSM_READY)
|
||||
notConnected = false;
|
||||
else
|
||||
{
|
||||
@ -58,7 +58,7 @@ void setup()
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Serial.println("GSM initialized.");
|
||||
Serial.println("Enter phone number to call.");
|
||||
|
||||
@ -84,33 +84,33 @@ void loop()
|
||||
|
||||
// Call the remote number
|
||||
remoteNumber.toCharArray(charbuffer, 20);
|
||||
|
||||
|
||||
|
||||
|
||||
// Check if the receiving end has picked up the call
|
||||
if(vcs.voiceCall(charbuffer))
|
||||
if (vcs.voiceCall(charbuffer))
|
||||
{
|
||||
Serial.println("Call Established. Enter line to end");
|
||||
// Wait for some input from the line
|
||||
while(Serial.read()!='\n' && (vcs.getvoiceCallStatus()==TALKING));
|
||||
while (Serial.read() != '\n' && (vcs.getvoiceCallStatus() == TALKING));
|
||||
// And hang up
|
||||
vcs.hangCall();
|
||||
}
|
||||
Serial.println("Call Finished");
|
||||
remoteNumber="";
|
||||
remoteNumber = "";
|
||||
Serial.println("Enter phone number to call.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("That's too long for a phone number. I'm forgetting it");
|
||||
Serial.println("That's too long for a phone number. I'm forgetting it");
|
||||
remoteNumber = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// add the latest character to the message to send:
|
||||
if(inChar!='\r')
|
||||
if (inChar != '\r')
|
||||
remoteNumber += inChar;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,20 +1,20 @@
|
||||
/*
|
||||
SMS receiver
|
||||
|
||||
This sketch, for the Arduino GSM shield, waits for a SMS message
|
||||
and displays it through the Serial port.
|
||||
|
||||
|
||||
This sketch, for the Arduino GSM shield, waits for a SMS message
|
||||
and displays it through the Serial port.
|
||||
|
||||
Circuit:
|
||||
* GSM shield attached to and Arduino
|
||||
* SIM card that can receive SMS messages
|
||||
|
||||
|
||||
created 25 Feb 2012
|
||||
by Javier Zorzano / TD
|
||||
|
||||
|
||||
This example is in the public domain.
|
||||
|
||||
|
||||
http://arduino.cc/en/Tutorial/GSMExamplesReceiveSMS
|
||||
|
||||
|
||||
*/
|
||||
|
||||
// include the GSM library
|
||||
@ -28,25 +28,25 @@ GSM gsmAccess;
|
||||
GSM_SMS sms;
|
||||
|
||||
// Array to hold the number a SMS is retreived from
|
||||
char senderNumber[20];
|
||||
char senderNumber[20];
|
||||
|
||||
void setup()
|
||||
void setup()
|
||||
{
|
||||
// initialize serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
}
|
||||
|
||||
Serial.println("SMS Messages Receiver");
|
||||
|
||||
|
||||
// connection state
|
||||
boolean notConnected = true;
|
||||
|
||||
|
||||
// Start GSM connection
|
||||
while(notConnected)
|
||||
while (notConnected)
|
||||
{
|
||||
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
|
||||
if (gsmAccess.begin(PINNUMBER) == GSM_READY)
|
||||
notConnected = false;
|
||||
else
|
||||
{
|
||||
@ -54,38 +54,38 @@ void setup()
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Serial.println("GSM initialized");
|
||||
Serial.println("Waiting for messages");
|
||||
}
|
||||
|
||||
void loop()
|
||||
void loop()
|
||||
{
|
||||
char c;
|
||||
|
||||
// If there are any SMSs available()
|
||||
|
||||
// If there are any SMSs available()
|
||||
if (sms.available())
|
||||
{
|
||||
Serial.println("Message received from:");
|
||||
|
||||
|
||||
// Get remote number
|
||||
sms.remoteNumber(senderNumber, 20);
|
||||
Serial.println(senderNumber);
|
||||
|
||||
// An example of message disposal
|
||||
// An example of message disposal
|
||||
// Any messages starting with # should be discarded
|
||||
if(sms.peek()=='#')
|
||||
if (sms.peek() == '#')
|
||||
{
|
||||
Serial.println("Discarded SMS");
|
||||
sms.flush();
|
||||
}
|
||||
|
||||
|
||||
// Read message bytes and print them
|
||||
while(c=sms.read())
|
||||
while (c = sms.read())
|
||||
Serial.print(c);
|
||||
|
||||
|
||||
Serial.println("\nEND OF MESSAGE");
|
||||
|
||||
|
||||
// Delete message from modem memory
|
||||
sms.flush();
|
||||
Serial.println("MESSAGE DELETED");
|
||||
|
@ -1,24 +1,24 @@
|
||||
/*
|
||||
Receive Voice Call
|
||||
|
||||
This sketch, for the Arduino GSM shield, receives voice calls,
|
||||
|
||||
This sketch, for the Arduino GSM shield, receives voice calls,
|
||||
displays the calling number, waits a few seconds then hangs up.
|
||||
|
||||
|
||||
Circuit:
|
||||
* GSM shield
|
||||
* GSM shield
|
||||
* Voice circuit. Refer to to the GSM shield getting started guide
|
||||
at http://arduino.cc/en/Guide/ArduinoGSMShield#toc11
|
||||
* SIM card that can accept voice calls
|
||||
|
||||
|
||||
With no voice circuit the call will connect, but will not send or receive sound
|
||||
|
||||
|
||||
created Mar 2012
|
||||
by Javier Zorzano
|
||||
|
||||
|
||||
This example is in the public domain.
|
||||
|
||||
|
||||
http://arduino.cc/en/Tutorial/GSMExamplesReceiveVoiceCall
|
||||
|
||||
|
||||
*/
|
||||
|
||||
// Include the GSM library
|
||||
@ -32,7 +32,7 @@ GSM gsmAccess;
|
||||
GSMVoiceCall vcs;
|
||||
|
||||
// Array to hold the number for the incoming call
|
||||
char numtel[20];
|
||||
char numtel[20];
|
||||
|
||||
void setup()
|
||||
{
|
||||
@ -43,15 +43,15 @@ void setup()
|
||||
}
|
||||
|
||||
Serial.println("Receive Voice Call");
|
||||
|
||||
|
||||
// connection state
|
||||
boolean notConnected = true;
|
||||
|
||||
|
||||
// Start GSM shield
|
||||
// If your SIM has PIN, pass it as a parameter of begin() in quotes
|
||||
while(notConnected)
|
||||
while (notConnected)
|
||||
{
|
||||
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
|
||||
if (gsmAccess.begin(PINNUMBER) == GSM_READY)
|
||||
notConnected = false;
|
||||
else
|
||||
{
|
||||
@ -59,44 +59,44 @@ void setup()
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// This makes sure the modem correctly reports incoming events
|
||||
vcs.hangCall();
|
||||
|
||||
|
||||
Serial.println("Waiting for a call");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Check the status of the voice call
|
||||
switch (vcs.getvoiceCallStatus())
|
||||
switch (vcs.getvoiceCallStatus())
|
||||
{
|
||||
case IDLE_CALL: // Nothing is happening
|
||||
|
||||
|
||||
break;
|
||||
|
||||
|
||||
case RECEIVINGCALL: // Yes! Someone is calling us
|
||||
|
||||
|
||||
Serial.println("RECEIVING CALL");
|
||||
|
||||
|
||||
// Retrieve the calling number
|
||||
vcs.retrieveCallingNumber(numtel, 20);
|
||||
|
||||
|
||||
// Print the calling number
|
||||
Serial.print("Number:");
|
||||
Serial.println(numtel);
|
||||
|
||||
|
||||
// Answer the call, establish the call
|
||||
vcs.answerCall();
|
||||
vcs.answerCall();
|
||||
break;
|
||||
|
||||
|
||||
case TALKING: // In this case the call would be established
|
||||
|
||||
|
||||
Serial.println("TALKING. Press enter to hang up.");
|
||||
while(Serial.read()!='\n')
|
||||
while (Serial.read() != '\n')
|
||||
delay(100);
|
||||
vcs.hangCall();
|
||||
Serial.println("Hanging up and waiting for the next call.");
|
||||
Serial.println("Hanging up and waiting for the next call.");
|
||||
break;
|
||||
}
|
||||
delay(1000);
|
||||
|
@ -1,24 +1,24 @@
|
||||
/*
|
||||
SMS sender
|
||||
|
||||
This sketch, for the Arduino GSM shield,sends an SMS message
|
||||
you enter in the serial monitor. Connect your Arduino with the
|
||||
GSM shield and SIM card, open the serial monitor, and wait for
|
||||
the "READY" message to appear in the monitor. Next, type a
|
||||
message to send and press "return". Make sure the serial
|
||||
|
||||
This sketch, for the Arduino GSM shield,sends an SMS message
|
||||
you enter in the serial monitor. Connect your Arduino with the
|
||||
GSM shield and SIM card, open the serial monitor, and wait for
|
||||
the "READY" message to appear in the monitor. Next, type a
|
||||
message to send and press "return". Make sure the serial
|
||||
monitor is set to send a newline when you press return.
|
||||
|
||||
|
||||
Circuit:
|
||||
* GSM shield
|
||||
* GSM shield
|
||||
* SIM card that can send SMS
|
||||
|
||||
|
||||
created 25 Feb 2012
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
This example is in the public domain.
|
||||
|
||||
|
||||
http://arduino.cc/en/Tutorial/GSMExamplesSendSMS
|
||||
|
||||
|
||||
*/
|
||||
|
||||
// Include the GSM library
|
||||
@ -37,7 +37,7 @@ void setup()
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
|
||||
Serial.println("SMS Messages Sender");
|
||||
|
||||
// connection state
|
||||
@ -45,9 +45,9 @@ void setup()
|
||||
|
||||
// Start GSM shield
|
||||
// If your SIM has PIN, pass it as a parameter of begin() in quotes
|
||||
while(notConnected)
|
||||
while (notConnected)
|
||||
{
|
||||
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
|
||||
if (gsmAccess.begin(PINNUMBER) == GSM_READY)
|
||||
notConnected = false;
|
||||
else
|
||||
{
|
||||
@ -55,7 +55,7 @@ void setup()
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Serial.println("GSM initialized");
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ void loop()
|
||||
char remoteNum[20]; // telephone number to send sms
|
||||
readSerial(remoteNum);
|
||||
Serial.println(remoteNum);
|
||||
|
||||
|
||||
// sms text
|
||||
Serial.print("Now, enter SMS content: ");
|
||||
char txtMsg[200];
|
||||
@ -75,11 +75,11 @@ void loop()
|
||||
Serial.println();
|
||||
Serial.println("Message:");
|
||||
Serial.println(txtMsg);
|
||||
|
||||
|
||||
// send the message
|
||||
sms.beginSMS(remoteNum);
|
||||
sms.print(txtMsg);
|
||||
sms.endSMS();
|
||||
sms.endSMS();
|
||||
Serial.println("\nCOMPLETE!\n");
|
||||
}
|
||||
|
||||
@ -89,7 +89,7 @@ void loop()
|
||||
int readSerial(char result[])
|
||||
{
|
||||
int i = 0;
|
||||
while(1)
|
||||
while (1)
|
||||
{
|
||||
while (Serial.available() > 0)
|
||||
{
|
||||
@ -100,7 +100,7 @@ int readSerial(char result[])
|
||||
Serial.flush();
|
||||
return 0;
|
||||
}
|
||||
if(inChar!='\r')
|
||||
if (inChar != '\r')
|
||||
{
|
||||
result[i] = inChar;
|
||||
i++;
|
||||
|
@ -1,24 +1,24 @@
|
||||
/*
|
||||
Band Management
|
||||
|
||||
|
||||
This sketch, for the Arduino GSM shield, checks the band
|
||||
currently configured in the modem and allows you to change
|
||||
currently configured in the modem and allows you to change
|
||||
it.
|
||||
|
||||
|
||||
Please check http://www.worldtimezone.com/gsm.html
|
||||
Usual configurations:
|
||||
Europe, Africa, Middle East: E-GSM(900)+DCS(1800)
|
||||
USA, Canada, South America: GSM(850)+PCS(1900)
|
||||
Mexico: PCS(1900)
|
||||
Brazil: GSM(850)+E-GSM(900)+DCS(1800)+PCS(1900)
|
||||
|
||||
|
||||
|
||||
|
||||
Circuit:
|
||||
* GSM shield
|
||||
|
||||
* GSM shield
|
||||
|
||||
created 12 June 2012
|
||||
by Javier Zorzano, Scott Fitzgerald
|
||||
|
||||
|
||||
This example is in the public domain.
|
||||
*/
|
||||
|
||||
@ -35,18 +35,18 @@ void setup()
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
|
||||
// Beginning the band manager restarts the modem
|
||||
Serial.println("Restarting modem...");
|
||||
band.begin();
|
||||
Serial.println("Modem restarted.");
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Get current band
|
||||
// Get current band
|
||||
String bandName = band.getBand(); // Get and print band name
|
||||
Serial.print("Current band:");
|
||||
Serial.println(bandName);
|
||||
@ -54,25 +54,25 @@ void loop()
|
||||
String newBandName;
|
||||
newBandName = askUser();
|
||||
// Tell the user what we are about to do…
|
||||
Serial.print("\nConfiguring band ");
|
||||
Serial.println(newBandName);
|
||||
// Change the band
|
||||
boolean operationSuccess;
|
||||
operationSuccess = band.setBand(newBandName);
|
||||
// Tell the user if the operation was OK
|
||||
if(operationSuccess)
|
||||
{
|
||||
Serial.print("\nConfiguring band ");
|
||||
Serial.println(newBandName);
|
||||
// Change the band
|
||||
boolean operationSuccess;
|
||||
operationSuccess = band.setBand(newBandName);
|
||||
// Tell the user if the operation was OK
|
||||
if (operationSuccess)
|
||||
{
|
||||
Serial.println("Success");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
Serial.println("Error while changing band");
|
||||
}
|
||||
|
||||
if(operationSuccess)
|
||||
{
|
||||
while(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (operationSuccess)
|
||||
{
|
||||
while (true);
|
||||
}
|
||||
}
|
||||
|
||||
// This function offers the user different options
|
||||
@ -80,41 +80,41 @@ void loop()
|
||||
// The user selects one
|
||||
String askUser()
|
||||
{
|
||||
String newBand;
|
||||
Serial.println("Select band:");
|
||||
// Print the different options
|
||||
Serial.println("1 : E-GSM(900)");
|
||||
Serial.println("2 : DCS(1800)");
|
||||
Serial.println("3 : PCS(1900)");
|
||||
Serial.println("4 : E-GSM(900)+DCS(1800) ex: Europe");
|
||||
Serial.println("5 : GSM(850)+PCS(1900) Ex: USA, South Am.");
|
||||
Serial.println("6 : GSM(850)+E-GSM(900)+DCS(1800)+PCS(1900)");
|
||||
|
||||
// Empty the incoming buffer
|
||||
while(Serial.available())
|
||||
Serial.read();
|
||||
|
||||
// Wait for an answer, just look at the first character
|
||||
while(!Serial.available());
|
||||
char c= Serial.read();
|
||||
if(c=='1')
|
||||
newBand=GSM_MODE_EGSM;
|
||||
else if(c=='2')
|
||||
newBand=GSM_MODE_DCS;
|
||||
else if(c=='3')
|
||||
newBand=GSM_MODE_PCS;
|
||||
else if(c=='4')
|
||||
newBand=GSM_MODE_EGSM_DCS;
|
||||
else if(c=='5')
|
||||
newBand=GSM_MODE_GSM850_PCS;
|
||||
else if(c=='6')
|
||||
newBand=GSM_MODE_GSM850_EGSM_DCS_PCS;
|
||||
String newBand;
|
||||
Serial.println("Select band:");
|
||||
// Print the different options
|
||||
Serial.println("1 : E-GSM(900)");
|
||||
Serial.println("2 : DCS(1800)");
|
||||
Serial.println("3 : PCS(1900)");
|
||||
Serial.println("4 : E-GSM(900)+DCS(1800) ex: Europe");
|
||||
Serial.println("5 : GSM(850)+PCS(1900) Ex: USA, South Am.");
|
||||
Serial.println("6 : GSM(850)+E-GSM(900)+DCS(1800)+PCS(1900)");
|
||||
|
||||
// Empty the incoming buffer
|
||||
while (Serial.available())
|
||||
Serial.read();
|
||||
|
||||
// Wait for an answer, just look at the first character
|
||||
while (!Serial.available());
|
||||
char c = Serial.read();
|
||||
if (c == '1')
|
||||
newBand = GSM_MODE_EGSM;
|
||||
else if (c == '2')
|
||||
newBand = GSM_MODE_DCS;
|
||||
else if (c == '3')
|
||||
newBand = GSM_MODE_PCS;
|
||||
else if (c == '4')
|
||||
newBand = GSM_MODE_EGSM_DCS;
|
||||
else if (c == '5')
|
||||
newBand = GSM_MODE_GSM850_PCS;
|
||||
else if (c == '6')
|
||||
newBand = GSM_MODE_GSM850_EGSM_DCS_PCS;
|
||||
else
|
||||
newBand="GSM_MODE_UNDEFINED";
|
||||
newBand = "GSM_MODE_UNDEFINED";
|
||||
return newBand;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,23 +1,23 @@
|
||||
/*
|
||||
|
||||
|
||||
GSM Scan Networks
|
||||
|
||||
|
||||
This example prints out the IMEI number of the modem,
|
||||
then checks to see if it's connected to a carrier. If so,
|
||||
then checks to see if it's connected to a carrier. If so,
|
||||
it prints the phone number associated with the card.
|
||||
Then it scans for nearby networks and prints out their signal strengths.
|
||||
|
||||
|
||||
Circuit:
|
||||
* GSM shield
|
||||
* GSM shield
|
||||
* SIM card
|
||||
|
||||
|
||||
Created 8 Mar 2012
|
||||
by Tom Igoe, implemented by Javier Carazo
|
||||
Modified 4 Feb 2013
|
||||
by Scott Fitzgerald
|
||||
|
||||
|
||||
http://arduino.cc/en/Tutorial/GSMToolsGsmScanNetworks
|
||||
|
||||
|
||||
This example code is part of the public domain
|
||||
*/
|
||||
|
||||
@ -48,15 +48,15 @@ void setup()
|
||||
|
||||
Serial.println("GSM networks scanner");
|
||||
scannerNetworks.begin();
|
||||
|
||||
|
||||
// connection state
|
||||
boolean notConnected = true;
|
||||
|
||||
|
||||
// Start GSM shield
|
||||
// If your SIM has PIN, pass it as a parameter of begin() in quotes
|
||||
while(notConnected)
|
||||
while (notConnected)
|
||||
{
|
||||
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
|
||||
if (gsmAccess.begin(PINNUMBER) == GSM_READY)
|
||||
notConnected = false;
|
||||
else
|
||||
{
|
||||
@ -64,13 +64,13 @@ void setup()
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// get modem parameters
|
||||
// IMEI, modem unique identifier
|
||||
Serial.print("Modem IMEI: ");
|
||||
IMEI = modemTest.getIMEI();
|
||||
IMEI.replace("\n","");
|
||||
if(IMEI != NULL)
|
||||
IMEI.replace("\n", "");
|
||||
if (IMEI != NULL)
|
||||
Serial.println(IMEI);
|
||||
}
|
||||
|
||||
@ -79,11 +79,11 @@ void loop()
|
||||
// scan for existing networks, displays a list of networks
|
||||
Serial.println("Scanning available networks. May take some seconds.");
|
||||
Serial.println(scannerNetworks.readNetworks());
|
||||
|
||||
// currently connected carrier
|
||||
|
||||
// currently connected carrier
|
||||
Serial.print("Current carrier: ");
|
||||
Serial.println(scannerNetworks.getCurrentCarrier());
|
||||
|
||||
|
||||
// returns strength and ber
|
||||
// signal strength in 0-31 scale. 31 means power > 51dBm
|
||||
// BER is the Bit Error Rate. 0-7 scale. 99=not detectable
|
||||
|
@ -1,19 +1,19 @@
|
||||
/*
|
||||
|
||||
This example enables you to change or remove the PIN number of
|
||||
|
||||
This example enables you to change or remove the PIN number of
|
||||
a SIM card inserted into a GSM shield.
|
||||
|
||||
|
||||
Circuit:
|
||||
* GSM shield
|
||||
* SIM card
|
||||
|
||||
|
||||
Created 12 Jun 2012
|
||||
by David del Peral
|
||||
|
||||
This example code is part of the public domain
|
||||
|
||||
|
||||
This example code is part of the public domain
|
||||
|
||||
http://arduino.cc/en/Tutorial/GSMToolsPinManagement
|
||||
|
||||
|
||||
*/
|
||||
|
||||
// libraries
|
||||
@ -39,32 +39,32 @@ void setup()
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
|
||||
Serial.println("Change PIN example\n");
|
||||
PINManager.begin();
|
||||
|
||||
|
||||
// check if the SIM have pin lock
|
||||
while(!auth){
|
||||
while (!auth) {
|
||||
int pin_query = PINManager.isPIN();
|
||||
if(pin_query == 1)
|
||||
if (pin_query == 1)
|
||||
{
|
||||
// if SIM is locked, enter PIN code
|
||||
Serial.print("Enter PIN code: ");
|
||||
user_input = readSerial();
|
||||
// check PIN code
|
||||
if(PINManager.checkPIN(user_input) == 0)
|
||||
if (PINManager.checkPIN(user_input) == 0)
|
||||
{
|
||||
auth = true;
|
||||
PINManager.setPINUsed(true);
|
||||
Serial.println(oktext);
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
// if PIN code was incorrected
|
||||
Serial.println("Incorrect PIN. Remember that you have 3 opportunities.");
|
||||
}
|
||||
}
|
||||
else if(pin_query == -1)
|
||||
else if (pin_query == -1)
|
||||
{
|
||||
// PIN code is locked, user must enter PUK code
|
||||
Serial.println("PIN locked. Enter PUK code: ");
|
||||
@ -72,7 +72,7 @@ void setup()
|
||||
Serial.print("Now, enter a new PIN code: ");
|
||||
user_input = readSerial();
|
||||
// check PUK code
|
||||
if(PINManager.checkPUK(puk, user_input) == 0)
|
||||
if (PINManager.checkPUK(puk, user_input) == 0)
|
||||
{
|
||||
auth = true;
|
||||
PINManager.setPINUsed(true);
|
||||
@ -84,32 +84,32 @@ void setup()
|
||||
Serial.println("Incorrect PUK or invalid new PIN. Try again!.");
|
||||
}
|
||||
}
|
||||
else if(pin_query == -2)
|
||||
else if (pin_query == -2)
|
||||
{
|
||||
// the worst case, PIN and PUK are locked
|
||||
Serial.println("PIN & PUK locked. Use PIN2/PUK2 in a mobile phone.");
|
||||
while(true);
|
||||
while (true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// SIM does not requires authetication
|
||||
// SIM does not requires authetication
|
||||
Serial.println("No pin necessary.");
|
||||
auth = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// start GSM shield
|
||||
Serial.print("Checking register in GSM network...");
|
||||
if(PINManager.checkReg() == 0)
|
||||
if (PINManager.checkReg() == 0)
|
||||
Serial.println(oktext);
|
||||
// if you are connect by roaming
|
||||
else if(PINManager.checkReg() == 1)
|
||||
Serial.println("ROAMING " + oktext);
|
||||
else if (PINManager.checkReg() == 1)
|
||||
Serial.println("ROAMING " + oktext);
|
||||
else
|
||||
{
|
||||
// error connection
|
||||
Serial.println(errortext);
|
||||
while(true);
|
||||
while (true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -118,19 +118,19 @@ void loop()
|
||||
// Function loop implements pin management user menu
|
||||
// Only if you SIM use pin lock, you can change PIN code
|
||||
// user_op variables save user option
|
||||
|
||||
|
||||
Serial.println("Choose an option:\n1 - On/Off PIN.");
|
||||
if(PINManager.getPINUsed())
|
||||
if (PINManager.getPINUsed())
|
||||
Serial.println("2 - Change PIN.");
|
||||
String user_op = readSerial();
|
||||
if(user_op == "1")
|
||||
if (user_op == "1")
|
||||
{
|
||||
Serial.println("Enter your PIN code:");
|
||||
user_input = readSerial();
|
||||
// activate/deactivate PIN lock
|
||||
PINManager.switchPIN(user_input);
|
||||
}
|
||||
else if(user_op == "2" & PINManager.getPINUsed())
|
||||
else if (user_op == "2" & PINManager.getPINUsed())
|
||||
{
|
||||
Serial.println("Enter your actual PIN code:");
|
||||
String oldPIN = readSerial();
|
||||
@ -152,7 +152,7 @@ void loop()
|
||||
String readSerial()
|
||||
{
|
||||
String text = "";
|
||||
while(1)
|
||||
while (1)
|
||||
{
|
||||
while (Serial.available() > 0)
|
||||
{
|
||||
@ -161,7 +161,7 @@ String readSerial()
|
||||
{
|
||||
return text;
|
||||
}
|
||||
if(inChar!='\r')
|
||||
if (inChar != '\r')
|
||||
text += inChar;
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,20 @@
|
||||
/*
|
||||
|
||||
|
||||
This sketch test the GSM shield's ability to connect to a
|
||||
GPERS network. It asks for APN information through the
|
||||
GPERS network. It asks for APN information through the
|
||||
serial monitor and tries to connect to arduino.cc.
|
||||
|
||||
|
||||
Circuit:
|
||||
* GSM shield attached
|
||||
* SIM card with data plan
|
||||
|
||||
|
||||
Created 18 Jun 2012
|
||||
by David del Peral
|
||||
|
||||
|
||||
This example code is part of the public domain
|
||||
|
||||
|
||||
http://arduino.cc/en/Tutorial/GSMToolsTestGPRS
|
||||
|
||||
|
||||
*/
|
||||
|
||||
// libraries
|
||||
@ -55,53 +55,53 @@ void setup()
|
||||
void loop()
|
||||
{
|
||||
use_proxy = false;
|
||||
|
||||
|
||||
// start GSM shield
|
||||
// if your SIM has PIN, pass it as a parameter of begin() in quotes
|
||||
Serial.print("Connecting GSM network...");
|
||||
if(gsmAccess.begin(PINNUMBER)!=GSM_READY)
|
||||
if (gsmAccess.begin(PINNUMBER) != GSM_READY)
|
||||
{
|
||||
Serial.println(errortext);
|
||||
while(true);
|
||||
while (true);
|
||||
}
|
||||
Serial.println(oktext);
|
||||
|
||||
|
||||
// read APN introduced by user
|
||||
char apn[50];
|
||||
Serial.print("Enter your APN: ");
|
||||
readSerial(apn);
|
||||
Serial.println(apn);
|
||||
|
||||
|
||||
// Read APN login introduced by user
|
||||
char login[50];
|
||||
Serial.print("Now, enter your login: ");
|
||||
readSerial(login);
|
||||
Serial.println(login);
|
||||
|
||||
|
||||
// read APN password introduced by user
|
||||
char password[20];
|
||||
Serial.print("Finally, enter your password: ");
|
||||
readSerial(password);
|
||||
|
||||
|
||||
// attach GPRS
|
||||
Serial.println("Attaching to GPRS with your APN...");
|
||||
if(gprsAccess.attachGPRS(apn, login, password)!=GPRS_READY)
|
||||
if (gprsAccess.attachGPRS(apn, login, password) != GPRS_READY)
|
||||
{
|
||||
Serial.println(errortext);
|
||||
}
|
||||
else{
|
||||
|
||||
else {
|
||||
|
||||
Serial.println(oktext);
|
||||
|
||||
|
||||
// read proxy introduced by user
|
||||
char proxy[100];
|
||||
Serial.print("If your carrier uses a proxy, enter it, if not press enter: ");
|
||||
readSerial(proxy);
|
||||
Serial.println(proxy);
|
||||
|
||||
|
||||
// if user introduced a proxy, asks him for proxy port
|
||||
int pport;
|
||||
if(proxy[0] != '\0'){
|
||||
if (proxy[0] != '\0') {
|
||||
// read proxy port introduced by user
|
||||
char proxyport[10];
|
||||
Serial.print("Enter the proxy port: ");
|
||||
@ -111,61 +111,61 @@ void loop()
|
||||
use_proxy = true;
|
||||
Serial.println(proxyport);
|
||||
}
|
||||
|
||||
|
||||
// connection with arduino.cc and realize HTTP request
|
||||
Serial.print("Connecting and sending GET request to arduino.cc...");
|
||||
int res_connect;
|
||||
|
||||
|
||||
// if use a proxy, connect with it
|
||||
if(use_proxy)
|
||||
if (use_proxy)
|
||||
res_connect = client.connect(proxy, pport);
|
||||
else
|
||||
res_connect = client.connect(url, 80);
|
||||
|
||||
|
||||
if (res_connect)
|
||||
{
|
||||
// make a HTTP 1.0 GET request (client sends the request)
|
||||
client.print("GET ");
|
||||
|
||||
|
||||
// if use a proxy, the path is arduino.cc URL
|
||||
if(use_proxy)
|
||||
if (use_proxy)
|
||||
client.print(urlproxy);
|
||||
else
|
||||
client.print(path);
|
||||
|
||||
|
||||
client.println(" HTTP/1.0");
|
||||
client.println();
|
||||
Serial.println(oktext);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// if you didn't get a connection to the server
|
||||
Serial.println(errortext);
|
||||
}
|
||||
Serial.print("Receiving response...");
|
||||
|
||||
|
||||
boolean test = true;
|
||||
while(test)
|
||||
while (test)
|
||||
{
|
||||
// if there are incoming bytes available
|
||||
// if there are incoming bytes available
|
||||
// from the server, read and check them
|
||||
if (client.available())
|
||||
{
|
||||
char c = client.read();
|
||||
response += c;
|
||||
|
||||
|
||||
// cast response obtained from string to char array
|
||||
char responsechar[response.length()+1];
|
||||
response.toCharArray(responsechar, response.length()+1);
|
||||
|
||||
char responsechar[response.length() + 1];
|
||||
response.toCharArray(responsechar, response.length() + 1);
|
||||
|
||||
// if response includes a "200 OK" substring
|
||||
if(strstr(responsechar, "200 OK") != NULL){
|
||||
if (strstr(responsechar, "200 OK") != NULL) {
|
||||
Serial.println(oktext);
|
||||
Serial.println("TEST COMPLETE!");
|
||||
test = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// if the server's disconnected, stop the client:
|
||||
if (!client.connected())
|
||||
{
|
||||
@ -184,7 +184,7 @@ void loop()
|
||||
int readSerial(char result[])
|
||||
{
|
||||
int i = 0;
|
||||
while(1)
|
||||
while (1)
|
||||
{
|
||||
while (Serial.available() > 0)
|
||||
{
|
||||
@ -194,7 +194,7 @@ int readSerial(char result[])
|
||||
result[i] = '\0';
|
||||
return 0;
|
||||
}
|
||||
if(inChar!='\r')
|
||||
if (inChar != '\r')
|
||||
{
|
||||
result[i] = inChar;
|
||||
i++;
|
||||
|
@ -1,21 +1,21 @@
|
||||
/*
|
||||
|
||||
This example tests to see if the modem of the
|
||||
GSM shield is working correctly. You do not need
|
||||
|
||||
This example tests to see if the modem of the
|
||||
GSM shield is working correctly. You do not need
|
||||
a SIM card for this example.
|
||||
|
||||
|
||||
Circuit:
|
||||
* GSM shield attached
|
||||
|
||||
* GSM shield attached
|
||||
|
||||
Created 12 Jun 2012
|
||||
by David del Peral
|
||||
modified 21 Nov 2012
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
http://arduino.cc/en/Tutorial/GSMToolsTestModem
|
||||
|
||||
|
||||
This sample code is part of the public domain
|
||||
|
||||
|
||||
*/
|
||||
|
||||
// libraries
|
||||
@ -34,10 +34,10 @@ void setup()
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
|
||||
// start modem test (reset and check response)
|
||||
Serial.print("Starting modem test...");
|
||||
if(modem.begin())
|
||||
if (modem.begin())
|
||||
Serial.println("modem.begin() succeeded");
|
||||
else
|
||||
Serial.println("ERROR, no modem answer.");
|
||||
@ -48,9 +48,9 @@ void loop()
|
||||
// get modem IMEI
|
||||
Serial.print("Checking IMEI...");
|
||||
IMEI = modem.getIMEI();
|
||||
|
||||
|
||||
// check IMEI response
|
||||
if(IMEI != NULL)
|
||||
if (IMEI != NULL)
|
||||
{
|
||||
// show IMEI in serial monitor
|
||||
Serial.println("Modem's IMEI: " + IMEI);
|
||||
@ -58,7 +58,7 @@ void loop()
|
||||
Serial.print("Resetting modem...");
|
||||
modem.begin();
|
||||
// get and check IMEI one more time
|
||||
if(modem.getIMEI() != NULL)
|
||||
if (modem.getIMEI() != NULL)
|
||||
{
|
||||
Serial.println("Modem is functoning properly");
|
||||
}
|
||||
@ -72,6 +72,6 @@ void loop()
|
||||
Serial.println("Error: Could not get IMEI");
|
||||
}
|
||||
// do nothing:
|
||||
while(true);
|
||||
while (true);
|
||||
}
|
||||
|
||||
|
@ -1,22 +1,22 @@
|
||||
/*
|
||||
Basic Web Server
|
||||
|
||||
|
||||
A simple web server that replies with nothing, but prints the client's request
|
||||
and the server IP address.
|
||||
|
||||
Circuit:
|
||||
* GSM shield attached
|
||||
|
||||
created
|
||||
|
||||
created
|
||||
by David Cuartielles
|
||||
modified 21 Nov 2012
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
http://arduino.cc/en/Tutorial/GSMToolsTestWebServer
|
||||
|
||||
|
||||
This example code is part of the public domain
|
||||
*/
|
||||
#include <GSM.h>
|
||||
#include <GSM.h>
|
||||
|
||||
// PIN Number
|
||||
#define PINNUMBER ""
|
||||
@ -33,7 +33,7 @@ GSM gsmAccess; // include a 'true' parameter for debug enabled
|
||||
GSMServer server(80); // port 80 (http default)
|
||||
|
||||
// timeout
|
||||
const unsigned long __TIMEOUT__ = 10*1000;
|
||||
const unsigned long __TIMEOUT__ = 10 * 1000;
|
||||
|
||||
void setup()
|
||||
{
|
||||
@ -49,10 +49,10 @@ void setup()
|
||||
|
||||
// Start GSM shield
|
||||
// If your SIM has PIN, pass it as a parameter of begin() in quotes
|
||||
while(!connected)
|
||||
while (!connected)
|
||||
{
|
||||
if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
|
||||
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
|
||||
if ((gsmAccess.begin(PINNUMBER) == GSM_READY) &
|
||||
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY))
|
||||
connected = true;
|
||||
else
|
||||
{
|
||||
@ -72,14 +72,14 @@ void setup()
|
||||
Serial.println(LocalIP);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
void loop() {
|
||||
GSMClient client = server.available();
|
||||
|
||||
if (client) {
|
||||
if (client.available()) {
|
||||
Serial.write(client.read());
|
||||
}
|
||||
}
|
||||
|
||||
if (client) {
|
||||
if (client.available()) {
|
||||
Serial.write(client.read());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,14 @@
|
||||
/*
|
||||
LiquidCrystal Library - Autoscroll
|
||||
|
||||
|
||||
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
|
||||
library works with all LCD displays that are compatible with the
|
||||
library works with all LCD displays that are compatible with the
|
||||
Hitachi HD44780 driver. There are many of them out there, and you
|
||||
can usually tell them by the 16-pin interface.
|
||||
|
||||
|
||||
This sketch demonstrates the use of the autoscroll()
|
||||
and noAutoscroll() functions to make new text scroll or not.
|
||||
|
||||
|
||||
The circuit:
|
||||
* LCD RS pin to digital pin 12
|
||||
* LCD Enable pin to digital pin 11
|
||||
@ -20,16 +20,16 @@
|
||||
* 10K resistor:
|
||||
* ends to +5V and ground
|
||||
* wiper to LCD VO pin (pin 3)
|
||||
|
||||
|
||||
Library originally added 18 Apr 2008
|
||||
by David A. Mellis
|
||||
library modified 5 Jul 2009
|
||||
by Limor Fried (http://www.ladyada.net)
|
||||
example added 9 Jul 2009
|
||||
by Tom Igoe
|
||||
by Tom Igoe
|
||||
modified 22 Nov 2010
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
http://arduino.cc/en/Tutorial/LiquidCrystalAutoscroll
|
||||
@ -43,8 +43,8 @@
|
||||
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
|
||||
|
||||
void setup() {
|
||||
// set up the LCD's number of columns and rows:
|
||||
lcd.begin(16,2);
|
||||
// set up the LCD's number of columns and rows:
|
||||
lcd.begin(16, 2);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@ -52,12 +52,12 @@ void loop() {
|
||||
lcd.setCursor(0, 0);
|
||||
// print from 0 to 9:
|
||||
for (int thisChar = 0; thisChar < 10; thisChar++) {
|
||||
lcd.print(thisChar);
|
||||
delay(500);
|
||||
lcd.print(thisChar);
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// set the cursor to (16,1):
|
||||
lcd.setCursor(16,1);
|
||||
lcd.setCursor(16, 1);
|
||||
// set the display to automatically scroll:
|
||||
lcd.autoscroll();
|
||||
// print from 0 to 9:
|
||||
@ -67,7 +67,7 @@ void loop() {
|
||||
}
|
||||
// turn off automatic scrolling
|
||||
lcd.noAutoscroll();
|
||||
|
||||
|
||||
// clear screen for the next loop:
|
||||
lcd.clear();
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
/*
|
||||
LiquidCrystal Library - Blink
|
||||
|
||||
|
||||
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
|
||||
library works with all LCD displays that are compatible with the
|
||||
library works with all LCD displays that are compatible with the
|
||||
Hitachi HD44780 driver. There are many of them out there, and you
|
||||
can usually tell them by the 16-pin interface.
|
||||
|
||||
This sketch prints "Hello World!" to the LCD and makes the
|
||||
|
||||
This sketch prints "Hello World!" to the LCD and makes the
|
||||
cursor block blink.
|
||||
|
||||
|
||||
The circuit:
|
||||
* LCD RS pin to digital pin 12
|
||||
* LCD Enable pin to digital pin 11
|
||||
@ -20,20 +20,20 @@
|
||||
* 10K resistor:
|
||||
* ends to +5V and ground
|
||||
* wiper to LCD VO pin (pin 3)
|
||||
|
||||
|
||||
Library originally added 18 Apr 2008
|
||||
by David A. Mellis
|
||||
library modified 5 Jul 2009
|
||||
by Limor Fried (http://www.ladyada.net)
|
||||
example added 9 Jul 2009
|
||||
by Tom Igoe
|
||||
by Tom Igoe
|
||||
modified 22 Nov 2010
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
http://arduino.cc/en/Tutorial/LiquidCrystalBlink
|
||||
|
||||
|
||||
*/
|
||||
|
||||
// include the library code:
|
||||
@ -43,7 +43,7 @@
|
||||
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
|
||||
|
||||
void setup() {
|
||||
// set up the LCD's number of columns and rows:
|
||||
// set up the LCD's number of columns and rows:
|
||||
lcd.begin(16, 2);
|
||||
// Print a message to the LCD.
|
||||
lcd.print("hello, world!");
|
||||
@ -53,7 +53,7 @@ void loop() {
|
||||
// Turn off the blinking cursor:
|
||||
lcd.noBlink();
|
||||
delay(3000);
|
||||
// Turn on the blinking cursor:
|
||||
// Turn on the blinking cursor:
|
||||
lcd.blink();
|
||||
delay(3000);
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
/*
|
||||
LiquidCrystal Library - Cursor
|
||||
|
||||
|
||||
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
|
||||
library works with all LCD displays that are compatible with the
|
||||
library works with all LCD displays that are compatible with the
|
||||
Hitachi HD44780 driver. There are many of them out there, and you
|
||||
can usually tell them by the 16-pin interface.
|
||||
|
||||
|
||||
This sketch prints "Hello World!" to the LCD and
|
||||
uses the cursor() and noCursor() methods to turn
|
||||
on and off the cursor.
|
||||
|
||||
|
||||
The circuit:
|
||||
* LCD RS pin to digital pin 12
|
||||
* LCD Enable pin to digital pin 11
|
||||
@ -21,13 +21,13 @@
|
||||
* 10K resistor:
|
||||
* ends to +5V and ground
|
||||
* wiper to LCD VO pin (pin 3)
|
||||
|
||||
|
||||
Library originally added 18 Apr 2008
|
||||
by David A. Mellis
|
||||
library modified 5 Jul 2009
|
||||
by Limor Fried (http://www.ladyada.net)
|
||||
example added 9 Jul 2009
|
||||
by Tom Igoe
|
||||
by Tom Igoe
|
||||
modified 22 Nov 2010
|
||||
by Tom Igoe
|
||||
|
||||
@ -44,7 +44,7 @@
|
||||
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
|
||||
|
||||
void setup() {
|
||||
// set up the LCD's number of columns and rows:
|
||||
// set up the LCD's number of columns and rows:
|
||||
lcd.begin(16, 2);
|
||||
// Print a message to the LCD.
|
||||
lcd.print("hello, world!");
|
||||
@ -54,7 +54,7 @@ void loop() {
|
||||
// Turn off the cursor:
|
||||
lcd.noCursor();
|
||||
delay(500);
|
||||
// Turn on the cursor:
|
||||
// Turn on the cursor:
|
||||
lcd.cursor();
|
||||
delay(500);
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
/*
|
||||
LiquidCrystal Library - Custom Characters
|
||||
|
||||
Demonstrates how to add custom characters on an LCD display.
|
||||
The LiquidCrystal library works with all LCD displays that are
|
||||
compatible with the Hitachi HD44780 driver. There are many of
|
||||
|
||||
Demonstrates how to add custom characters on an LCD display.
|
||||
The LiquidCrystal library works with all LCD displays that are
|
||||
compatible with the Hitachi HD44780 driver. There are many of
|
||||
them out there, and you can usually tell them by the 16-pin interface.
|
||||
|
||||
|
||||
This sketch prints "I <heart> Arduino!" and a little dancing man
|
||||
to the LCD.
|
||||
|
||||
|
||||
The circuit:
|
||||
* LCD RS pin to digital pin 12
|
||||
* LCD Enable pin to digital pin 11
|
||||
@ -21,18 +21,18 @@
|
||||
* ends to +5V and ground
|
||||
* wiper to LCD VO pin (pin 3)
|
||||
* 10K poterntiometer on pin A0
|
||||
|
||||
|
||||
created21 Mar 2011
|
||||
by Tom Igoe
|
||||
Based on Adafruit's example at
|
||||
https://github.com/adafruit/SPI_VFD/blob/master/examples/createChar/createChar.pde
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
http://www.arduino.cc/en/Tutorial/LiquidCrystal
|
||||
|
||||
|
||||
Also useful:
|
||||
http://icontexto.com/charactercreator/
|
||||
|
||||
|
||||
*/
|
||||
|
||||
// include the library code:
|
||||
@ -104,14 +104,14 @@ void setup() {
|
||||
// create a new character
|
||||
lcd.createChar(2, frownie);
|
||||
// create a new character
|
||||
lcd.createChar(3, armsDown);
|
||||
lcd.createChar(3, armsDown);
|
||||
// create a new character
|
||||
lcd.createChar(4, armsUp);
|
||||
lcd.createChar(4, armsUp);
|
||||
|
||||
// set up the lcd's number of columns and rows:
|
||||
// set up the lcd's number of columns and rows:
|
||||
lcd.begin(16, 2);
|
||||
// Print a message to the lcd.
|
||||
lcd.print("I ");
|
||||
lcd.print("I ");
|
||||
lcd.write(0);
|
||||
lcd.print(" Arduino! ");
|
||||
lcd.write(1);
|
||||
@ -131,7 +131,7 @@ void loop() {
|
||||
lcd.setCursor(4, 1);
|
||||
// draw him arms up:
|
||||
lcd.write(4);
|
||||
delay(delayTime);
|
||||
delay(delayTime);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,15 +1,15 @@
|
||||
/*
|
||||
LiquidCrystal Library - display() and noDisplay()
|
||||
|
||||
|
||||
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
|
||||
library works with all LCD displays that are compatible with the
|
||||
library works with all LCD displays that are compatible with the
|
||||
Hitachi HD44780 driver. There are many of them out there, and you
|
||||
can usually tell them by the 16-pin interface.
|
||||
|
||||
This sketch prints "Hello World!" to the LCD and uses the
|
||||
|
||||
This sketch prints "Hello World!" to the LCD and uses the
|
||||
display() and noDisplay() functions to turn on and off
|
||||
the display.
|
||||
|
||||
|
||||
The circuit:
|
||||
* LCD RS pin to digital pin 12
|
||||
* LCD Enable pin to digital pin 11
|
||||
@ -21,13 +21,13 @@
|
||||
* 10K resistor:
|
||||
* ends to +5V and ground
|
||||
* wiper to LCD VO pin (pin 3)
|
||||
|
||||
|
||||
Library originally added 18 Apr 2008
|
||||
by David A. Mellis
|
||||
library modified 5 Jul 2009
|
||||
by Limor Fried (http://www.ladyada.net)
|
||||
example added 9 Jul 2009
|
||||
by Tom Igoe
|
||||
by Tom Igoe
|
||||
modified 22 Nov 2010
|
||||
by Tom Igoe
|
||||
|
||||
@ -44,7 +44,7 @@
|
||||
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
|
||||
|
||||
void setup() {
|
||||
// set up the LCD's number of columns and rows:
|
||||
// set up the LCD's number of columns and rows:
|
||||
lcd.begin(16, 2);
|
||||
// Print a message to the LCD.
|
||||
lcd.print("hello, world!");
|
||||
@ -54,7 +54,7 @@ void loop() {
|
||||
// Turn off the display:
|
||||
lcd.noDisplay();
|
||||
delay(500);
|
||||
// Turn on the display:
|
||||
// Turn on the display:
|
||||
lcd.display();
|
||||
delay(500);
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
/*
|
||||
LiquidCrystal Library - Hello World
|
||||
|
||||
|
||||
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
|
||||
library works with all LCD displays that are compatible with the
|
||||
library works with all LCD displays that are compatible with the
|
||||
Hitachi HD44780 driver. There are many of them out there, and you
|
||||
can usually tell them by the 16-pin interface.
|
||||
|
||||
|
||||
This sketch prints "Hello World!" to the LCD
|
||||
and shows the time.
|
||||
|
||||
|
||||
The circuit:
|
||||
* LCD RS pin to digital pin 12
|
||||
* LCD Enable pin to digital pin 11
|
||||
@ -20,7 +20,7 @@
|
||||
* 10K resistor:
|
||||
* ends to +5V and ground
|
||||
* wiper to LCD VO pin (pin 3)
|
||||
|
||||
|
||||
Library originally added 18 Apr 2008
|
||||
by David A. Mellis
|
||||
library modified 5 Jul 2009
|
||||
@ -29,7 +29,7 @@
|
||||
by Tom Igoe
|
||||
modified 22 Nov 2010
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/LiquidCrystal
|
||||
@ -42,7 +42,7 @@
|
||||
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
|
||||
|
||||
void setup() {
|
||||
// set up the LCD's number of columns and rows:
|
||||
// set up the LCD's number of columns and rows:
|
||||
lcd.begin(16, 2);
|
||||
// Print a message to the LCD.
|
||||
lcd.print("hello, world!");
|
||||
@ -53,6 +53,6 @@ void loop() {
|
||||
// (note: line 1 is the second row, since counting begins with 0):
|
||||
lcd.setCursor(0, 1);
|
||||
// print the number of seconds since reset:
|
||||
lcd.print(millis()/1000);
|
||||
lcd.print(millis() / 1000);
|
||||
}
|
||||
|
||||
|
@ -1,15 +1,15 @@
|
||||
/*
|
||||
LiquidCrystal Library - scrollDisplayLeft() and scrollDisplayRight()
|
||||
|
||||
|
||||
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
|
||||
library works with all LCD displays that are compatible with the
|
||||
library works with all LCD displays that are compatible with the
|
||||
Hitachi HD44780 driver. There are many of them out there, and you
|
||||
can usually tell them by the 16-pin interface.
|
||||
|
||||
|
||||
This sketch prints "Hello World!" to the LCD and uses the
|
||||
scrollDisplayLeft() and scrollDisplayRight() methods to scroll
|
||||
the text.
|
||||
|
||||
|
||||
The circuit:
|
||||
* LCD RS pin to digital pin 12
|
||||
* LCD Enable pin to digital pin 11
|
||||
@ -21,18 +21,18 @@
|
||||
* 10K resistor:
|
||||
* ends to +5V and ground
|
||||
* wiper to LCD VO pin (pin 3)
|
||||
|
||||
|
||||
Library originally added 18 Apr 2008
|
||||
by David A. Mellis
|
||||
library modified 5 Jul 2009
|
||||
by Limor Fried (http://www.ladyada.net)
|
||||
example added 9 Jul 2009
|
||||
by Tom Igoe
|
||||
by Tom Igoe
|
||||
modified 22 Nov 2010
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
|
||||
http://arduino.cc/en/Tutorial/LiquidCrystalScroll
|
||||
|
||||
*/
|
||||
@ -44,7 +44,7 @@
|
||||
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
|
||||
|
||||
void setup() {
|
||||
// set up the LCD's number of columns and rows:
|
||||
// set up the LCD's number of columns and rows:
|
||||
lcd.begin(16, 2);
|
||||
// Print a message to the LCD.
|
||||
lcd.print("hello, world!");
|
||||
@ -52,11 +52,11 @@ void setup() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// scroll 13 positions (string length) to the left
|
||||
// scroll 13 positions (string length) to the left
|
||||
// to move it offscreen left:
|
||||
for (int positionCounter = 0; positionCounter < 13; positionCounter++) {
|
||||
// scroll one position left:
|
||||
lcd.scrollDisplayLeft();
|
||||
lcd.scrollDisplayLeft();
|
||||
// wait a bit:
|
||||
delay(150);
|
||||
}
|
||||
@ -65,20 +65,20 @@ void loop() {
|
||||
// to move it offscreen right:
|
||||
for (int positionCounter = 0; positionCounter < 29; positionCounter++) {
|
||||
// scroll one position right:
|
||||
lcd.scrollDisplayRight();
|
||||
lcd.scrollDisplayRight();
|
||||
// wait a bit:
|
||||
delay(150);
|
||||
}
|
||||
|
||||
// scroll 16 positions (display length + string length) to the left
|
||||
// to move it back to center:
|
||||
|
||||
// scroll 16 positions (display length + string length) to the left
|
||||
// to move it back to center:
|
||||
for (int positionCounter = 0; positionCounter < 16; positionCounter++) {
|
||||
// scroll one position left:
|
||||
lcd.scrollDisplayLeft();
|
||||
lcd.scrollDisplayLeft();
|
||||
// wait a bit:
|
||||
delay(150);
|
||||
}
|
||||
|
||||
|
||||
// delay at the end of the full loop:
|
||||
delay(1000);
|
||||
|
||||
|
@ -1,14 +1,14 @@
|
||||
/*
|
||||
LiquidCrystal Library - Serial Input
|
||||
|
||||
|
||||
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
|
||||
library works with all LCD displays that are compatible with the
|
||||
library works with all LCD displays that are compatible with the
|
||||
Hitachi HD44780 driver. There are many of them out there, and you
|
||||
can usually tell them by the 16-pin interface.
|
||||
|
||||
This sketch displays text sent over the serial port
|
||||
|
||||
This sketch displays text sent over the serial port
|
||||
(e.g. from the Serial Monitor) on an attached LCD.
|
||||
|
||||
|
||||
The circuit:
|
||||
* LCD RS pin to digital pin 12
|
||||
* LCD Enable pin to digital pin 11
|
||||
@ -20,18 +20,18 @@
|
||||
* 10K resistor:
|
||||
* ends to +5V and ground
|
||||
* wiper to LCD VO pin (pin 3)
|
||||
|
||||
|
||||
Library originally added 18 Apr 2008
|
||||
by David A. Mellis
|
||||
library modified 5 Jul 2009
|
||||
by Limor Fried (http://www.ladyada.net)
|
||||
example added 9 Jul 2009
|
||||
by Tom Igoe
|
||||
by Tom Igoe
|
||||
modified 22 Nov 2010
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
|
||||
http://arduino.cc/en/Tutorial/LiquidCrystalSerial
|
||||
*/
|
||||
|
||||
@ -41,8 +41,8 @@
|
||||
// initialize the library with the numbers of the interface pins
|
||||
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
|
||||
|
||||
void setup(){
|
||||
// set up the LCD's number of columns and rows:
|
||||
void setup() {
|
||||
// set up the LCD's number of columns and rows:
|
||||
lcd.begin(16, 2);
|
||||
// initialize the serial communications:
|
||||
Serial.begin(9600);
|
||||
|
@ -1,40 +1,40 @@
|
||||
/*
|
||||
LiquidCrystal Library - TextDirection
|
||||
|
||||
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
|
||||
library works with all LCD displays that are compatible with the
|
||||
Hitachi HD44780 driver. There are many of them out there, and you
|
||||
can usually tell them by the 16-pin interface.
|
||||
|
||||
This sketch demonstrates how to use leftToRight() and rightToLeft()
|
||||
to move the cursor.
|
||||
|
||||
The circuit:
|
||||
* LCD RS pin to digital pin 12
|
||||
* LCD Enable pin to digital pin 11
|
||||
* LCD D4 pin to digital pin 5
|
||||
* LCD D5 pin to digital pin 4
|
||||
* LCD D6 pin to digital pin 3
|
||||
* LCD D7 pin to digital pin 2
|
||||
* LCD R/W pin to ground
|
||||
* 10K resistor:
|
||||
* ends to +5V and ground
|
||||
* wiper to LCD VO pin (pin 3)
|
||||
|
||||
Library originally added 18 Apr 2008
|
||||
by David A. Mellis
|
||||
library modified 5 Jul 2009
|
||||
by Limor Fried (http://www.ladyada.net)
|
||||
example added 9 Jul 2009
|
||||
by Tom Igoe
|
||||
modified 22 Nov 2010
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
http://arduino.cc/en/Tutorial/LiquidCrystalTextDirection
|
||||
|
||||
*/
|
||||
/*
|
||||
LiquidCrystal Library - TextDirection
|
||||
|
||||
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
|
||||
library works with all LCD displays that are compatible with the
|
||||
Hitachi HD44780 driver. There are many of them out there, and you
|
||||
can usually tell them by the 16-pin interface.
|
||||
|
||||
This sketch demonstrates how to use leftToRight() and rightToLeft()
|
||||
to move the cursor.
|
||||
|
||||
The circuit:
|
||||
* LCD RS pin to digital pin 12
|
||||
* LCD Enable pin to digital pin 11
|
||||
* LCD D4 pin to digital pin 5
|
||||
* LCD D5 pin to digital pin 4
|
||||
* LCD D6 pin to digital pin 3
|
||||
* LCD D7 pin to digital pin 2
|
||||
* LCD R/W pin to ground
|
||||
* 10K resistor:
|
||||
* ends to +5V and ground
|
||||
* wiper to LCD VO pin (pin 3)
|
||||
|
||||
Library originally added 18 Apr 2008
|
||||
by David A. Mellis
|
||||
library modified 5 Jul 2009
|
||||
by Limor Fried (http://www.ladyada.net)
|
||||
example added 9 Jul 2009
|
||||
by Tom Igoe
|
||||
modified 22 Nov 2010
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
http://arduino.cc/en/Tutorial/LiquidCrystalTextDirection
|
||||
|
||||
*/
|
||||
|
||||
// include the library code:
|
||||
#include <LiquidCrystal.h>
|
||||
@ -45,7 +45,7 @@ LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
|
||||
int thisChar = 'a';
|
||||
|
||||
void setup() {
|
||||
// set up the LCD's number of columns and rows:
|
||||
// set up the LCD's number of columns and rows:
|
||||
lcd.begin(16, 2);
|
||||
// turn on the cursor:
|
||||
lcd.cursor();
|
||||
@ -55,17 +55,17 @@ void loop() {
|
||||
// reverse directions at 'm':
|
||||
if (thisChar == 'm') {
|
||||
// go right for the next letter
|
||||
lcd.rightToLeft();
|
||||
lcd.rightToLeft();
|
||||
}
|
||||
// reverse again at 's':
|
||||
if (thisChar == 's') {
|
||||
// go left for the next letter
|
||||
lcd.leftToRight();
|
||||
lcd.leftToRight();
|
||||
}
|
||||
// reset at 'z':
|
||||
if (thisChar > 'z') {
|
||||
// go to (0,0):
|
||||
lcd.home();
|
||||
lcd.home();
|
||||
// start again at 0
|
||||
thisChar = 'a';
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
/*
|
||||
LiquidCrystal Library - setCursor
|
||||
|
||||
|
||||
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
|
||||
library works with all LCD displays that are compatible with the
|
||||
library works with all LCD displays that are compatible with the
|
||||
Hitachi HD44780 driver. There are many of them out there, and you
|
||||
can usually tell them by the 16-pin interface.
|
||||
|
||||
|
||||
This sketch prints to all the positions of the LCD using the
|
||||
setCursor(0 method:
|
||||
|
||||
|
||||
The circuit:
|
||||
* LCD RS pin to digital pin 12
|
||||
* LCD Enable pin to digital pin 11
|
||||
@ -20,18 +20,18 @@
|
||||
* 10K resistor:
|
||||
* ends to +5V and ground
|
||||
* wiper to LCD VO pin (pin 3)
|
||||
|
||||
|
||||
Library originally added 18 Apr 2008
|
||||
by David A. Mellis
|
||||
library modified 5 Jul 2009
|
||||
by Limor Fried (http://www.ladyada.net)
|
||||
example added 9 Jul 2009
|
||||
by Tom Igoe
|
||||
by Tom Igoe
|
||||
modified 22 Nov 2010
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
|
||||
http://arduino.cc/en/Tutorial/LiquidCrystalSetCursor
|
||||
|
||||
*/
|
||||
@ -48,8 +48,8 @@ const int numCols = 16;
|
||||
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
|
||||
|
||||
void setup() {
|
||||
// set up the LCD's number of columns and rows:
|
||||
lcd.begin(numCols,numRows);
|
||||
// set up the LCD's number of columns and rows:
|
||||
lcd.begin(numCols, numRows);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@ -60,7 +60,7 @@ void loop() {
|
||||
// loop over the rows:
|
||||
for (int thisRow = 0; thisRow < numCols; thisRow++) {
|
||||
// set the cursor position:
|
||||
lcd.setCursor(thisRow,thisCol);
|
||||
lcd.setCursor(thisRow, thisCol);
|
||||
// print the letter:
|
||||
lcd.write(thisLetter);
|
||||
delay(200);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* IRrecord: record and play back IR signals as a minimal
|
||||
* IRrecord: record and play back IR signals as a minimal
|
||||
* An IR detector/demodulator must be connected to the input RECV_PIN.
|
||||
* An IR LED must be connected to the output PWM pin 3.
|
||||
* A button must be connected to the input BUTTON_PIN; this is the
|
||||
@ -56,12 +56,12 @@ void storeCode(decode_results *results) {
|
||||
for (int i = 1; i <= codeLen; i++) {
|
||||
if (i % 2) {
|
||||
// Mark
|
||||
rawCodes[i - 1] = results->rawbuf[i]*USECPERTICK - MARK_EXCESS;
|
||||
rawCodes[i - 1] = results->rawbuf[i] * USECPERTICK - MARK_EXCESS;
|
||||
Serial.print(" m");
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Space
|
||||
rawCodes[i - 1] = results->rawbuf[i]*USECPERTICK + MARK_EXCESS;
|
||||
rawCodes[i - 1] = results->rawbuf[i] * USECPERTICK + MARK_EXCESS;
|
||||
Serial.print(" s");
|
||||
}
|
||||
Serial.print(rawCodes[i - 1], DEC);
|
||||
@ -76,16 +76,16 @@ void storeCode(decode_results *results) {
|
||||
Serial.println("repeat; ignoring.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (codeType == SONY) {
|
||||
Serial.print("Received SONY: ");
|
||||
}
|
||||
}
|
||||
else if (codeType == RC5) {
|
||||
Serial.print("Received RC5: ");
|
||||
}
|
||||
}
|
||||
else if (codeType == RC6) {
|
||||
Serial.print("Received RC6: ");
|
||||
}
|
||||
}
|
||||
else {
|
||||
Serial.print("Unexpected codeType ");
|
||||
Serial.print(codeType, DEC);
|
||||
@ -102,18 +102,18 @@ void sendCode(int repeat) {
|
||||
if (repeat) {
|
||||
irsend.sendNEC(REPEAT, codeLen);
|
||||
Serial.println("Sent NEC repeat");
|
||||
}
|
||||
}
|
||||
else {
|
||||
irsend.sendNEC(codeValue, codeLen);
|
||||
Serial.print("Sent NEC ");
|
||||
Serial.println(codeValue, HEX);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (codeType == SONY) {
|
||||
irsend.sendSony(codeValue, codeLen);
|
||||
Serial.print("Sent Sony ");
|
||||
Serial.println(codeValue, HEX);
|
||||
}
|
||||
}
|
||||
else if (codeType == RC5 || codeType == RC6) {
|
||||
if (!repeat) {
|
||||
// Flip the toggle bit for a new button press
|
||||
@ -126,13 +126,13 @@ void sendCode(int repeat) {
|
||||
Serial.print("Sent RC5 ");
|
||||
Serial.println(codeValue, HEX);
|
||||
irsend.sendRC5(codeValue, codeLen);
|
||||
}
|
||||
}
|
||||
else {
|
||||
irsend.sendRC6(codeValue, codeLen);
|
||||
Serial.print("Sent RC6 ");
|
||||
Serial.println(codeValue, HEX);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (codeType == UNKNOWN /* i.e. raw */) {
|
||||
// Assume 38 KHz
|
||||
irsend.sendRaw(rawCodes, codeLen, 38);
|
||||
@ -156,7 +156,7 @@ void loop() {
|
||||
sendCode(lastButtonState == buttonState);
|
||||
digitalWrite(STATUS_PIN, LOW);
|
||||
delay(50); // Wait a bit between retransmissions
|
||||
}
|
||||
}
|
||||
else if (irrecv.decode(&results)) {
|
||||
digitalWrite(STATUS_PIN, HIGH);
|
||||
storeCode(&results);
|
||||
|
@ -30,26 +30,26 @@ void dump(decode_results *results) {
|
||||
int count = results->rawlen;
|
||||
if (results->decode_type == UNKNOWN) {
|
||||
Serial.print("Unknown encoding: ");
|
||||
}
|
||||
}
|
||||
else if (results->decode_type == NEC) {
|
||||
Serial.print("Decoded NEC: ");
|
||||
}
|
||||
}
|
||||
else if (results->decode_type == SONY) {
|
||||
Serial.print("Decoded SONY: ");
|
||||
}
|
||||
}
|
||||
else if (results->decode_type == RC5) {
|
||||
Serial.print("Decoded RC5: ");
|
||||
}
|
||||
}
|
||||
else if (results->decode_type == RC6) {
|
||||
Serial.print("Decoded RC6: ");
|
||||
}
|
||||
else if (results->decode_type == PANASONIC) {
|
||||
else if (results->decode_type == PANASONIC) {
|
||||
Serial.print("Decoded PANASONIC - Address: ");
|
||||
Serial.print(results->panasonicAddress,HEX);
|
||||
Serial.print(results->panasonicAddress, HEX);
|
||||
Serial.print(" Value: ");
|
||||
}
|
||||
else if (results->decode_type == JVC) {
|
||||
Serial.print("Decoded JVC: ");
|
||||
Serial.print("Decoded JVC: ");
|
||||
}
|
||||
Serial.print(results->value, HEX);
|
||||
Serial.print(" (");
|
||||
@ -62,7 +62,7 @@ void dump(decode_results *results) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
if ((i % 2) == 1) {
|
||||
Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC);
|
||||
}
|
||||
|
@ -23,17 +23,17 @@ void dump(decode_results *results) {
|
||||
int count = results->rawlen;
|
||||
if (results->decode_type == UNKNOWN) {
|
||||
Serial.println("Could not decode message");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (results->decode_type == NEC) {
|
||||
Serial.print("Decoded NEC: ");
|
||||
}
|
||||
}
|
||||
else if (results->decode_type == SONY) {
|
||||
Serial.print("Decoded SONY: ");
|
||||
}
|
||||
}
|
||||
else if (results->decode_type == RC5) {
|
||||
Serial.print("Decoded RC5: ");
|
||||
}
|
||||
}
|
||||
else if (results->decode_type == RC6) {
|
||||
Serial.print("Decoded RC6: ");
|
||||
}
|
||||
@ -49,7 +49,7 @@ void dump(decode_results *results) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
if ((i % 2) == 1) {
|
||||
Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC);
|
||||
}
|
||||
@ -62,7 +62,7 @@ void setup()
|
||||
{
|
||||
pinMode(RELAY_PIN, OUTPUT);
|
||||
pinMode(13, OUTPUT);
|
||||
Serial.begin(9600);
|
||||
Serial.begin(9600);
|
||||
irrecv.enableIRIn(); // Start the receiver
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ void loop() {
|
||||
digitalWrite(13, on ? HIGH : LOW);
|
||||
dump(&results);
|
||||
}
|
||||
last = millis();
|
||||
last = millis();
|
||||
irrecv.resume(); // Receive the next value
|
||||
}
|
||||
}
|
||||
|
@ -21,17 +21,17 @@ void dump(decode_results *results) {
|
||||
int count = results->rawlen;
|
||||
if (results->decode_type == UNKNOWN) {
|
||||
Serial.println("Could not decode message");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (results->decode_type == NEC) {
|
||||
Serial.print("Decoded NEC: ");
|
||||
}
|
||||
}
|
||||
else if (results->decode_type == SONY) {
|
||||
Serial.print("Decoded SONY: ");
|
||||
}
|
||||
}
|
||||
else if (results->decode_type == RC5) {
|
||||
Serial.print("Decoded RC5: ");
|
||||
}
|
||||
}
|
||||
else if (results->decode_type == RC6) {
|
||||
Serial.print("Decoded RC6: ");
|
||||
}
|
||||
@ -47,7 +47,7 @@ void dump(decode_results *results) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
if ((i % 2) == 1) {
|
||||
Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC);
|
||||
}
|
||||
@ -59,61 +59,61 @@ void dump(decode_results *results) {
|
||||
IRrecv irrecv(0);
|
||||
decode_results results;
|
||||
|
||||
class IRsendDummy :
|
||||
public IRsend
|
||||
class IRsendDummy :
|
||||
public IRsend
|
||||
{
|
||||
public:
|
||||
// For testing, just log the marks/spaces
|
||||
public:
|
||||
// For testing, just log the marks/spaces
|
||||
#define SENDLOG_LEN 128
|
||||
int sendlog[SENDLOG_LEN];
|
||||
int sendlogcnt;
|
||||
IRsendDummy() :
|
||||
IRsend() {
|
||||
}
|
||||
void reset() {
|
||||
sendlogcnt = 0;
|
||||
}
|
||||
void mark(int time) {
|
||||
sendlog[sendlogcnt] = time;
|
||||
if (sendlogcnt < SENDLOG_LEN) sendlogcnt++;
|
||||
}
|
||||
void space(int time) {
|
||||
sendlog[sendlogcnt] = -time;
|
||||
if (sendlogcnt < SENDLOG_LEN) sendlogcnt++;
|
||||
}
|
||||
// Copies the dummy buf into the interrupt buf
|
||||
void useDummyBuf() {
|
||||
int last = SPACE;
|
||||
irparams.rcvstate = STATE_STOP;
|
||||
irparams.rawlen = 1; // Skip the gap
|
||||
for (int i = 0 ; i < sendlogcnt; i++) {
|
||||
if (sendlog[i] < 0) {
|
||||
if (last == MARK) {
|
||||
// New space
|
||||
irparams.rawbuf[irparams.rawlen++] = (-sendlog[i] - MARK_EXCESS) / USECPERTICK;
|
||||
last = SPACE;
|
||||
}
|
||||
else {
|
||||
// More space
|
||||
irparams.rawbuf[irparams.rawlen - 1] += -sendlog[i] / USECPERTICK;
|
||||
int sendlog[SENDLOG_LEN];
|
||||
int sendlogcnt;
|
||||
IRsendDummy() :
|
||||
IRsend() {
|
||||
}
|
||||
void reset() {
|
||||
sendlogcnt = 0;
|
||||
}
|
||||
void mark(int time) {
|
||||
sendlog[sendlogcnt] = time;
|
||||
if (sendlogcnt < SENDLOG_LEN) sendlogcnt++;
|
||||
}
|
||||
void space(int time) {
|
||||
sendlog[sendlogcnt] = -time;
|
||||
if (sendlogcnt < SENDLOG_LEN) sendlogcnt++;
|
||||
}
|
||||
// Copies the dummy buf into the interrupt buf
|
||||
void useDummyBuf() {
|
||||
int last = SPACE;
|
||||
irparams.rcvstate = STATE_STOP;
|
||||
irparams.rawlen = 1; // Skip the gap
|
||||
for (int i = 0 ; i < sendlogcnt; i++) {
|
||||
if (sendlog[i] < 0) {
|
||||
if (last == MARK) {
|
||||
// New space
|
||||
irparams.rawbuf[irparams.rawlen++] = (-sendlog[i] - MARK_EXCESS) / USECPERTICK;
|
||||
last = SPACE;
|
||||
}
|
||||
else {
|
||||
// More space
|
||||
irparams.rawbuf[irparams.rawlen - 1] += -sendlog[i] / USECPERTICK;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (sendlog[i] > 0) {
|
||||
if (last == SPACE) {
|
||||
// New mark
|
||||
irparams.rawbuf[irparams.rawlen++] = (sendlog[i] + MARK_EXCESS) / USECPERTICK;
|
||||
last = MARK;
|
||||
}
|
||||
else {
|
||||
// More mark
|
||||
irparams.rawbuf[irparams.rawlen - 1] += sendlog[i] / USECPERTICK;
|
||||
else if (sendlog[i] > 0) {
|
||||
if (last == SPACE) {
|
||||
// New mark
|
||||
irparams.rawbuf[irparams.rawlen++] = (sendlog[i] + MARK_EXCESS) / USECPERTICK;
|
||||
last = MARK;
|
||||
}
|
||||
else {
|
||||
// More mark
|
||||
irparams.rawbuf[irparams.rawlen - 1] += sendlog[i] / USECPERTICK;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (irparams.rawlen % 2) {
|
||||
irparams.rawlen--; // Remove trailing space
|
||||
}
|
||||
}
|
||||
if (irparams.rawlen % 2) {
|
||||
irparams.rawlen--; // Remove trailing space
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
IRsendDummy irsenddummy;
|
||||
@ -125,12 +125,12 @@ void verify(unsigned long val, int bits, int type) {
|
||||
Serial.print(val, HEX);
|
||||
if (results.value == val && results.bits == bits && results.decode_type == type) {
|
||||
Serial.println(": OK");
|
||||
}
|
||||
}
|
||||
else {
|
||||
Serial.println(": Error");
|
||||
dump(&results);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void testNEC(unsigned long val, int bits) {
|
||||
irsenddummy.reset();
|
||||
|
@ -20,7 +20,7 @@
|
||||
* The test software automatically decides which board is the sender and which is
|
||||
* the receiver by looking for an input on the send pin, which will indicate
|
||||
* the sender. You should hook the serial port to the receiver for debugging.
|
||||
*
|
||||
*
|
||||
* Copyright 2010 Ken Shirriff
|
||||
* http://arcfn.com
|
||||
*/
|
||||
@ -51,7 +51,7 @@ void setup()
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
digitalWrite(LED_PIN, LOW);
|
||||
Serial.println("Receiver mode");
|
||||
}
|
||||
}
|
||||
else {
|
||||
mode = SENDER;
|
||||
Serial.println("Sender mode");
|
||||
@ -64,7 +64,7 @@ void setup()
|
||||
void waitForGap(int gap) {
|
||||
Serial.println("Waiting for gap");
|
||||
while (1) {
|
||||
while (digitalRead(RECV_PIN) == LOW) {
|
||||
while (digitalRead(RECV_PIN) == LOW) {
|
||||
}
|
||||
unsigned long time = millis();
|
||||
while (digitalRead(RECV_PIN) == HIGH) {
|
||||
@ -81,17 +81,17 @@ void dump(decode_results *results) {
|
||||
int count = results->rawlen;
|
||||
if (results->decode_type == UNKNOWN) {
|
||||
Serial.println("Could not decode message");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (results->decode_type == NEC) {
|
||||
Serial.print("Decoded NEC: ");
|
||||
}
|
||||
}
|
||||
else if (results->decode_type == SONY) {
|
||||
Serial.print("Decoded SONY: ");
|
||||
}
|
||||
}
|
||||
else if (results->decode_type == RC5) {
|
||||
Serial.print("Decoded RC5: ");
|
||||
}
|
||||
}
|
||||
else if (results->decode_type == RC6) {
|
||||
Serial.print("Decoded RC6: ");
|
||||
}
|
||||
@ -107,7 +107,7 @@ void dump(decode_results *results) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
if ((i % 2) == 1) {
|
||||
Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC);
|
||||
}
|
||||
@ -130,22 +130,22 @@ void test(char *label, int type, unsigned long value, int bits) {
|
||||
Serial.println(label);
|
||||
if (type == NEC) {
|
||||
irsend.sendNEC(value, bits);
|
||||
}
|
||||
}
|
||||
else if (type == SONY) {
|
||||
irsend.sendSony(value, bits);
|
||||
}
|
||||
}
|
||||
else if (type == RC5) {
|
||||
irsend.sendRC5(value, bits);
|
||||
}
|
||||
}
|
||||
else if (type == RC6) {
|
||||
irsend.sendRC6(value, bits);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Serial.print(label);
|
||||
Serial.println("Bad type!");
|
||||
}
|
||||
delay(200);
|
||||
}
|
||||
}
|
||||
else if (mode == RECEIVER) {
|
||||
irrecv.resume(); // Receive the next value
|
||||
unsigned long max_time = millis() + 30000;
|
||||
@ -164,7 +164,7 @@ void test(char *label, int type, unsigned long value, int bits) {
|
||||
digitalWrite(LED_PIN, HIGH);
|
||||
delay(20);
|
||||
digitalWrite(LED_PIN, LOW);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Serial.println(": BAD");
|
||||
dump(&results);
|
||||
@ -180,7 +180,7 @@ void testRaw(char *label, unsigned int *rawbuf, int rawlen) {
|
||||
Serial.println(label);
|
||||
irsend.sendRaw(rawbuf, rawlen, 38 /* kHz */);
|
||||
delay(200);
|
||||
}
|
||||
}
|
||||
else if (mode == RECEIVER ) {
|
||||
irrecv.resume(); // Receive the next value
|
||||
unsigned long max_time = millis() + 30000;
|
||||
@ -203,11 +203,11 @@ void testRaw(char *label, unsigned int *rawbuf, int rawlen) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < rawlen; i++) {
|
||||
long got = results.rawbuf[i+1] * USECPERTICK;
|
||||
long got = results.rawbuf[i + 1] * USECPERTICK;
|
||||
// Adjust for extra duration of marks
|
||||
if (i % 2 == 0) {
|
||||
if (i % 2 == 0) {
|
||||
got -= MARK_EXCESS;
|
||||
}
|
||||
}
|
||||
else {
|
||||
got += MARK_EXCESS;
|
||||
}
|
||||
@ -225,7 +225,7 @@ void testRaw(char *label, unsigned int *rawbuf, int rawlen) {
|
||||
delay(20);
|
||||
digitalWrite(LED_PIN, LOW);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This is the raw data corresponding to NEC 0x12345678
|
||||
unsigned int sendbuf[] = { /* NEC format */
|
||||
@ -238,15 +238,16 @@ unsigned int sendbuf[] = { /* NEC format */
|
||||
560, 560, 560, 1690, 560, 1690, 560, 560, /* 6 */
|
||||
560, 560, 560, 1690, 560, 1690, 560, 1690, /* 7 */
|
||||
560, 1690, 560, 560, 560, 560, 560, 560, /* 8 */
|
||||
560};
|
||||
560
|
||||
};
|
||||
|
||||
void loop() {
|
||||
if (mode == SENDER) {
|
||||
delay(2000); // Delay for more than gap to give receiver a better chance to sync.
|
||||
}
|
||||
}
|
||||
else if (mode == RECEIVER) {
|
||||
waitForGap(1000);
|
||||
}
|
||||
}
|
||||
else if (mode == ERROR) {
|
||||
// Light up for 5 seconds for error
|
||||
digitalWrite(LED_PIN, HIGH);
|
||||
@ -282,7 +283,7 @@ void loop() {
|
||||
if (mode == SENDER) {
|
||||
testRaw("RAW2", sendbuf, 67);
|
||||
test("RAW3", NEC, 0x12345678, 32);
|
||||
}
|
||||
}
|
||||
else {
|
||||
test("RAW2", NEC, 0x12345678, 32);
|
||||
testRaw("RAW3", sendbuf, 67);
|
||||
|
@ -7,7 +7,7 @@
|
||||
* JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post)
|
||||
*/
|
||||
#include <IRremote.h>
|
||||
|
||||
|
||||
#define PanasonicAddress 0x4004 // Panasonic address (Pre data)
|
||||
#define PanasonicPower 0x100BCBD // Panasonic Power button
|
||||
|
||||
@ -20,10 +20,10 @@ void setup()
|
||||
}
|
||||
|
||||
void loop() {
|
||||
irsend.sendPanasonic(PanasonicAddress,PanasonicPower); // This should turn your TV on and off
|
||||
|
||||
irsend.sendJVC(JVCPower, 16,0); // hex value, 16 bits, no repeat
|
||||
irsend.sendPanasonic(PanasonicAddress, PanasonicPower); // This should turn your TV on and off
|
||||
|
||||
irsend.sendJVC(JVCPower, 16, 0); // hex value, 16 bits, no repeat
|
||||
delayMicroseconds(50); // see http://www.sbprojects.com/knowledge/ir/jvc.php for information
|
||||
irsend.sendJVC(JVCPower, 16,1); // hex value, 16 bits, repeat
|
||||
irsend.sendJVC(JVCPower, 16, 1); // hex value, 16 bits, repeat
|
||||
delayMicroseconds(50);
|
||||
}
|
||||
|
@ -1,24 +1,24 @@
|
||||
/* Robot Logo
|
||||
|
||||
This sketch demonstrates basic movement of the Robot.
|
||||
When the sketch starts, press the on-board buttons to tell
|
||||
the robot how to move. Pressing the middle button will
|
||||
save the pattern, and the robot will follow accordingly.
|
||||
You can record up to 20 commands. The robot will move for
|
||||
This sketch demonstrates basic movement of the Robot.
|
||||
When the sketch starts, press the on-board buttons to tell
|
||||
the robot how to move. Pressing the middle button will
|
||||
save the pattern, and the robot will follow accordingly.
|
||||
You can record up to 20 commands. The robot will move for
|
||||
one second per command.
|
||||
|
||||
|
||||
This example uses images on an SD card. It looks for
|
||||
files named "lg0.bmp" and "lg1.bmp" and draws them on the
|
||||
screen.
|
||||
|
||||
Circuit:
|
||||
* Arduino Robot
|
||||
|
||||
|
||||
created 1 May 2013
|
||||
by X. Yang
|
||||
modified 12 May 2013
|
||||
by D. Cuartielles
|
||||
|
||||
|
||||
This example is in the public domain
|
||||
*/
|
||||
|
||||
@ -27,7 +27,7 @@
|
||||
int commands[20]; // array for storing commands
|
||||
|
||||
void setup() {
|
||||
// initialize the Robot, SD card, and display
|
||||
// initialize the Robot, SD card, and display
|
||||
Robot.begin();
|
||||
Robot.beginTFT();
|
||||
Robot.beginSD();
|
||||
@ -37,39 +37,39 @@ void setup() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
|
||||
Robot.drawBMP("intro.bmp", 0, 0); //display background image
|
||||
|
||||
|
||||
iniCommands(); // remove commands from the array
|
||||
addCommands(); // add commands to the array
|
||||
|
||||
|
||||
delay(1000); // wait for a second
|
||||
|
||||
|
||||
executeCommands(); // follow orders
|
||||
|
||||
Robot.stroke(0,0,0);
|
||||
|
||||
Robot.stroke(0, 0, 0);
|
||||
Robot.text("Done!", 5, 103); // write some text to the display
|
||||
delay(1500); // wait for a moment
|
||||
}
|
||||
|
||||
// empty the commands array
|
||||
void iniCommands() {
|
||||
for(int i=0; i<20; i++)
|
||||
commands[i]=-1;
|
||||
for (int i = 0; i < 20; i++)
|
||||
commands[i] = -1;
|
||||
}
|
||||
|
||||
// add commands to the array
|
||||
void addCommands() {
|
||||
Robot.stroke(0,0,0);
|
||||
Robot.stroke(0, 0, 0);
|
||||
// display text on the screen
|
||||
Robot.text("1. Press buttons to\n add commands.\n\n 2. Middle to finish.", 5, 5);
|
||||
|
||||
|
||||
// read the buttons' state
|
||||
for(int i=0; i<20;) { //max 20 commands
|
||||
for (int i = 0; i < 20;) { //max 20 commands
|
||||
int key = Robot.keyboardRead();
|
||||
if(key == BUTTON_MIDDLE) { //finish input
|
||||
if (key == BUTTON_MIDDLE) { //finish input
|
||||
break;
|
||||
}else if(key == BUTTON_NONE) { //if no button is pressed
|
||||
} else if (key == BUTTON_NONE) { //if no button is pressed
|
||||
continue;
|
||||
}
|
||||
commands[i] = key; // save the button to the array
|
||||
@ -82,11 +82,11 @@ void addCommands() {
|
||||
// run through the array and move the robot
|
||||
void executeCommands() {
|
||||
// print status to the screen
|
||||
Robot.text("Excuting...",5,70);
|
||||
|
||||
Robot.text("Excuting...", 5, 70);
|
||||
|
||||
// read through the array and move accordingly
|
||||
for(int i=0; i<20; i++) {
|
||||
switch(commands[i]) {
|
||||
for (int i = 0; i < 20; i++) {
|
||||
switch (commands[i]) {
|
||||
case BUTTON_LEFT:
|
||||
Robot.turn(-90);
|
||||
break;
|
||||
@ -103,10 +103,10 @@ void executeCommands() {
|
||||
return;
|
||||
}
|
||||
// print the current command to the screen
|
||||
Robot.stroke(255,0,0);
|
||||
Robot.stroke(255, 0, 0);
|
||||
PrintCommandI(i, 86);
|
||||
delay(1000);
|
||||
|
||||
|
||||
// stop moving for a second
|
||||
Robot.motorsStop();
|
||||
delay(1000);
|
||||
@ -115,7 +115,7 @@ void executeCommands() {
|
||||
|
||||
// convert the button press to a single character
|
||||
char keyToChar(int key) {
|
||||
switch(key) {
|
||||
switch (key) {
|
||||
case BUTTON_LEFT:
|
||||
return '<';
|
||||
case BUTTON_RIGHT:
|
||||
@ -129,6 +129,6 @@ char keyToChar(int key) {
|
||||
|
||||
// display a command
|
||||
void PrintCommandI(int i, int originY) {
|
||||
Robot.text(keyToChar(commands[i]), i%14*8+5, i/14*10+originY);
|
||||
Robot.text(keyToChar(commands[i]), i % 14 * 8 + 5, i / 14 * 10 + originY);
|
||||
}
|
||||
|
||||
|
@ -1,19 +1,19 @@
|
||||
/* Robot Line Follow
|
||||
|
||||
This sketch demonstrates the line following capabilities
|
||||
of the Arduino Robot. On the floor, place some black
|
||||
of the Arduino Robot. On the floor, place some black
|
||||
electrical tape along the path you wish the robot to follow.
|
||||
To indicate a stopping point, place another piece of tape
|
||||
perpendicular to the path.
|
||||
|
||||
Circuit:
|
||||
* Arduino Robot
|
||||
|
||||
|
||||
created 1 May 2013
|
||||
by X. Yang
|
||||
modified 12 May 2013
|
||||
by D. Cuartielles
|
||||
|
||||
|
||||
This example is in the public domain
|
||||
*/
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
long timerOrigin; // used for counting elapsed time
|
||||
|
||||
void setup() {
|
||||
// initialize the Robot, SD card, display, and speaker
|
||||
// initialize the Robot, SD card, display, and speaker
|
||||
Robot.begin();
|
||||
Robot.beginTFT();
|
||||
Robot.beginSD();
|
||||
@ -30,45 +30,45 @@ void setup() {
|
||||
|
||||
// show the logots on the TFT screen
|
||||
Robot.displayLogos();
|
||||
|
||||
|
||||
Robot.drawBMP("lf.bmp", 0, 0); // display background image
|
||||
|
||||
Robot.playFile("chase.sqm"); // play a song from the SD card
|
||||
|
||||
|
||||
// add the instructions
|
||||
Robot.text("Line Following\n\n place the robot on\n the track and \n see it run", 5, 5);
|
||||
Robot.text("Press the middle\n button to start...", 5, 61);
|
||||
Robot.waitContinue();
|
||||
|
||||
// These are some general values that work for line following
|
||||
// These are some general values that work for line following
|
||||
// uncomment one or the other to see the different behaviors of the robot
|
||||
//Robot.lineFollowConfig(14, 9, 50, 10);
|
||||
Robot.lineFollowConfig(11, 7, 60, 5);
|
||||
|
||||
|
||||
|
||||
|
||||
//set the motor board into line-follow mode
|
||||
Robot.setMode(MODE_LINE_FOLLOW);
|
||||
|
||||
Robot.setMode(MODE_LINE_FOLLOW);
|
||||
|
||||
// start
|
||||
Robot.fill(255, 255, 255);
|
||||
Robot.stroke(255, 255, 255);
|
||||
Robot.rect(0, 0, 128, 80); // erase the previous text
|
||||
Robot.stroke(0, 0, 0);
|
||||
Robot.text("Start", 5, 5);
|
||||
|
||||
|
||||
Robot.stroke(0, 0, 0); // choose color for the text
|
||||
Robot.text("Time passed:", 5, 21); // write some text to the screen
|
||||
|
||||
timerOrigin=millis(); // keep track of the elapsed time
|
||||
|
||||
while(!Robot.isActionDone()) { //wait for the finish signal
|
||||
Robot.debugPrint(millis()-timerOrigin, 5, 29); // show how much time has passed
|
||||
|
||||
timerOrigin = millis(); // keep track of the elapsed time
|
||||
|
||||
while (!Robot.isActionDone()) { //wait for the finish signal
|
||||
Robot.debugPrint(millis() - timerOrigin, 5, 29); // show how much time has passed
|
||||
}
|
||||
|
||||
Robot.stroke(0, 0, 0);
|
||||
|
||||
Robot.stroke(0, 0, 0);
|
||||
Robot.text("Done!", 5, 45);
|
||||
}
|
||||
void loop() {
|
||||
//nothing here, the program only runs once. Reset the robot
|
||||
//nothing here, the program only runs once. Reset the robot
|
||||
//to do it again!
|
||||
}
|
||||
|
@ -1,18 +1,18 @@
|
||||
/* Disco Bot
|
||||
|
||||
This sketch shows you how to use the melody playing
|
||||
feature of the robot, with some really cool 8-bit music.
|
||||
Music will play when the robot is turned on, and it
|
||||
This sketch shows you how to use the melody playing
|
||||
feature of the robot, with some really cool 8-bit music.
|
||||
Music will play when the robot is turned on, and it
|
||||
will show you some dance moves.
|
||||
|
||||
Circuit:
|
||||
* Arduino Robot
|
||||
|
||||
|
||||
created 1 May 2013
|
||||
by X. Yang
|
||||
modified 12 May 2013
|
||||
by D. Cuartielles
|
||||
|
||||
|
||||
This example is in the public domain
|
||||
*/
|
||||
|
||||
@ -25,12 +25,12 @@
|
||||
F: go forward
|
||||
B: go backwards
|
||||
|
||||
The number after each command determines how long
|
||||
The number after each command determines how long
|
||||
each step lasts. Each number is 1/2 second long.
|
||||
|
||||
The "\0" indicates end of string
|
||||
*/
|
||||
char danceScript[] = "S4L1R1S2F1B1S1\0";
|
||||
char danceScript[] = "S4L1R1S2F1B1S1\0";
|
||||
|
||||
int currentScript = 0; // what step are we at
|
||||
|
||||
@ -49,34 +49,34 @@ long waitFrom;
|
||||
long waitTime = 0;
|
||||
|
||||
void setup() {
|
||||
// initialize the Robot, SD card, display, and speaker
|
||||
// initialize the Robot, SD card, display, and speaker
|
||||
Robot.begin();
|
||||
Robot.beginSpeaker();
|
||||
Robot.beginSD();
|
||||
Robot.beginTFT();
|
||||
|
||||
|
||||
// draw "lg0.bmp" and "lg1.bmp" on the screen
|
||||
Robot.displayLogos();
|
||||
|
||||
|
||||
// Print instructions to the screen
|
||||
Robot.text("1. Use left and\n right key to switch\n song", 5, 5);
|
||||
Robot.text("2. Put robot on the\n ground to dance", 5, 33);
|
||||
|
||||
// wait for a few soconds
|
||||
delay(3000);
|
||||
|
||||
|
||||
setInterface(); // display the current song
|
||||
play(0); //play the first song in the array
|
||||
|
||||
|
||||
resetWait(); //Initialize non-blocking delay
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the butttons on the robot
|
||||
int key = Robot.keyboardRead();
|
||||
|
||||
|
||||
// Right/left buttons play next/previous song
|
||||
switch(key) {
|
||||
switch (key) {
|
||||
case BUTTON_UP:
|
||||
case BUTTON_LEFT:
|
||||
play(-1); //play previous song
|
||||
@ -86,25 +86,25 @@ void loop() {
|
||||
play(1); //play next song
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// dance!
|
||||
runScript();
|
||||
}
|
||||
|
||||
// Dancing function
|
||||
void runScript() {
|
||||
if(!waiting()) { // if the previous instructions have finished
|
||||
// get the next 2 commands (direction and duration)
|
||||
parseCommand(danceScript[currentScript], danceScript[currentScript+1]);
|
||||
void runScript() {
|
||||
if (!waiting()) { // if the previous instructions have finished
|
||||
// get the next 2 commands (direction and duration)
|
||||
parseCommand(danceScript[currentScript], danceScript[currentScript + 1]);
|
||||
currentScript += 2;
|
||||
if(danceScript[currentScript] == '\0') // at the end of the array
|
||||
if (danceScript[currentScript] == '\0') // at the end of the array
|
||||
currentScript = 0; // start again at the beginning
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// instead of delay, use this timer
|
||||
boolean waiting() {
|
||||
if(millis()-waitFrom >= waitTime)
|
||||
if (millis() - waitFrom >= waitTime)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
@ -122,9 +122,9 @@ void resetWait() {
|
||||
}
|
||||
|
||||
// read the direction and dirstion of the steps
|
||||
void parseCommand(char dir, char duration) {
|
||||
void parseCommand(char dir, char duration) {
|
||||
//convert the scripts to action
|
||||
switch(dir) {
|
||||
switch (dir) {
|
||||
case 'L':
|
||||
Robot.motorsWrite(-255, 255);
|
||||
break;
|
||||
@ -142,7 +142,7 @@ void parseCommand(char dir, char duration) {
|
||||
break;
|
||||
}
|
||||
//You can change "500" to change the pace of dancing
|
||||
wait(500*(duration-'0'));
|
||||
wait(500 * (duration - '0'));
|
||||
}
|
||||
|
||||
// display the song
|
||||
@ -154,10 +154,10 @@ void setInterface() {
|
||||
|
||||
// display the next song
|
||||
void select(int seq, boolean onOff) {
|
||||
if(onOff){//select
|
||||
if (onOff) { //select
|
||||
Robot.stroke(0, 0, 0);
|
||||
Robot.text(musics[seq], 0, 0);
|
||||
}else{//deselect
|
||||
} else { //deselect
|
||||
Robot.stroke(255, 255, 255);
|
||||
Robot.text(musics[seq], 0, 0);
|
||||
}
|
||||
@ -166,9 +166,9 @@ void select(int seq, boolean onOff) {
|
||||
// play the slected song
|
||||
void play(int seq) {
|
||||
select(currentSong, false);
|
||||
if(currentSong <= 0 && seq == -1) { //previous of 1st song?
|
||||
currentSong = SONGS_COUNT-1; //go to last song
|
||||
} else if(currentSong >= SONGS_COUNT-1 && seq == 1) { //next of last?
|
||||
if (currentSong <= 0 && seq == -1) { //previous of 1st song?
|
||||
currentSong = SONGS_COUNT - 1; //go to last song
|
||||
} else if (currentSong >= SONGS_COUNT - 1 && seq == 1) { //next of last?
|
||||
currentSong = 0; //go to 1st song
|
||||
} else {
|
||||
currentSong += seq; //next song
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user