Examples: mass code format. See example_formatter.conf

This commit is contained in:
Federico Fissore 2015-07-06 15:18:33 +02:00
parent 1af21b2233
commit 5e98cd8528
136 changed files with 1357 additions and 1447 deletions

View File

@ -8,17 +8,17 @@
* LED attached from pin 13 to ground.
* Note: on most Arduinos, there is already an LED on the board
that's attached to pin 13, so no hardware is needed for this example.
created 2005
by David A. Mellis
modified 8 Feb 2010
by Paul Stoffregen
modified 11 Nov 2013
by Scott Fitzgerald
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
*/
@ -40,8 +40,7 @@ void setup() {
pinMode(ledPin, OUTPUT);
}
void loop()
{
void loop() {
// here is where you'd put code that needs to be running all the time.
// check to see if it's time to blink the LED; that is, if the
@ -49,16 +48,17 @@ void loop()
// the LED is bigger than the interval at which you want to
// blink the LED.
unsigned long currentMillis = millis();
if(currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
if (ledState == LOW) {
ledState = HIGH;
else
} else {
ledState = LOW;
}
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);

View File

@ -48,8 +48,7 @@ void loop() {
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
} else {
// turn LED off:
digitalWrite(ledPin, LOW);
}

View File

@ -42,8 +42,7 @@ void loop() {
// button's pressed, and off when it's not:
if (sensorVal == HIGH) {
digitalWrite(13, LOW);
}
else {
} else {
digitalWrite(13, HIGH);
}
}

View File

@ -58,8 +58,7 @@ void loop() {
Serial.println("on");
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter);
}
else {
} else {
// if the current state is LOW then the button
// wend from on to off:
Serial.println("off");

View File

@ -41,7 +41,7 @@ void loop() {
analogWrite(analogOutPin, outputValue);
// print the results to the serial monitor:
Serial.print("sensor = " );
Serial.print("sensor = ");
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);

View File

@ -34,13 +34,13 @@ int average = 0; // the average
int inputPin = A0;
void setup()
{
void setup() {
// initialize serial communication with computer:
Serial.begin(9600);
// initialize all the readings to 0:
for (int thisReading = 0; thisReading < numReadings; thisReading++)
for (int thisReading = 0; thisReading < numReadings; thisReading++) {
readings[thisReading] = 0;
}
}
void loop() {
@ -54,9 +54,10 @@ void loop() {
readIndex = readIndex + 1;
// if we're at the end of the array...
if (readIndex >= numReadings)
if (readIndex >= numReadings) {
// ...wrap around to the beginning:
readIndex = 0;
}
// calculate the average:
average = total / numReadings;

View File

@ -23,8 +23,7 @@
const int ledPin = 9; // the pin that the LED is attached to
void setup()
{
void setup() {
// initialize the serial communication:
Serial.begin(9600);
// initialize the ledPin as an output:

View File

@ -65,15 +65,15 @@ void loop() {
// List all the available serial ports
// if using Processing 2.1 or later, use Serial.printArray()
println(Serial.list());
// I know that the first port in the serial list on my mac
// is always my Arduino, so I open Serial.list()[0].
// Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[0], 9600);
// don't generate a serialEvent() unless you get a newline character:
myPort.bufferUntil('\n');
// set inital background:
background(0);
}

View File

@ -78,19 +78,19 @@ void loop() {
size(200, 200);
boxX = width/2.0;
boxY = height/2.0;
rectMode(RADIUS);
// List all the available serial ports in the output pane.
// You will need to choose the port that the Arduino board is
// connected to from this list. The first port in the list is
// port #0 and the third port in the list is port #2.
rectMode(RADIUS);
// List all the available serial ports in the output pane.
// You will need to choose the port that the Arduino board is
// connected to from this list. The first port in the list is
// port #0 and the third port in the list is port #2.
// if using Processing 2.1 or later, use Serial.printArray()
println(Serial.list());
// Open the port that the Arduino board is connected to (in this case #0)
// Make sure to open the port at the same speed Arduino is using (9600bps)
port = new Serial(this, Serial.list()[0], 9600);
println(Serial.list());
// Open the port that the Arduino board is connected to (in this case #0)
// Make sure to open the port at the same speed Arduino is using (9600bps)
port = new Serial(this, Serial.list()[0], 9600);
}
void draw()

View File

@ -29,8 +29,7 @@ int secondSensor = 0; // second analog sensor
int thirdSensor = 0; // digital sensor
int inByte = 0; // incoming serial byte
void setup()
{
void setup() {
// start serial port at 9600 bps:
Serial.begin(9600);
while (!Serial) {
@ -41,8 +40,7 @@ void setup()
establishContact(); // send a byte to establish contact until receiver responds
}
void loop()
{
void loop() {
// if we get a valid byte, read analog ins:
if (Serial.available() > 0) {
// get incoming byte:

View File

@ -33,8 +33,7 @@ int secondSensor = 0; // second analog sensor
int thirdSensor = 0; // digital sensor
int inByte = 0; // incoming serial byte
void setup()
{
void setup() {
// start serial port at 9600 bps and wait for port to open:
Serial.begin(9600);
while (!Serial) {
@ -46,8 +45,7 @@ void setup()
establishContact(); // send a byte to establish contact until receiver responds
}
void loop()
{
void loop() {
// if we get a valid byte, read analog ins:
if (Serial.available() > 0) {
// get incoming byte:

View File

@ -20,13 +20,11 @@ const int redPin = A0; // sensor to control red color
const int greenPin = A1; // sensor to control green color
const int bluePin = A2; // sensor to control blue color
void setup()
{
void setup() {
Serial.begin(9600);
}
void loop()
{
void loop() {
Serial.print(analogRead(redPin));
Serial.print(",");
Serial.print(analogRead(greenPin));
@ -52,7 +50,7 @@ void loop()
// List all the available serial ports
// if using Processing 2.1 or later, use Serial.printArray()
println(Serial.list());
// I know that the first port in the serial list on my mac
// is always my Arduino, so I open Serial.list()[0].
// Open whatever port is the one you're using.

View File

@ -44,8 +44,7 @@ void loop() {
// if the analog value is high enough, turn on the LED:
if (analogValue > threshold) {
digitalWrite(ledPin, HIGH);
}
else {
} else {
digitalWrite(ledPin, LOW);
}

View File

@ -43,8 +43,8 @@ int sensorValue = 0; // the sensor value
void setup() {
// set the LED pins as outputs and the switch pin as input:
pinMode(indicatorLedPin, OUTPUT);
pinMode (ledPin, OUTPUT);
pinMode (buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop() {

View File

@ -33,8 +33,7 @@ const int xpin = A3; // x-axis of the accelerometer
const int ypin = A2; // y-axis
const int zpin = A1; // z-axis (only on 3-axis models)
void setup()
{
void setup() {
// initialize the serial communications:
Serial.begin(9600);
@ -48,8 +47,7 @@ void setup()
digitalWrite(powerpin, HIGH);
}
void loop()
{
void loop() {
// print the sensor values:
Serial.print(analogRead(xpin));
// print a tab between values:

View File

@ -31,8 +31,7 @@ void setup() {
Serial.begin(9600);
}
void loop()
{
void loop() {
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration, inches, cm;
@ -65,8 +64,7 @@ void loop()
delay(100);
}
long microsecondsToInches(long microseconds)
{
long microsecondsToInches(long microseconds) {
// According to Parallax's datasheet for the PING))), there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
// second). This gives the distance travelled by the ping, outbound
@ -75,8 +73,7 @@ long microsecondsToInches(long microseconds)
return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds)
{
long microsecondsToCentimeters(long microseconds) {
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.

View File

@ -25,7 +25,7 @@ void setup() {
stringOne = String("stringThree = ");
stringTwo = String("this string");
stringThree = String ();
stringThree = String();
// send an intro:
Serial.println("\n\nAdding strings together (concatenation):");
Serial.println();

View File

@ -49,16 +49,14 @@ void loop() {
// you can also use equals() to see if two strings are the same:
if (stringOne.equals(stringTwo)) {
Serial.println(stringOne + " equals " + stringTwo);
}
else {
} else {
Serial.println(stringOne + " does not equal " + stringTwo);
}
// or perhaps you want to ignore case:
if (stringOne.equalsIgnoreCase(stringTwo)) {
Serial.println(stringOne + " equals (ignoring case) " + stringTwo);
}
else {
} else {
Serial.println(stringOne + " does not equal (ignoring case) " + stringTwo);
}
@ -103,10 +101,9 @@ void loop() {
// comes first in alphanumeric order, then compareTo() is greater than 0:
stringOne = "Cucumber";
stringTwo = "Cucuracha";
if (stringOne.compareTo(stringTwo) < 0 ) {
if (stringOne.compareTo(stringTwo) < 0) {
Serial.println(stringOne + " comes before " + stringTwo);
}
else {
} else {
Serial.println(stringOne + " comes after " + stringTwo);
}
@ -121,10 +118,9 @@ void loop() {
stringOne += analogRead(A0);
stringTwo += analogRead(A5);
if (stringOne.compareTo(stringTwo) < 0 ) {
if (stringOne.compareTo(stringTwo) < 0) {
Serial.println(stringOne + " comes before " + stringTwo);
}
else {
} else {
Serial.println(stringOne + " comes after " + stringTwo);
}

View File

@ -33,7 +33,7 @@ void loop() {
stringOne = "<HTML><HEAD><BODY>";
int secondOpeningBracket = firstClosingBracket + 1;
int secondClosingBracket = stringOne.indexOf('>', secondOpeningBracket );
int secondClosingBracket = stringOne.indexOf('>', secondOpeningBracket);
Serial.println("The index of the second > in the string " + stringOne + " is " + secondClosingBracket);
// you can also use indexOf() to search for Strings:
@ -43,7 +43,7 @@ void loop() {
stringOne = "<UL><LI>item<LI>item<LI>item</UL>";
int firstListItem = stringOne.indexOf("<LI>");
int secondListItem = stringOne.indexOf("item", firstListItem + 1 );
int secondListItem = stringOne.indexOf("item", firstListItem + 1);
Serial.println("The index of the second list item in the string " + stringOne + " is " + secondClosingBracket);
// lastIndexOf() gives you the last occurrence of a character or string:

View File

@ -41,8 +41,7 @@ void loop() {
// if the String's longer than 140 characters, complain:
if (txtMsg.length() < 140) {
Serial.println("That's a perfectly acceptable text message");
}
else {
} else {
Serial.println("That's too long for a text message.");
}
// note the length for next time through the loop:

View File

@ -41,11 +41,10 @@ void loop() {
// endsWith() checks to see if a String ends with a particular character:
String sensorReading = "sensor = ";
sensorReading += analogRead(A0);
Serial.print (sensorReading);
Serial.print(sensorReading);
if (sensorReading.endsWith("0")) {
Serial.println(". This reading is divisible by ten");
}
else {
} else {
Serial.println(". This reading is not divisible by ten");
}

View File

@ -1,22 +1,22 @@
/*
/*
Keyboard Message test
For the Arduino Leonardo and Micro.
Sends a text string when a button is pressed.
The circuit:
* pushbutton attached from pin 4 to +5V
* 10-kilohm resistor attached from pin 4 to ground
created 24 Oct 2011
modified 27 Mar 2012
by Tom Igoe
modified 11 Nov 2013
by Scott Fitzgerald
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/KeyboardMessage
*/

View File

@ -21,7 +21,7 @@
by Tom Igoe
modified 3 May 2014
by Scott Fitzgerald
This example is in the public domain
http://www.arduino.cc/en/Tutorial/KeyboardReprogram
@ -58,7 +58,7 @@ void loop() {
// wait for new window to open:
delay(1000);
// versions of the Arduino IDE after 1.5 pre-populate
// versions of the Arduino IDE after 1.5 pre-populate
// new sketches with setup() and loop() functions
// let's clear the window before typing anything new
// select all

View File

@ -44,7 +44,7 @@ void loop() {
switchstate = digitalRead(2);
// if the button is not pressed
// turn on the green LED and off the red LEDs
// turn on the green LED and off the red LEDs
if (switchstate == LOW) {
digitalWrite(3, HIGH); // turn the green LED on pin 3 on
digitalWrite(4, LOW); // turn the red LED on pin 4 off
@ -52,7 +52,7 @@ void loop() {
}
// this else is part of the above if() statement.
// if the switch is not LOW (the button is pressed)
// turn off the green LED and blink alternatively the red LEDs
// turn off the green LED and blink alternatively the red LEDs
else {
digitalWrite(3, LOW); // turn the green LED on pin 3 off
digitalWrite(4, LOW); // turn the red LED on pin 4 off

View File

@ -40,20 +40,16 @@ void loop() {
if (keyVal == 1023) {
// play the first frequency in the array on pin 8
tone(8, notes[0]);
}
else if (keyVal >= 990 && keyVal <= 1010) {
} else if (keyVal >= 990 && keyVal <= 1010) {
// play the second frequency in the array on pin 8
tone(8, notes[1]);
}
else if (keyVal >= 505 && keyVal <= 515) {
} else if (keyVal >= 505 && keyVal <= 515) {
// play the third frequency in the array on pin 8
tone(8, notes[2]);
}
else if (keyVal >= 5 && keyVal <= 10) {
} else if (keyVal >= 5 && keyVal <= 10) {
// play the fourth frequency in the array on pin 8
tone(8, notes[3]);
}
else {
} else {
// if the value is out of range, play no tone
noTone(8);
}

View File

@ -42,8 +42,7 @@ void loop() {
if (switchState == HIGH) {
// turn motor on:
digitalWrite(motorPin, HIGH);
}
else {
} else {
// turn motor off:
digitalWrite(motorPin, LOW);
}

View File

@ -84,8 +84,7 @@ void loop() {
if (motorDirection == 1) {
digitalWrite(controlPin1, HIGH);
digitalWrite(controlPin2, LOW);
}
else {
} else {
digitalWrite(controlPin1, LOW);
digitalWrite(controlPin2, HIGH);
}
@ -94,8 +93,7 @@ void loop() {
if (motorEnabled == 1) {
// PWM the enable pin to vary the speed
analogWrite(enablePin, motorSpeed);
}
else { // if the motor is not supposed to be on
} else { // if the motor is not supposed to be on
//turn the motor off
analogWrite(enablePin, 0);
}

View File

@ -100,7 +100,7 @@ void loop() {
Serial.println("the box is locked!");
// wait for the servo to move into position
delay (1000);
delay(1000);
}
}

View File

@ -105,8 +105,12 @@ parameter param;
uint8_t hbval = 128;
int8_t hbdelta = 8;
void heartbeat() {
if (hbval > 192) hbdelta = -hbdelta;
if (hbval < 32) hbdelta = -hbdelta;
if (hbval > 192) {
hbdelta = -hbdelta;
}
if (hbval < 32) {
hbdelta = -hbdelta;
}
hbval += hbdelta;
analogWrite(LED_HB, hbval);
delay(20);
@ -115,11 +119,17 @@ void heartbeat() {
void loop(void) {
// is pmode active?
if (pmode) digitalWrite(LED_PMODE, HIGH);
else digitalWrite(LED_PMODE, LOW);
if (pmode) {
digitalWrite(LED_PMODE, HIGH);
} else {
digitalWrite(LED_PMODE, LOW);
}
// is there an error?
if (error) digitalWrite(LED_ERR, HIGH);
else digitalWrite(LED_ERR, LOW);
if (error) {
digitalWrite(LED_ERR, HIGH);
} else {
digitalWrite(LED_ERR, LOW);
}
// light the heartbeat LED
heartbeat();
@ -145,13 +155,13 @@ void pulse(int pin, int times) {
delay(PTIME);
digitalWrite(pin, LOW);
delay(PTIME);
}
while (times--);
} while (times--);
}
void prog_lamp(int state) {
if (PROG_FLICKER)
if (PROG_FLICKER) {
digitalWrite(LED_PMODE, state);
}
}
void spi_init() {
@ -163,8 +173,7 @@ void spi_init() {
void spi_wait() {
do {
}
while (!(SPSR & (1 << SPIF)));
} while (!(SPSR & (1 << SPIF)));
}
uint8_t spi_send(uint8_t b) {
@ -188,8 +197,7 @@ void empty_reply() {
if (CRC_EOP == getch()) {
Serial.print((char)STK_INSYNC);
Serial.print((char)STK_OK);
}
else {
} else {
error++;
Serial.print((char)STK_NOSYNC);
}
@ -200,8 +208,7 @@ void breply(uint8_t b) {
Serial.print((char)STK_INSYNC);
Serial.print((char)b);
Serial.print((char)STK_OK);
}
else {
} else {
error++;
Serial.print((char)STK_NOSYNC);
}
@ -291,7 +298,9 @@ void flash(uint8_t hilo, int addr, uint8_t data) {
data);
}
void commit(int addr) {
if (PROG_FLICKER) prog_lamp(LOW);
if (PROG_FLICKER) {
prog_lamp(LOW);
}
spi_transaction(0x4C, (addr >> 8) & 0xFF, addr & 0xFF, 0);
if (PROG_FLICKER) {
delay(PTIME);
@ -301,10 +310,18 @@ void commit(int addr) {
//#define _current_page(x) (here & 0xFFFFE0)
int current_page(int addr) {
if (param.pagesize == 32) return here & 0xFFFFFFF0;
if (param.pagesize == 64) return here & 0xFFFFFFE0;
if (param.pagesize == 128) return here & 0xFFFFFFC0;
if (param.pagesize == 256) return here & 0xFFFFFF80;
if (param.pagesize == 32) {
return here & 0xFFFFFFF0;
}
if (param.pagesize == 64) {
return here & 0xFFFFFFE0;
}
if (param.pagesize == 128) {
return here & 0xFFFFFFC0;
}
if (param.pagesize == 256) {
return here & 0xFFFFFF80;
}
return here;
}
@ -314,8 +331,7 @@ void write_flash(int length) {
if (CRC_EOP == getch()) {
Serial.print((char) STK_INSYNC);
Serial.print((char) write_flash_pages(length));
}
else {
} else {
error++;
Serial.print((char) STK_NOSYNC);
}
@ -386,8 +402,7 @@ void program_page() {
if (CRC_EOP == getch()) {
Serial.print((char) STK_INSYNC);
Serial.print(result);
}
else {
} else {
error++;
Serial.print((char) STK_NOSYNC);
}
@ -437,8 +452,12 @@ void read_page() {
return;
}
Serial.print((char) STK_INSYNC);
if (memtype == 'F') result = flash_read_page(length);
if (memtype == 'E') result = eeprom_read_page(length);
if (memtype == 'F') {
result = flash_read_page(length);
}
if (memtype == 'E') {
result = eeprom_read_page(length);
}
Serial.print(result);
return;
}
@ -533,20 +552,21 @@ int avrisp() {
read_signature();
break;
// expecting a command, not CRC_EOP
// this is how we can get back in sync
// expecting a command, not CRC_EOP
// this is how we can get back in sync
case CRC_EOP:
error++;
Serial.print((char) STK_NOSYNC);
break;
// anything else we will return STK_UNKNOWN
// anything else we will return STK_UNKNOWN
default:
error++;
if (CRC_EOP == getch())
if (CRC_EOP == getch()) {
Serial.print((char)STK_UNKNOWN);
else
} else {
Serial.print((char)STK_NOSYNC);
}
}
}

44
examples_formatter.conf Normal file
View File

@ -0,0 +1,44 @@
# This configuration file contains a selection of the available options provided by the formatting tool "Artistic Style"
# http://astyle.sourceforge.net/astyle.html
#
# If you wish to change them, don't edit this file.
# Instead, copy it in the same folder of file "preferences.txt" and modify the copy. This way, you won't lose your custom formatter settings when upgrading the IDE
# If you don't know where file preferences.txt is stored, open the IDE, File -> Preferences and you'll find a link
mode=c
# 2 spaces indentation
indent=spaces=2
# also indent macros
indent-preprocessor
# indent classes, switches (and cases), comments starting at column 1
indent-classes
indent-switches
indent-cases
indent-col1-comments
# put a space around operators
pad-oper
# put a space after if/for/while
pad-header
# if you like one-liners, keep them
keep-one-line-statements
style=java
xn
xc
xl
xk
indent-modifiers
N
L
xW
w
xw
U
j

View File

@ -1,2 +1,2 @@
# you need to have astyle installed before running this
find libraries/ hardware/ -name '*.ino' -exec astyle --options=build/shared/lib/formatter.conf {} \;
find -name '*.ino' -exec /home/federico/materiale/works_Arduino/astyle/astyle-code/AStyle/build/gcc/bin/astyle --options=examples_formatter.conf {} \;

View File

@ -10,26 +10,28 @@
#include <EEPROM.h>
void setup()
{
void setup() {
/***
Iterate through each byte of the EEPROM storage.
Iterate through each byte of the EEPROM storage.
Larger AVR processors have larger EEPROM sizes, E.g:
- Arduno Duemilanove: 512b EEPROM storage.
- Arduino Uno: 1kb EEPROM storage.
- Arduino Mega: 4kb EEPROM storage.
Rather than hard-coding the length, you should use the pre-provided length function.
This will make your code portable to all AVR processors.
This will make your code portable to all AVR processors.
***/
for ( int i = 0 ; i < EEPROM.length() ; i++ )
for (int i = 0 ; i < EEPROM.length() ; i++) {
EEPROM.write(i, 0);
}
// turn the LED on when we're done
digitalWrite(13, HIGH);
}
void loop(){ /** Empty loop. **/ }
void loop() {
/** Empty loop. **/
}

View File

@ -1,7 +1,7 @@
/***
Written by Christopher Andrews.
CRC algorithm generated by pycrc, MIT licence ( https://github.com/tpircher/pycrc ).
A CRC is a simple way of checking whether data has changed or become corrupted.
This example calculates a CRC value directly on the EEPROM values.
The purpose of this example is to highlight how the EEPROM object can be used just like an array.
@ -10,8 +10,8 @@
#include <Arduino.h>
#include <EEPROM.h>
void setup(){
void setup() {
//Start serial
Serial.begin(9600);
while (!Serial) {
@ -19,31 +19,33 @@ void setup(){
}
//Print length of data to run CRC on.
Serial.print( "EEPROM length: " );
Serial.println( EEPROM.length() );
Serial.print("EEPROM length: ");
Serial.println(EEPROM.length());
//Print the result of calling eeprom_crc()
Serial.print( "CRC32 of EEPROM data: 0x" );
Serial.println( eeprom_crc(), HEX );
Serial.print( "\n\nDone!" );
Serial.print("CRC32 of EEPROM data: 0x");
Serial.println(eeprom_crc(), HEX);
Serial.print("\n\nDone!");
}
void loop(){ /* Empty loop */ }
void loop() {
/* Empty loop */
}
unsigned long eeprom_crc(void) {
unsigned long eeprom_crc( void ){
const unsigned long crc_table[16] = {
0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c,
0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
};
0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c,
0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
};
unsigned long crc = ~0L;
for( int index = 0 ; index < EEPROM.length() ; ++index ){
crc = crc_table[( crc ^ EEPROM[index] ) & 0x0f] ^ (crc >> 4);
crc = crc_table[( crc ^ ( EEPROM[index] >> 4 )) & 0x0f] ^ (crc >> 4);
for (int index = 0 ; index < EEPROM.length() ; ++index) {
crc = crc_table[(crc ^ EEPROM[index]) & 0x0f] ^ (crc >> 4);
crc = crc_table[(crc ^ (EEPROM[index] >> 4)) & 0x0f] ^ (crc >> 4);
crc = ~crc;
}
return crc;

View File

@ -1,66 +1,68 @@
/***
eeprom_get example.
This shows how to use the EEPROM.get() method.
To pre-set the EEPROM data, run the example sketch eeprom_put.
This sketch will run without it, however, the values shown
This sketch will run without it, however, the values shown
will be shown from what ever is already on the EEPROM.
This may cause the serial object to print out a large string
of garbage if there is no null character inside one of the strings
loaded.
Written by Christopher Andrews 2015
Released under MIT licence.
Released under MIT licence.
***/
#include <EEPROM.h>
void setup(){
void setup() {
float f = 0.00f; //Variable to store data read from EEPROM.
int eeAddress = 0; //EEPROM address to start reading from
Serial.begin( 9600 );
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.print( "Read float from EEPROM: " );
Serial.print("Read float from EEPROM: ");
//Get the float data from the EEPROM at position 'eeAddress'
EEPROM.get( eeAddress, f );
Serial.println( f, 3 ); //This may print 'ovf, nan' if the data inside the EEPROM is not a valid float.
EEPROM.get(eeAddress, f);
Serial.println(f, 3); //This may print 'ovf, nan' if the data inside the EEPROM is not a valid float.
/***
As get also returns a reference to 'f', you can use it inline.
E.g: Serial.print( EEPROM.get( eeAddress, f ) );
***/
/***
Get can be used with custom structures too.
/***
Get can be used with custom structures too.
I have separated this into an extra function.
***/
secondTest(); //Run the next test.
}
struct MyObject{
struct MyObject {
float field1;
byte field2;
char name[10];
};
void secondTest(){
void secondTest() {
int eeAddress = sizeof(float); //Move address to the next byte after float 'f'.
MyObject customVar; //Variable to store custom object read from EEPROM.
EEPROM.get( eeAddress, customVar );
Serial.println( "Read custom object from EEPROM: " );
Serial.println( customVar.field1 );
Serial.println( customVar.field2 );
Serial.println( customVar.name );
EEPROM.get(eeAddress, customVar);
Serial.println("Read custom object from EEPROM: ");
Serial.println(customVar.field1);
Serial.println(customVar.field2);
Serial.println(customVar.name);
}
void loop(){ /* Empty loop */ }
void loop() {
/* Empty loop */
}

View File

@ -1,12 +1,12 @@
/***
eeprom_iteration example.
A set of example snippets highlighting the
simplest methods for traversing the EEPROM.
Running this sketch is not necessary, this is
Running this sketch is not necessary, this is
simply highlighting certain programming methods.
Written by Christopher Andrews 2015
Released under MIT licence.
***/
@ -18,40 +18,40 @@ void setup() {
/***
Iterate the EEPROM using a for loop.
***/
for( int index = 0 ; index < EEPROM.length() ; index++ ){
for (int index = 0 ; index < EEPROM.length() ; index++) {
//Add one to each cell in the EEPROM
EEPROM[ index ] += 1;
}
/***
Iterate the EEPROM using a while loop.
***/
int index = 0;
while( index < EEPROM.length() ){
while (index < EEPROM.length()) {
//Add one to each cell in the EEPROM
EEPROM[ index ] += 1;
EEPROM[ index ] += 1;
index++;
}
/***
Iterate the EEPROM using a do-while loop.
***/
int idx = 0; //Used 'idx' to avoid name conflict with 'index' above.
do{
do {
//Add one to each cell in the EEPROM
EEPROM[ idx ] += 1;
EEPROM[ idx ] += 1;
idx++;
}while( idx < EEPROM.length() );
} while (idx < EEPROM.length());
} //End of setup function.
void loop(){}
void loop() {}

View File

@ -1,28 +1,28 @@
/***
eeprom_put example.
This shows how to use the EEPROM.put() method.
Also, this sketch will pre-set the EEPROM data for the
Also, this sketch will pre-set the EEPROM data for the
example sketch eeprom_get.
Note, unlike the single byte version EEPROM.write(),
the put method will use update semantics. As in a byte
will only be written to the EEPROM if the data is actually
different.
Written by Christopher Andrews 2015
Released under MIT licence.
Released under MIT licence.
***/
#include <EEPROM.h>
struct MyObject{
struct MyObject {
float field1;
byte field2;
char name[10];
};
void setup(){
void setup() {
Serial.begin(9600);
while (!Serial) {
@ -31,15 +31,15 @@ void setup(){
float f = 123.456f; //Variable to store in EEPROM.
int eeAddress = 0; //Location we want the data to be put.
//One simple call, with the address first and the object second.
EEPROM.put( eeAddress, f );
EEPROM.put(eeAddress, f);
Serial.println("Written float data type!");
/** Put is designed for use with custom structures also. **/
//Data to store.
MyObject customVar = {
3.14f,
@ -48,9 +48,11 @@ void setup(){
};
eeAddress += sizeof(float); //Move address to the next byte after float 'f'.
EEPROM.put( eeAddress, customVar );
Serial.print( "Written custom data type! \n\nView the example sketch eeprom_get to see how you can retrieve the values!" );
EEPROM.put(eeAddress, customVar);
Serial.print("Written custom data type! \n\nView the example sketch eeprom_get to see how you can retrieve the values!");
}
void loop(){ /* Empty loop */ }
void loop() {
/* Empty loop */
}

View File

@ -12,8 +12,7 @@
int address = 0;
byte value;
void setup()
{
void setup() {
// initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
@ -21,8 +20,7 @@ void setup()
}
}
void loop()
{
void loop() {
// read a byte from the current address of the EEPROM
value = EEPROM.read(address);
@ -32,24 +30,25 @@ void loop()
Serial.println();
/***
Advance to the next address, when at the end restart at the beginning.
Advance to the next address, when at the end restart at the beginning.
Larger AVR processors have larger EEPROM sizes, E.g:
- Arduno Duemilanove: 512b EEPROM storage.
- Arduino Uno: 1kb EEPROM storage.
- Arduino Mega: 4kb EEPROM storage.
Rather than hard-coding the length, you should use the pre-provided length function.
This will make your code portable to all AVR processors.
This will make your code portable to all AVR processors.
***/
address = address + 1;
if(address == EEPROM.length())
if (address == EEPROM.length()) {
address = 0;
}
/***
As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an
As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an
EEPROM address is also doable by a bitwise and of the length - 1.
++address &= EEPROM.length() - 1;
***/

View File

@ -1,13 +1,13 @@
/***
EEPROM Update method
Stores values read from analog input 0 into the EEPROM.
These values will stay in the EEPROM when the board is
turned off and may be retrieved later by another sketch.
If a value has not changed in the EEPROM, it is not overwritten
which would reduce the life span of the EEPROM unnecessarily.
Released using MIT licence.
***/
@ -16,10 +16,11 @@
/** the current address in the EEPROM (i.e. which byte we're going to write to next) **/
int address = 0;
void setup(){ /** EMpty setup **/ }
void setup() {
/** EMpty setup **/
}
void loop()
{
void loop() {
/***
need to divide by 4 because analog inputs range from
0 to 1023 and each byte of the EEPROM can only hold a
@ -33,35 +34,36 @@ void loop()
turned off.
***/
EEPROM.update(address, val);
/***
The function EEPROM.update(address, val) is equivalent to the following:
if( EEPROM.read(address) != val ){
EEPROM.write(address, val);
}
***/
/***
Advance to the next address, when at the end restart at the beginning.
Advance to the next address, when at the end restart at the beginning.
Larger AVR processors have larger EEPROM sizes, E.g:
- Arduno Duemilanove: 512b EEPROM storage.
- Arduino Uno: 1kb EEPROM storage.
- Arduino Mega: 4kb EEPROM storage.
Rather than hard-coding the length, you should use the pre-provided length function.
This will make your code portable to all AVR processors.
This will make your code portable to all AVR processors.
***/
address = address + 1;
if(address == EEPROM.length())
if (address == EEPROM.length()) {
address = 0;
}
/***
As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an
As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an
EEPROM address is also doable by a bitwise and of the length - 1.
++address &= EEPROM.length() - 1;
***/

View File

@ -9,18 +9,19 @@
#include <EEPROM.h>
/** the current address in the EEPROM (i.e. which byte we're going to write to next) **/
int addr = 0;
int addr = 0;
void setup(){ /** Empty setup. **/}
void setup() {
/** Empty setup. **/
}
void loop()
{
void loop() {
/***
Need to divide by 4 because analog inputs range from
0 to 1023 and each byte of the EEPROM can only hold a
value from 0 to 255.
***/
int val = analogRead(0) / 4;
/***
@ -28,28 +29,29 @@ void loop()
these values will remain there when the board is
turned off.
***/
EEPROM.write(addr, val);
/***
Advance to the next address, when at the end restart at the beginning.
Advance to the next address, when at the end restart at the beginning.
Larger AVR processors have larger EEPROM sizes, E.g:
- Arduno Duemilanove: 512b EEPROM storage.
- Arduino Uno: 1kb EEPROM storage.
- Arduino Mega: 4kb EEPROM storage.
Rather than hard-coding the length, you should use the pre-provided length function.
This will make your code portable to all AVR processors.
This will make your code portable to all AVR processors.
***/
addr = addr + 1;
if(addr == EEPROM.length())
if (addr == EEPROM.length()) {
addr = 0;
}
/***
As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an
As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an
EEPROM address is also doable by a bitwise and of the length - 1.
++addr &= EEPROM.length() - 1;
***/

View File

@ -85,7 +85,7 @@ void loop() {
}
//Read from or write to register from the SCP1000:
unsigned int readRegister(byte thisRegister, int bytesToRead ) {
unsigned int readRegister(byte thisRegister, int bytesToRead) {
byte inByte = 0; // incoming byte from the SPI
unsigned int result = 0; // result to return
Serial.print(thisRegister, BIN);
@ -117,7 +117,7 @@ unsigned int readRegister(byte thisRegister, int bytesToRead ) {
// take the chip select high to de-select:
digitalWrite(chipSelectPin, HIGH);
// return the result:
return(result);
return (result);
}

View File

@ -36,7 +36,7 @@ const int slaveSelectPin = 10;
void setup() {
// set the slaveSelectPin as an output:
pinMode (slaveSelectPin, OUTPUT);
pinMode(slaveSelectPin, OUTPUT);
// initialize SPI:
SPI.begin();
}

View File

@ -29,8 +29,7 @@
SoftwareSerial mySerial(10, 11); // RX, TX
void setup()
{
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(57600);
while (!Serial) {
@ -45,11 +44,12 @@ void setup()
mySerial.println("Hello, world?");
}
void loop() // run over and over
{
if (mySerial.available())
void loop() { // run over and over
if (mySerial.available()) {
Serial.write(mySerial.read());
if (Serial.available())
}
if (Serial.available()) {
mySerial.write(Serial.read());
}
}

View File

@ -42,8 +42,7 @@ SoftwareSerial portOne(10, 11);
// on the Mega, use other pins instead, since 8 and 9 don't work on the Mega
SoftwareSerial portTwo(8, 9);
void setup()
{
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
@ -56,8 +55,7 @@ void setup()
portTwo.begin(9600);
}
void loop()
{
void loop() {
// By default, the last intialized port is listening.
// when you want to listen on a port, explicitly select it:
portOne.listen();

View File

@ -12,16 +12,14 @@
#include <Wire.h>
void setup()
{
void setup() {
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial communication at 9600bps
}
int reading = 0;
void loop()
{
void loop() {
// step 1: instruct sensor to read echoes
Wire.beginTransmission(112); // transmit to device #112 (0x70)
// the address specified in the datasheet is 224 (0xE0)
@ -44,8 +42,7 @@ void loop()
Wire.requestFrom(112, 2); // request 2 bytes from slave device #112
// step 5: receive reading from sensor
if (2 <= Wire.available()) // if two bytes were received
{
if (2 <= Wire.available()) { // if two bytes were received
reading = Wire.read(); // receive high byte (overwrites previous reading)
reading = reading << 8; // shift high byte to be high 8 bits
reading |= Wire.read(); // receive low byte as lower 8 bits

View File

@ -14,15 +14,13 @@
#include <Wire.h>
void setup()
{
void setup() {
Wire.begin(); // join i2c bus (address optional for master)
}
byte val = 0;
void loop()
{
void loop() {
Wire.beginTransmission(44); // transmit to device #44 (0x2c)
// device address is specified in datasheet
Wire.write(byte(0x00)); // sends instruction byte
@ -30,8 +28,7 @@ void loop()
Wire.endTransmission(); // stop transmitting
val++; // increment value
if (val == 64) // if reached 64th position (max)
{
if (val == 64) { // if reached 64th position (max)
val = 0; // start over from lowest value
}
delay(500);

View File

@ -12,18 +12,15 @@
#include <Wire.h>
void setup()
{
void setup() {
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
}
void loop()
{
void loop() {
Wire.requestFrom(8, 6); // request 6 bytes from slave device #8
while (Wire.available()) // slave may send less than requested
{
while (Wire.available()) { // slave may send less than requested
char c = Wire.read(); // receive a byte as character
Serial.print(c); // print the character
}

View File

@ -12,15 +12,13 @@
#include <Wire.h>
void setup()
{
void setup() {
Wire.begin(); // join i2c bus (address optional for master)
}
byte x = 0;
void loop()
{
void loop() {
Wire.beginTransmission(8); // transmit to device #8
Wire.write("x is "); // sends five bytes
Wire.write(x); // sends one byte

View File

@ -12,24 +12,20 @@
#include <Wire.h>
void setup()
{
void setup() {
Wire.begin(8); // join i2c bus with address #8
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
}
void loop()
{
void loop() {
delay(100);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
while (1 < Wire.available()) // loop through all but the last
{
void receiveEvent(int howMany) {
while (1 < Wire.available()) { // loop through all but the last
char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
}

View File

@ -12,21 +12,18 @@
#include <Wire.h>
void setup()
{
void setup() {
Wire.begin(8); // join i2c bus with address #8
Wire.onRequest(requestEvent); // register event
}
void loop()
{
void loop() {
delay(100);
}
// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent()
{
void requestEvent() {
Wire.write("hello "); // respond with message of 6 bytes
// as expected by master
}

View File

@ -85,7 +85,7 @@ void loop() {
}
//Read from or write to register from the SCP1000:
unsigned int readRegister(byte thisRegister, int bytesToRead ) {
unsigned int readRegister(byte thisRegister, int bytesToRead) {
byte inByte = 0; // incoming byte from the SPI
unsigned int result = 0; // result to return
Serial.print(thisRegister, BIN);
@ -117,7 +117,7 @@ unsigned int readRegister(byte thisRegister, int bytesToRead ) {
// take the chip select high to de-select:
digitalWrite(chipSelectPin, HIGH);
// return the result:
return(result);
return (result);
}

View File

@ -36,7 +36,7 @@ const int slaveSelectPin = 10;
void setup() {
// set the slaveSelectPin as an output:
pinMode (slaveSelectPin, OUTPUT);
pinMode(slaveSelectPin, OUTPUT);
// initialize SPI:
SPI.begin();
}

View File

@ -22,8 +22,7 @@
#include <SPI.h>
#include <Audio.h>
void setup()
{
void setup() {
// debug output at 9600 baud
Serial.begin(9600);
@ -42,8 +41,7 @@ void setup()
Audio.begin(88200, 100);
}
void loop()
{
void loop() {
int count = 0;
// open wave file from sdcard

View File

@ -1,26 +1,26 @@
/*
Arduino Yún Bridge example
This example for the Arduino Yún 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.
This example for the Arduino Yún 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:
Possible commands created in this shetch:
* "/arduino/digital/13" -> digitalRead(13)
* "/arduino/digital/13/1" -> digitalWrite(13, HIGH)
* "/arduino/analog/2/123" -> analogWrite(2, 123)
* "/arduino/analog/2" -> analogRead(2)
* "/arduino/mode/13/input" -> pinMode(13, INPUT)
* "/arduino/mode/13/output" -> pinMode(13, OUTPUT)
"/arduino/digital/13" -> digitalRead(13)
"/arduino/digital/13/1" -> digitalWrite(13, HIGH)
"/arduino/analog/2/123" -> analogWrite(2, 123)
"/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
This example code is part of the public domain
http://www.arduino.cc/en/Tutorial/Bridge
http://www.arduino.cc/en/Tutorial/Bridge
*/
*/
#include <Bridge.h>
#include <BridgeServer.h>
@ -90,8 +90,7 @@ void digitalCommand(BridgeClient client) {
if (client.read() == '/') {
value = client.parseInt();
digitalWrite(pin, value);
}
else {
} else {
value = digitalRead(pin);
}
@ -130,8 +129,7 @@ void analogCommand(BridgeClient client) {
String key = "D";
key += pin;
Bridge.put(key, String(value));
}
else {
} else {
// Read analog pin
value = analogRead(pin);

View File

@ -49,8 +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
} else { // if the buffer is empty Cosole.read() returns -1
name += c; // append the read char from Console to the name string
}
} else {

View File

@ -43,7 +43,7 @@ void setup() {
}
void loop () {
void loop() {
// make a string that start with a timestamp for assembling the data to log:
String dataString;
dataString += getTimeStamp();
@ -93,8 +93,9 @@ String getTimeStamp() {
// read the output of the command
while (time.available() > 0) {
char c = time.read();
if (c != '\n')
if (c != '\n') {
result += c;
}
}
return result;

View File

@ -43,11 +43,9 @@ void loop() {
String message;
// if there is a message in the Mailbox
if (Mailbox.messageAvailable())
{
if (Mailbox.messageAvailable()) {
// read all the messages present in the queue
while (Mailbox.messageAvailable())
{
while (Mailbox.messageAvailable()) {
Mailbox.readMessage(message);
Serial.println(message);
}

View File

@ -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 Yún 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,100 +33,102 @@ 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");
// we give some time to arduino to connect to sandbox, otherwise the first sb.monitor(); call will give an error
delay(1000);
}
// connect to cloud spacebrew server at "sandbox.spacebrew.cc"
sb.connect("sandbox.spacebrew.cc");
// we give some time to arduino to connect to sandbox, otherwise the first sb.monitor(); call will give an error
delay(1000);
}
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();
}
}
delay(1000);
}
}
}
delay(1000);
}
// 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);
void handleRange(String route, int 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);
void handleString(String route, String 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");
void handleBoolean(String route, boolean value) {
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);
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);
}

View File

@ -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 Yún is connected to the internet for this example
to function properly.
The circuit:
- Button connected to Yún, 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,62 @@ 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");
}

View File

@ -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 Yún is connected to the internet for this example
to function properly.
The circuit:
- Potentiometer connected to Yún. 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);
}

View File

@ -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 Yún 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);
}

View File

@ -1,26 +1,26 @@
/*
GetYahooWeatherReport
Demonstrates making a request to the Yahoo! Weather API using Temboo from an Arduino Yún.
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 Yún is connected
to the Internet.
Looking for another API to use with your Arduino Yún? 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,25 +32,24 @@ 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();
}
void loop()
{
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 +57,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 +100,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.
*/

View File

@ -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 Yún.
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 Yún
is connected to the Internet.
Want to use another social API with your Arduino Yún? 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,25 +43,24 @@ 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()
{
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 +68,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 +77,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 +130,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 +158,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.
*/

View File

@ -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 Yún is connected
to the Internet.
Want to use another social API with your Arduino Yún? 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,29 +48,28 @@ void setup() {
// for debugging, wait until a serial console is connected
delay(4000);
while(!Serial);
while (!Serial);
Bridge.begin();
}
void loop()
{
void loop() {
// only try to send the tweet if we haven't already sent it successfully
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 +79,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 +106,7 @@ void loop()
char c = StatusesUpdateChoreo.read();
Serial.print(c);
}
}
}
StatusesUpdateChoreo.close();
// do nothing for the next 90 seconds
@ -124,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.
*/

View File

@ -5,46 +5,46 @@
Check out the latest Arduino & Temboo examples and tutorials 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
Instructions:
1. Create a Temboo account: http://www.temboo.com
2. Retrieve your Temboo application details: http://www.temboo.com/account/applications
3. Replace the values in the TembooAccount.h tab with your Temboo application details
4. You'll also need a Gmail account. Update the placeholder Gmail address in the code
4. You'll also need a Gmail account. Update the placeholder Gmail address in the code
below with your own details.
https://www.gmail.com
5. Once you have a Gmail account, turn on 2-step authentication, and create an application-specific
5. Once you have a Gmail account, turn on 2-step authentication, and create an application-specific
password to allow Temboo to access your Google account: https://www.google.com/landing/2step/.
6. After you've enabled 2-Step authentication, you'll need to create an App Password:
https://security.google.com/settings/security/apppasswords
7. In the "Select app" dropdown menu, choose "Other", and give your app a name (e.g., TembooApp).
8. Click "Generate". You'll be given a 16-digit passcode that can be used to access your Google Account from Temboo.
9. Copy and paste this password into the code below, updating the GMAIL_APP_PASSWORD variable
10. Upload the sketch to your Arduino Yún and open the serial monitor
NOTE: You can test this Choreo and find the latest instructions on our website:
NOTE: You can test this Choreo and find the latest instructions on our website:
https://temboo.com/library/Library/Google/Gmail/SendEmail
You can also find an in-depth version of this example here:
https://temboo.com/arduino/yun/send-an-email
This example assumes basic familiarity with Arduino sketches, and that your Yún is connected
to the Internet.
Looking for another API to use with your Arduino Yún? We've got over 100 in our Library!
This example code is in the public domain.
@ -53,7 +53,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: ***/
@ -70,32 +70,31 @@ const String GMAIL_APP_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();
}
void loop()
{
void loop() {
// only try to send the email if we haven't already tried
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);
@ -103,13 +102,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 application specific password
SendEmailChoreo.addInput("Password", GMAIL_APP_PASSWORD);
@ -118,17 +117,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
@ -136,9 +135,9 @@ void loop()
char c = SendEmailChoreo.read();
Serial.print(c);
}
}
}
SendEmailChoreo.close();
// set the flag showing we've tried
attempted = true;
}
@ -152,15 +151,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.
*/

View File

@ -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 Yún is connected
to the Internet.
Looking for another API to use with your Arduino Yún? 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,25 +55,24 @@ 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();
}
void loop()
{
void loop() {
// only try to send the SMS if we haven't already sent it successfully
if (!attempted) {
Serial.println("Running SendAnSMS...");
// we need a Process object to send a Choreo request to Temboo
TembooChoreo SendSMSChoreo;
@ -81,7 +80,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 +90,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 +123,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 +139,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.
*/

View File

@ -5,48 +5,48 @@
Check out the latest Arduino & Temboo examples and tutorials 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
Instructions:
1. Create a Temboo account: http://www.temboo.com
2. Retrieve your Temboo application details: http://www.temboo.com/account/applications
3. Replace the values in the TembooAccount.h tab with your Temboo application details
4. You'll also need a Google Spreadsheet that includes a title in the first row
of each column that data will be written to. This example assumes there are two columns.
The first column is the time (in milliseconds) that the row was appended, and the second
4. You'll also need a Google Spreadsheet that includes a title in the first row
of each column that data will be written to. This example 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 |
------+-----------------
| |
| |
5. Google Spreadsheets requires you to authenticate via OAuth. Follow the steps
in the link below to find your ClientID, ClientSecret, and RefreshToken, and then
use those values to overwrite the placeholders in the code below.
in the link below to find your ClientID, ClientSecret, and RefreshToken, and then
use those values to overwrite the placeholders in the code below.
https://temboo.com/library/Library/Google/OAuth/
For the scope field, you need to use: https://spreadsheets.google.com/feeds/
Here's a video outlines how Temboo helps with the OAuth process:
Here's a video outlines how Temboo helps with the OAuth process:
https://www.temboo.com/videos#oauthchoreos
And here's a more in-depth version of this example on our website:
And here's a more in-depth version of this example on our website:
https://temboo.com/arduino/yun/update-google-spreadsheet
6. Next, upload the sketch to your Arduino Yún and open the serial monitor
Note: you can test this Choreo and find the latest instructions on our website:
https://temboo.com/library/Library/Google/Spreadsheets/AppendRow/
Looking for another API to use with your Arduino Yún? We've got over 100 in our Library!
This example code is in the public domain.
@ -56,7 +56,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: ***/
@ -81,25 +81,24 @@ 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();
Serial.println("Done");
}
void loop()
{
void loop() {
// get the number of milliseconds this sketch has been running
unsigned long now = millis();
@ -108,7 +107,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
@ -123,19 +122,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 application client ID
AppendRowChoreo.addInput("ClientID", CLIENT_ID);
// your Google application client secert
@ -156,7 +155,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
@ -164,7 +163,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();
@ -176,7 +175,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);
}
@ -189,15 +188,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.
*/

View File

@ -1,28 +1,28 @@
/*
ToxicFacilitiesSearch
Demonstrates making a request to the Envirofacts API using Temboo from an Arduino Yún.
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 Yún is connected
to the Internet.
Looking for another API to use with your Arduino Yún? 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,18 +32,17 @@ 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();
}
void loop()
{
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 +53,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 +82,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 +96,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 +117,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 +130,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 +156,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.
*/

View File

@ -4,9 +4,9 @@
Demonstrates sending a Facebook status update using Temboo from an Arduino Yún.
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
@ -17,17 +17,17 @@
This example assumes basic familiarity with Arduino sketches, and that your Yún
is connected to the Internet.
Want to use another social API with your Arduino Yún? 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.
*/

View File

@ -1,23 +1,23 @@
/*
UploadToDropbox
Demonstrates uploading a file to a Dropbox account using Temboo from an Arduino Yún.
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 Yún? 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,34 +57,33 @@ 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();
}
void loop()
{
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 +91,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 +102,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 +147,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 +193,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.
*/

View File

@ -41,13 +41,19 @@ void loop() {
if (lastSecond != seconds) { // if a second has passed
// print the time:
if (hours <= 9) Serial.print("0"); // adjust for 0-9
if (hours <= 9) {
Serial.print("0"); // adjust for 0-9
}
Serial.print(hours);
Serial.print(":");
if (minutes <= 9) Serial.print("0"); // adjust for 0-9
if (minutes <= 9) {
Serial.print("0"); // adjust for 0-9
}
Serial.print(minutes);
Serial.print(":");
if (seconds <= 9) Serial.print("0"); // adjust for 0-9
if (seconds <= 9) {
Serial.print("0"); // adjust for 0-9
}
Serial.println(seconds);
// restart the date process:

View File

@ -1,35 +1,35 @@
/*
Arduino Yún USB-to-Serial
Allows you to use the Yún's 32U4 processor as a
serial terminal for the Linux side on the Yún.
Allows you to use the Yún's 32U4 processor as a
serial terminal for the Linux side on the Yún.
Upload this to an Arduino Yún via serial (not WiFi) then open
the serial monitor at 115200 to see the boot process of Linux.
You can also use the serial monitor as a basic command line
interface for Linux using this sketch.
Upload this to an Arduino Yún via serial (not WiFi) then open
the serial monitor at 115200 to see the boot process of Linux.
You can also use the serial monitor as a basic command line
interface for Linux using this sketch.
From the serial monitor the following commands can be issued:
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
'~' followed by '~' -> Sends the bridge's shutdown command to
'~' 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
'~' followed by '~' -> Sends the bridge's shutdown command to
obtain the console.
The circuit:
* Arduino Yún
The circuit:
Arduino Yún
created March 2013
by Massimo Banzi
modified by Cristian Maglie
created March 2013
by Massimo Banzi
modified by Cristian Maglie
This example code is in the public domain.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/YunSerialTerminal
http://www.arduino.cc/en/Tutorial/YunSerialTerminal
*/
*/
long linuxBaud = 250000;
@ -65,8 +65,7 @@ void loop() {
Serial1.begin(500000); // set speed to 500000
Serial.println("Speed set to 500000");
} else if (c == '~') { // '~` key pressed?
// send "bridge shutdown" command
Serial1.write((uint8_t *)"\xff\0\0\x05XXXXX\x7f\xf9", 11);
Serial1.write((uint8_t *)"\xff\0\0\x05XXXXX\x7f\xf9", 11); // send "bridge shutdown" command
Serial.println("Sending bridge's shutdown command");
} else { // any other key pressed?
Serial1.write('~'); // write '~' to UART

View File

@ -14,13 +14,11 @@
#include <Esplora.h>
void setup()
{
void setup() {
Serial.begin(9600); // initialize serial communications with your computer
}
void loop()
{
void loop() {
int xAxis = Esplora.readAccelerometer(X_AXIS); // read the X axis
int yAxis = Esplora.readAccelerometer(Y_AXIS); // read the Y axis
int zAxis = Esplora.readAccelerometer(Z_AXIS); // read the Z axis

View File

@ -19,7 +19,7 @@
by Tom Igoe
Updated 8 March 2014
by Scott Fitzgerald
http://www.arduino.cc/en/Reference/EsploraReadJoystickSwitch
This example is in the public domain.
@ -27,14 +27,12 @@
#include <Esplora.h>
void setup()
{
void setup() {
Serial.begin(9600); // initialize serial communication with your computer
Mouse.begin(); // take control of the mouse
}
void loop()
{
void loop() {
int xValue = Esplora.readJoystickX(); // read the joystick's X position
int yValue = Esplora.readJoystickY(); // read the joystick's Y position
int button = Esplora.readJoystickSwitch(); // read the joystick pushbutton
@ -52,7 +50,7 @@ void loop()
if (button == 0) { // if the joystick button is pressed
Mouse.press(); // send a mouse click
} else {
Mouse.release(); // if it's not pressed, release the mouse button
Mouse.release(); // if it's not pressed, release the mouse button
}
delay(10); // a short delay before moving again

View File

@ -45,8 +45,7 @@ void loop() {
byte thisNote = map(slider, 0, 1023, 0, 13);
// play the note corresponding to the slider's position:
Esplora.tone(note[thisNote]);
}
else {
} else {
// if the button isn't pressed, turn the note off:
Esplora.noTone();
}

View File

@ -11,13 +11,11 @@
*/
#include <Esplora.h>
void setup()
{
void setup() {
Serial.begin(9600); // initialize serial communications with your computer
}
void loop()
{
void loop() {
// read the temperature sensor in Celsius, then Fahrenheit:
int celsius = Esplora.readTemperature(DEGREES_C);
int fahrenheit = Esplora.readTemperature(DEGREES_F);

View File

@ -103,8 +103,7 @@ void loop() {
*/
if (newState == PRESSED) {
Keyboard.press(keystrokes[thisButton]);
}
else if (newState == RELEASED) {
} else if (newState == RELEASED) {
Keyboard.release(keystrokes[thisButton]);
}
}

View File

@ -37,8 +37,9 @@ void setup() {
}
void loop() {
if (Serial.available())
if (Serial.available()) {
parseCommand();
}
}
/*

View File

@ -114,17 +114,19 @@ void loop() {
// let the RGB led blink green once per second, for 200ms.
unsigned int ms = millis() % 1000;
if (ms < 200)
if (ms < 200) {
Esplora.writeGreen(50);
else
} else {
Esplora.writeGreen(0);
}
Esplora.writeBlue(0);
}
else
} else
// while not active, keep a reassuring blue color coming
// from the Esplora...
{
Esplora.writeBlue(20);
}
}
@ -203,8 +205,9 @@ void checkSwitchPress() {
if (startBtn != lastStartBtn) {
if (startBtn == HIGH) { // button released
active = !active;
if (active)
if (active) {
justActivated = true;
}
}
lastStartBtn = startBtn;

View File

@ -1,7 +1,7 @@
/*
Advanced Chat Server
A more advanced server that distributes any incoming messages
A more advanced server that distributes any incoming messages
to all connected clients but the client the message comes from.
To use telnet to your device's IP address and type.
You can see the client's input in the serial monitor as well.
@ -26,10 +26,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);
@ -43,9 +44,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
}
@ -62,9 +63,9 @@ void loop() {
if (client) {
boolean newClient = true;
for (byte i=0;i<4;i++) {
for (byte i = 0; i < 4; i++) {
//check whether this client refers to the same socket as one of the existing instances:
if (clients[i]==client) {
if (clients[i] == client) {
newClient = false;
break;
}
@ -72,8 +73,8 @@ void loop() {
if (newClient) {
//check which of the existing clients can be overridden:
for (byte i=0;i<4;i++) {
if (!clients[i] && clients[i]!=client) {
for (byte i = 0; i < 4; i++) {
if (!clients[i] && clients[i] != client) {
clients[i] = client;
// clead out the input buffer:
client.flush();
@ -90,8 +91,8 @@ void loop() {
// read the bytes incoming from the client:
char thisChar = client.read();
// echo the bytes back to all other connected clients:
for (byte i=0;i<4;i++) {
if (clients[i] && (clients[i]!=client)) {
for (byte i = 0; i < 4; i++) {
if (clients[i] && (clients[i] != client)) {
clients[i].write(thisChar);
}
}
@ -99,7 +100,7 @@ void loop() {
Serial.write(thisChar);
}
}
for (byte i=0;i<4;i++) {
for (byte i = 0; i < 4; i++) {
if (!(clients[i].connected())) {
// client.stop() invalidates the internal socket-descriptor, so next use of == will allways return false;
clients[i].stop();

View File

@ -156,8 +156,7 @@ void listenForEthernetClients() {
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
} else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
@ -219,5 +218,5 @@ unsigned int readRegister(byte registerName, int numBytes) {
// take the chip select high to de-select:
digitalWrite(chipSelectPin, HIGH);
// return the result:
return(result);
return (result);
}

View File

@ -54,15 +54,13 @@ void setup() {
// if you get a connection, report back via serial:
if (client.connect(server, 10002)) {
Serial.println("connected");
}
else {
} else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop()
{
void loop() {
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {

View File

@ -45,17 +45,14 @@ 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)
{
if (i < 3) {
Serial.print(".");
}
}

View File

@ -37,8 +37,7 @@ byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing pack
// 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:
Serial.begin(9600);
while (!Serial) {
@ -56,13 +55,12 @@ void setup()
Udp.begin(localPort);
}
void loop()
{
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() ) {
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
@ -74,7 +72,7 @@ void loop()
// 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;
Serial.print("Seconds since Jan 1 1900 = " );
Serial.print("Seconds since Jan 1 1900 = ");
Serial.println(secsSince1900);
// now convert NTP time into everyday time:
@ -91,13 +89,13 @@ void loop()
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(':');
if ( ((epoch % 3600) / 60) < 10 ) {
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(':');
if ( (epoch % 60) < 10 ) {
if ((epoch % 60) < 10) {
// In the first 10 seconds of each minute, we'll want a leading '0'
Serial.print('0');
}
@ -108,8 +106,7 @@ void loop()
}
// send an NTP request to the time server at the given address
unsigned long sendNTPpacket(char* address)
{
unsigned long sendNTPpacket(char* address) {
// set all bytes in the buffer to 0
memset(packetBuffer, 0, NTP_PACKET_SIZE);
// Initialize values needed to form NTP request

View File

@ -59,15 +59,13 @@ void setup() {
client.println("Host: www.google.com");
client.println("Connection: close");
client.println();
}
else {
} else {
// kf you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop()
{
void loop() {
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {

View File

@ -98,8 +98,7 @@ void httpRequest() {
// note the time that the connection was made:
lastConnectionTime = millis();
}
else {
} else {
// if you couldn't make a connection:
Serial.println("connection failed");
}

View File

@ -84,8 +84,7 @@ void loop() {
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
} else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}

View File

@ -37,8 +37,7 @@ char server[] = "arduino.cc";
char path[] = "/asciilogo.txt";
int port = 80; // port 80 is the default for HTTP
void setup()
{
void setup() {
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
@ -51,13 +50,11 @@ 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))
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) {
notConnected = false;
else
{
} else {
Serial.println("Not connected");
delay(1000);
}
@ -66,8 +63,7 @@ void setup()
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, port))
{
if (client.connect(server, port)) {
Serial.println("connected");
// Make a HTTP request:
client.print("GET ");
@ -77,27 +73,22 @@ void setup()
client.println(server);
client.println("Connection: close");
client.println();
}
else
{
} else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop()
{
void loop() {
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available())
{
if (client.available()) {
char c = client.read();
Serial.print(c);
}
// if the server's disconnected, stop the client:
if (!client.available() && !client.connected())
{
if (!client.available() && !client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();

View File

@ -32,8 +32,7 @@ GSMServer server(80); // port 80 (http default)
// timeout
const unsigned long __TIMEOUT__ = 10 * 1000;
void setup()
{
void setup() {
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
@ -45,13 +44,11 @@ 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) &
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY))
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) {
notConnected = false;
else
{
} else {
Serial.println("Not connected");
delay(1000);
}
@ -76,22 +73,20 @@ void loop() {
if (client)
{
while (client.connected())
{
if (client.available())
{
if (client) {
while (client.connected()) {
if (client.available()) {
Serial.println("Receiving request!");
bool sendResponse = false;
while (char c = client.read()) {
if (c == '\n') sendResponse = true;
if (c == '\n') {
sendResponse = true;
}
}
// if you've gotten to the end of the line (received a newline
// character)
if (sendResponse)
{
if (sendResponse) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");

View File

@ -32,8 +32,7 @@ GSMVoiceCall vcs;
String remoteNumber = ""; // the number you will call
char charbuffer[20];
void setup()
{
void setup() {
// initialize serial communications and wait for port to open:
Serial.begin(9600);
@ -48,12 +47,10 @@ void setup()
// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
while (notConnected)
{
if (gsmAccess.begin(PINNUMBER) == GSM_READY)
while (notConnected) {
if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
notConnected = false;
else
{
} else {
Serial.println("Not connected");
delay(1000);
}
@ -64,19 +61,15 @@ void setup()
}
void loop()
{
void loop() {
// add any incoming characters to the String:
while (Serial.available() > 0)
{
while (Serial.available() > 0) {
char inChar = Serial.read();
// if it's a newline, that means you should make the call:
if (inChar == '\n')
{
if (inChar == '\n') {
// make sure the phone number is not too long:
if (remoteNumber.length() < 20)
{
if (remoteNumber.length() < 20) {
// let the user know you're calling:
Serial.print("Calling to : ");
Serial.println(remoteNumber);
@ -87,8 +80,7 @@ void loop()
// 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));
@ -98,18 +90,15 @@ void loop()
Serial.println("Call Finished");
remoteNumber = "";
Serial.println("Enter phone number to call.");
}
else
{
} else {
Serial.println("That's too long for a phone number. I'm forgetting it");
remoteNumber = "";
}
}
else
{
} else {
// add the latest character to the message to send:
if (inChar != '\r')
if (inChar != '\r') {
remoteNumber += inChar;
}
}
}
}

View File

@ -30,8 +30,7 @@ GSM_SMS sms;
// Array to hold the number a SMS is retreived from
char senderNumber[20];
void setup()
{
void setup() {
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
@ -44,12 +43,10 @@ void setup()
boolean notConnected = true;
// Start GSM connection
while (notConnected)
{
if (gsmAccess.begin(PINNUMBER) == GSM_READY)
while (notConnected) {
if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
notConnected = false;
else
{
} else {
Serial.println("Not connected");
delay(1000);
}
@ -59,13 +56,11 @@ void setup()
Serial.println("Waiting for messages");
}
void loop()
{
void loop() {
char c;
// If there are any SMSs available()
if (sms.available())
{
if (sms.available()) {
Serial.println("Message received from:");
// Get remote number
@ -74,15 +69,15 @@ void loop()
// 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");

View File

@ -34,8 +34,7 @@ GSMVoiceCall vcs;
// Array to hold the number for the incoming call
char numtel[20];
void setup()
{
void setup() {
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
@ -49,12 +48,10 @@ void setup()
// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
while (notConnected)
{
if (gsmAccess.begin(PINNUMBER) == GSM_READY)
while (notConnected) {
if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
notConnected = false;
else
{
} else {
Serial.println("Not connected");
delay(1000);
}
@ -66,11 +63,9 @@ void setup()
Serial.println("Waiting for a call");
}
void loop()
{
void loop() {
// Check the status of the voice call
switch (vcs.getvoiceCallStatus())
{
switch (vcs.getvoiceCallStatus()) {
case IDLE_CALL: // Nothing is happening
break;
@ -93,8 +88,9 @@ void loop()
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.");
break;

View File

@ -30,8 +30,7 @@
GSM gsmAccess;
GSM_SMS sms;
void setup()
{
void setup() {
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
@ -45,12 +44,10 @@ void setup()
// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
while (notConnected)
{
if (gsmAccess.begin(PINNUMBER) == GSM_READY)
while (notConnected) {
if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
notConnected = false;
else
{
} else {
Serial.println("Not connected");
delay(1000);
}
@ -59,8 +56,7 @@ void setup()
Serial.println("GSM initialized");
}
void loop()
{
void loop() {
Serial.print("Enter a mobile number: ");
char remoteNum[20]; // telephone number to send sms
@ -86,22 +82,17 @@ void loop()
/*
Read input serial
*/
int readSerial(char result[])
{
int readSerial(char result[]) {
int i = 0;
while (1)
{
while (Serial.available() > 0)
{
while (1) {
while (Serial.available() > 0) {
char inChar = Serial.read();
if (inChar == '\n')
{
if (inChar == '\n') {
result[i] = '\0';
Serial.flush();
return 0;
}
if (inChar != '\r')
{
if (inChar != '\r') {
result[i] = inChar;
i++;
}

View File

@ -28,8 +28,7 @@
// initialize the library instance
GSMBand band;
void setup()
{
void setup() {
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
@ -44,8 +43,7 @@ void setup()
};
void loop()
{
void loop() {
// Get current band
String bandName = band.getBand(); // Get and print band name
Serial.print("Current band:");
@ -60,17 +58,13 @@ void loop()
boolean operationSuccess;
operationSuccess = band.setBand(newBandName);
// Tell the user if the operation was OK
if (operationSuccess)
{
if (operationSuccess) {
Serial.println("Success");
}
else
{
} else {
Serial.println("Error while changing band");
}
if (operationSuccess)
{
if (operationSuccess) {
while (true);
}
}
@ -78,8 +72,7 @@ void loop()
// This function offers the user different options
// through the Serial interface
// The user selects one
String askUser()
{
String askUser() {
String newBand;
Serial.println("Select band:");
// Print the different options
@ -91,26 +84,28 @@ String askUser()
Serial.println("6 : GSM(850)+E-GSM(900)+DCS(1800)+PCS(1900)");
// Empty the incoming buffer
while (Serial.available())
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')
if (c == '1') {
newBand = GSM_MODE_EGSM;
else if (c == '2')
} else if (c == '2') {
newBand = GSM_MODE_DCS;
else if (c == '3')
} else if (c == '3') {
newBand = GSM_MODE_PCS;
else if (c == '4')
} else if (c == '4') {
newBand = GSM_MODE_EGSM_DCS;
else if (c == '5')
} else if (c == '5') {
newBand = GSM_MODE_GSM850_PCS;
else if (c == '6')
} else if (c == '6') {
newBand = GSM_MODE_GSM850_EGSM_DCS_PCS;
else
} else {
newBand = "GSM_MODE_UNDEFINED";
}
return newBand;
}

View File

@ -38,8 +38,7 @@ String IMEI = "";
// serial monitor result messages
String errortext = "ERROR";
void setup()
{
void setup() {
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
@ -54,12 +53,10 @@ void setup()
// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
while (notConnected)
{
if (gsmAccess.begin(PINNUMBER) == GSM_READY)
while (notConnected) {
if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
notConnected = false;
else
{
} else {
Serial.println("Not connected");
delay(1000);
}
@ -70,12 +67,12 @@ void setup()
Serial.print("Modem IMEI: ");
IMEI = modemTest.getIMEI();
IMEI.replace("\n", "");
if (IMEI != NULL)
if (IMEI != NULL) {
Serial.println(IMEI);
}
}
void loop()
{
void loop() {
// scan for existing networks, displays a list of networks
Serial.println("Scanning available networks. May take some seconds.");
Serial.println(scannerNetworks.readNetworks());

View File

@ -32,8 +32,7 @@ boolean auth = false;
String oktext = "OK";
String errortext = "ERROR";
void setup()
{
void setup() {
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
@ -46,52 +45,39 @@ void setup()
// check if the SIM have pin lock
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
{
} 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: ");
String puk = readSerial();
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);
Serial.println(oktext);
}
else
{
} else {
// if PUK o the new PIN are incorrect
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);
}
else
{
} else {
// SIM does not requires authetication
Serial.println("No pin necessary.");
auth = true;
@ -100,47 +86,42 @@ void setup()
// 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)
else if (PINManager.checkReg() == 1) {
Serial.println("ROAMING " + oktext);
else
{
} else {
// error connection
Serial.println(errortext);
while (true);
}
}
void loop()
{
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();
Serial.println("Now, enter your new PIN code:");
String newPIN = readSerial();
// change PIN
PINManager.changePIN(oldPIN, newPIN);
}
else
{
} else {
Serial.println("Incorrect option. Try again!.");
}
delay(1000);
@ -149,20 +130,17 @@ void loop()
/*
Read input serial
*/
String readSerial()
{
String readSerial() {
String text = "";
while (1)
{
while (Serial.available() > 0)
{
while (1) {
while (Serial.available() > 0) {
char inChar = Serial.read();
if (inChar == '\n')
{
if (inChar == '\n') {
return text;
}
if (inChar != '\r')
if (inChar != '\r') {
text += inChar;
}
}
}
}

View File

@ -43,8 +43,7 @@ String response = "";
// use a proxy
boolean use_proxy = false;
void setup()
{
void setup() {
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
@ -52,15 +51,13 @@ void setup()
}
}
void loop()
{
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);
}
@ -85,11 +82,9 @@ void loop()
// 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);
@ -117,40 +112,37 @@ void loop()
int res_connect;
// if use a proxy, connect with it
if (use_proxy)
if (use_proxy) {
res_connect = client.connect(proxy, pport);
else
} else {
res_connect = client.connect(url, 80);
}
if (res_connect)
{
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
} else {
client.print(path);
}
client.println(" HTTP/1.0");
client.println();
Serial.println(oktext);
}
else
{
} 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
// from the server, read and check them
if (client.available())
{
if (client.available()) {
char c = client.read();
response += c;
@ -167,8 +159,7 @@ void loop()
}
// if the server's disconnected, stop the client:
if (!client.connected())
{
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
@ -181,21 +172,16 @@ void loop()
/*
Read input serial
*/
int readSerial(char result[])
{
int readSerial(char result[]) {
int i = 0;
while (1)
{
while (Serial.available() > 0)
{
while (1) {
while (Serial.available() > 0) {
char inChar = Serial.read();
if (inChar == '\n')
{
if (inChar == '\n') {
result[i] = '\0';
return 0;
}
if (inChar != '\r')
{
if (inChar != '\r') {
result[i] = inChar;
i++;
}

View File

@ -27,8 +27,7 @@ GSMModem modem;
// IMEI variable
String IMEI = "";
void setup()
{
void setup() {
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
@ -37,38 +36,32 @@ void setup()
// start modem test (reset and check response)
Serial.print("Starting modem test...");
if (modem.begin())
if (modem.begin()) {
Serial.println("modem.begin() succeeded");
else
} else {
Serial.println("ERROR, no modem answer.");
}
}
void loop()
{
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);
// reset modem to check booting:
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");
}
else
{
} else {
Serial.println("Error: getIMEI() failed after modem.begin()");
}
}
else
{
} else {
Serial.println("Error: Could not get IMEI");
}
// do nothing:

View File

@ -35,8 +35,7 @@ GSMServer server(80); // port 80 (http default)
// timeout
const unsigned long __TIMEOUT__ = 10 * 1000;
void setup()
{
void setup() {
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
@ -49,13 +48,11 @@ 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))
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) {
connected = true;
else
{
} else {
Serial.println("Not connected");
delay(1000);
}

View File

@ -21,12 +21,12 @@
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
* 10K poterntiometer on pin A0
created 21 Mar 2011
by Tom Igoe
modified 11 Nov 2013
by Scott Fitzgerald
Based on Adafruit's example at
https://github.com/adafruit/SPI_VFD/blob/master/examples/createChar/createChar.pde
@ -101,9 +101,9 @@ byte armsUp[8] = {
};
void setup() {
// initialize LCD and set up the number of columns and rows:
// initialize LCD and set up the number of columns and rows:
lcd.begin(16, 2);
// create a new character
lcd.createChar(0, heart);
// create a new character
@ -116,7 +116,7 @@ void setup() {
lcd.createChar(4, armsUp);
// Print a message to the lcd.
lcd.print("I ");
lcd.print("I ");
lcd.write(byte(0)); // when calling lcd.write() '0' must be cast as a byte
lcd.print(" Arduino! ");
lcd.write((byte) 1);

View File

@ -48,8 +48,7 @@ void setup() {
Serial.begin(9600);
}
void loop()
{
void loop() {
// when characters arrive over the serial port...
if (Serial.available()) {
// wait a bit for the entire message to arrive

Some files were not shown because too many files have changed in this diff Show More