diff --git a/build/shared/examples/01.Basics/AnalogReadSerial/AnalogReadSerial.ino b/build/shared/examples/01.Basics/AnalogReadSerial/AnalogReadSerial.ino index 40b84df4e..f8e77f340 100644 --- a/build/shared/examples/01.Basics/AnalogReadSerial/AnalogReadSerial.ino +++ b/build/shared/examples/01.Basics/AnalogReadSerial/AnalogReadSerial.ino @@ -2,7 +2,7 @@ AnalogReadSerial Reads an analog input on pin 0, prints the result to the serial monitor. Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground. - + This example code is in the public domain. */ diff --git a/build/shared/examples/01.Basics/BareMinimum/BareMinimum.ino b/build/shared/examples/01.Basics/BareMinimum/BareMinimum.ino index c9c84ceca..95c2b6eb0 100644 --- a/build/shared/examples/01.Basics/BareMinimum/BareMinimum.ino +++ b/build/shared/examples/01.Basics/BareMinimum/BareMinimum.ino @@ -4,6 +4,6 @@ void setup() { } void loop() { - // put your main code here, to run repeatedly: - + // put your main code here, to run repeatedly: + } diff --git a/build/shared/examples/01.Basics/Blink/Blink.ino b/build/shared/examples/01.Basics/Blink/Blink.ino index 15b991140..e83815c60 100644 --- a/build/shared/examples/01.Basics/Blink/Blink.ino +++ b/build/shared/examples/01.Basics/Blink/Blink.ino @@ -1,18 +1,18 @@ /* Blink Turns on an LED on for one second, then off for one second, repeatedly. - + This example code is in the public domain. */ - + // Pin 13 has an LED connected on most Arduino boards. // give it a name: int led = 13; // the setup routine runs once when you press reset: -void setup() { +void setup() { // initialize the digital pin as an output. - pinMode(led, OUTPUT); + pinMode(led, OUTPUT); } // the loop routine runs over and over again forever: diff --git a/build/shared/examples/01.Basics/DigitalReadSerial/DigitalReadSerial.ino b/build/shared/examples/01.Basics/DigitalReadSerial/DigitalReadSerial.ino index 6fdd64f56..115b4c18c 100644 --- a/build/shared/examples/01.Basics/DigitalReadSerial/DigitalReadSerial.ino +++ b/build/shared/examples/01.Basics/DigitalReadSerial/DigitalReadSerial.ino @@ -1,7 +1,7 @@ /* DigitalReadSerial - Reads a digital input on pin 2, prints the result to the serial monitor - + Reads a digital input on pin 2, prints the result to the serial monitor + This example code is in the public domain. */ diff --git a/build/shared/examples/01.Basics/Fade/Fade.ino b/build/shared/examples/01.Basics/Fade/Fade.ino index 18f23caba..a8e9eb322 100644 --- a/build/shared/examples/01.Basics/Fade/Fade.ino +++ b/build/shared/examples/01.Basics/Fade/Fade.ino @@ -1,9 +1,9 @@ /* Fade - + This example shows how to fade an LED on pin 9 using the analogWrite() function. - + This example code is in the public domain. */ @@ -12,24 +12,24 @@ int brightness = 0; // how bright the LED is int fadeAmount = 5; // how many points to fade the LED by // the setup routine runs once when you press reset: -void setup() { +void setup() { // declare pin 9 to be an output: pinMode(led, OUTPUT); -} +} // the loop routine runs over and over again forever: -void loop() { +void loop() { // set the brightness of pin 9: - analogWrite(led, brightness); + analogWrite(led, brightness); // change the brightness for next time through the loop: brightness = brightness + fadeAmount; - // reverse the direction of the fading at the ends of the fade: + // reverse the direction of the fading at the ends of the fade: if (brightness == 0 || brightness == 255) { - fadeAmount = -fadeAmount ; - } - // wait for 30 milliseconds to see the dimming effect - delay(30); + fadeAmount = -fadeAmount ; + } + // wait for 30 milliseconds to see the dimming effect + delay(30); } diff --git a/build/shared/examples/01.Basics/ReadAnalogVoltage/ReadAnalogVoltage.ino b/build/shared/examples/01.Basics/ReadAnalogVoltage/ReadAnalogVoltage.ino index 26d124025..28afde882 100644 --- a/build/shared/examples/01.Basics/ReadAnalogVoltage/ReadAnalogVoltage.ino +++ b/build/shared/examples/01.Basics/ReadAnalogVoltage/ReadAnalogVoltage.ino @@ -2,7 +2,7 @@ ReadAnalogVoltage Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial monitor. Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground. - + This example code is in the public domain. */ diff --git a/build/shared/examples/02.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino b/build/shared/examples/02.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino index 014357191..e32875753 100644 --- a/build/shared/examples/02.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino +++ b/build/shared/examples/02.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino @@ -1,27 +1,27 @@ /* Blink without Delay - - Turns on and off a light emitting diode(LED) connected to a digital + + Turns on and off a light emitting diode(LED) connected to a digital pin, without using the delay() function. This means that other code can run at the same time without being interrupted by the LED code. - + The circuit: * 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 - + This example code is in the public domain. - + http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay */ -// constants won't change. Used here to +// constants won't change. Used here to // set pin numbers: const int ledPin = 13; // the number of the LED pin @@ -35,22 +35,22 @@ long interval = 1000; // interval at which to blink (milliseconds) void setup() { // set the digital pin as output: - pinMode(ledPin, OUTPUT); + pinMode(ledPin, OUTPUT); } 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 - // difference between the current time and last time you blinked - // the LED is bigger than the interval at which you want to + // check to see if it's time to blink the LED; that is, if the + // difference between the current time and last time you blinked + // 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) diff --git a/build/shared/examples/02.Digital/Button/Button.ino b/build/shared/examples/02.Digital/Button/Button.ino index e019fca31..887d84da8 100644 --- a/build/shared/examples/02.Digital/Button/Button.ino +++ b/build/shared/examples/02.Digital/Button/Button.ino @@ -1,30 +1,30 @@ /* Button - - Turns on and off a light emitting diode(LED) connected to digital - pin 13, when pressing a pushbutton attached to pin 2. - - + + Turns on and off a light emitting diode(LED) connected to digital + pin 13, when pressing a pushbutton attached to pin 2. + + The circuit: - * LED attached from pin 13 to ground + * LED attached from pin 13 to ground * pushbutton attached to pin 2 from +5V * 10K resistor attached to pin 2 from ground - + * Note: on most Arduinos there is already an LED on the board attached to pin 13. - - + + created 2005 by DojoDave modified 30 Aug 2011 by Tom Igoe - + This example code is in the public domain. - + http://www.arduino.cc/en/Tutorial/Button */ -// constants won't change. They're used here to +// constants won't change. They're used here to // set pin numbers: const int buttonPin = 2; // the number of the pushbutton pin const int ledPin = 13; // the number of the LED pin @@ -34,23 +34,23 @@ int buttonState = 0; // variable for reading the pushbutton status void setup() { // initialize the LED pin as an output: - pinMode(ledPin, OUTPUT); + pinMode(ledPin, OUTPUT); // initialize the pushbutton pin as an input: - pinMode(buttonPin, INPUT); + pinMode(buttonPin, INPUT); } -void loop(){ +void loop() { // read the state of the pushbutton value: buttonState = digitalRead(buttonPin); // check if the pushbutton is pressed. // if it is, the buttonState is HIGH: - if (buttonState == HIGH) { - // turn LED on: - digitalWrite(ledPin, HIGH); - } + if (buttonState == HIGH) { + // turn LED on: + digitalWrite(ledPin, HIGH); + } else { // turn LED off: - digitalWrite(ledPin, LOW); + digitalWrite(ledPin, LOW); } } \ No newline at end of file diff --git a/build/shared/examples/02.Digital/Debounce/Debounce.ino b/build/shared/examples/02.Digital/Debounce/Debounce.ino index da3aa29d9..9108b429e 100644 --- a/build/shared/examples/02.Digital/Debounce/Debounce.ino +++ b/build/shared/examples/02.Digital/Debounce/Debounce.ino @@ -1,33 +1,33 @@ -/* +/* Debounce - + Each time the input pin goes from LOW to HIGH (e.g. because of a push-button press), the output pin is toggled from LOW to HIGH or HIGH to LOW. There's a minimum delay between toggles to debounce the circuit (i.e. to ignore - noise). - + noise). + The circuit: * LED attached from pin 13 to ground * pushbutton attached from pin 2 to +5V * 10K resistor attached from pin 2 to ground - + * Note: On most Arduino boards, there is already an LED on the board connected to pin 13, so you don't need any extra components for this example. - - + + created 21 November 2006 by David A. Mellis modified 30 Aug 2011 by Limor Fried modified 28 Dec 2012 by Mike Walters - + This example code is in the public domain. - + http://www.arduino.cc/en/Tutorial/Debounce */ -// constants won't change. They're used here to +// constants won't change. They're used here to // set pin numbers: const int buttonPin = 2; // the number of the pushbutton pin const int ledPin = 13; // the number of the LED pin @@ -54,16 +54,16 @@ void loop() { // read the state of the switch into a local variable: int reading = digitalRead(buttonPin); - // check to see if you just pressed the button - // (i.e. the input went from LOW to HIGH), and you've waited - // long enough since the last press to ignore any noise: + // check to see if you just pressed the button + // (i.e. the input went from LOW to HIGH), and you've waited + // long enough since the last press to ignore any noise: // If the switch changed, due to noise or pressing: if (reading != lastButtonState) { // reset the debouncing timer lastDebounceTime = millis(); - } - + } + if ((millis() - lastDebounceTime) > debounceDelay) { // whatever the reading is at, it's been there for longer // than the debounce delay, so take it as the actual current state: @@ -78,7 +78,7 @@ void loop() { } } } - + // set the LED: digitalWrite(ledPin, ledState); diff --git a/build/shared/examples/02.Digital/DigitalInputPullup/DigitalInputPullup.ino b/build/shared/examples/02.Digital/DigitalInputPullup/DigitalInputPullup.ino index 6f540e9ff..1ef28057e 100644 --- a/build/shared/examples/02.Digital/DigitalInputPullup/DigitalInputPullup.ino +++ b/build/shared/examples/02.Digital/DigitalInputPullup/DigitalInputPullup.ino @@ -1,48 +1,48 @@ /* Input Pullup Serial - - This example demonstrates the use of pinMode(INPUT_PULLUP). It reads a + + This example demonstrates the use of pinMode(INPUT_PULLUP). It reads a digital input on pin 2 and prints the results to the serial monitor. - - The circuit: - * Momentary switch attached from pin 2 to ground + + The circuit: + * Momentary switch attached from pin 2 to ground * Built-in LED on pin 13 - - Unlike pinMode(INPUT), there is no pull-down resistor necessary. An internal - 20K-ohm resistor is pulled to 5V. This configuration causes the input to - read HIGH when the switch is open, and LOW when it is closed. - + + Unlike pinMode(INPUT), there is no pull-down resistor necessary. An internal + 20K-ohm resistor is pulled to 5V. This configuration causes the input to + read HIGH when the switch is open, and LOW when it is closed. + created 14 March 2012 by Scott Fitzgerald - + http://www.arduino.cc/en/Tutorial/InputPullupSerial - + This example code is in the public domain - + */ -void setup(){ +void setup() { //start serial connection Serial.begin(9600); //configure pin2 as an input and enable the internal pull-up resistor pinMode(2, INPUT_PULLUP); - pinMode(13, OUTPUT); + pinMode(13, OUTPUT); } -void loop(){ +void loop() { //read the pushbutton value into a variable int sensorVal = digitalRead(2); //print out the value of the pushbutton Serial.println(sensorVal); - + // Keep in mind the pullup means the pushbutton's // logic is inverted. It goes HIGH when it's open, - // and LOW when it's pressed. Turn on pin 13 when the + // and LOW when it's pressed. Turn on pin 13 when the // button's pressed, and off when it's not: if (sensorVal == HIGH) { digitalWrite(13, LOW); - } + } else { digitalWrite(13, HIGH); } diff --git a/build/shared/examples/02.Digital/StateChangeDetection/StateChangeDetection.ino b/build/shared/examples/02.Digital/StateChangeDetection/StateChangeDetection.ino index cb39e9dbb..bb3036931 100644 --- a/build/shared/examples/02.Digital/StateChangeDetection/StateChangeDetection.ino +++ b/build/shared/examples/02.Digital/StateChangeDetection/StateChangeDetection.ino @@ -1,28 +1,28 @@ /* State change detection (edge detection) - + Often, you don't need to know the state of a digital input all the time, but you just need to know when the input changes from one state to another. For example, you want to know when a button goes from OFF to ON. This is called state change detection, or edge detection. - + This example shows how to detect when a button or button changes from off to on and on to off. - + The circuit: * pushbutton attached to pin 2 from +5V * 10K resistor attached to pin 2 from ground * LED attached from pin 13 to ground (or use the built-in LED on most Arduino boards) - + created 27 Sep 2005 modified 30 Aug 2011 by Tom Igoe This example code is in the public domain. - + http://arduino.cc/en/Tutorial/ButtonStateChange - + */ // this constant won't change: @@ -58,30 +58,30 @@ void loop() { Serial.println("on"); Serial.print("number of button pushes: "); Serial.println(buttonPushCounter); - } + } else { // if the current state is LOW then the button // wend from on to off: - Serial.println("off"); + Serial.println("off"); } // Delay a little bit to avoid bouncing delay(50); } - // save the current state as the last state, + // save the current state as the last state, //for next time through the loop lastButtonState = buttonState; - - // turns on the LED every four button pushes by + + // turns on the LED every four button pushes by // checking the modulo of the button push counter. - // the modulo function gives you the remainder of + // the modulo function gives you the remainder of // the division of two numbers: if (buttonPushCounter % 4 == 0) { digitalWrite(ledPin, HIGH); } else { - digitalWrite(ledPin, LOW); + digitalWrite(ledPin, LOW); } - + } diff --git a/build/shared/examples/02.Digital/toneKeyboard/toneKeyboard.ino b/build/shared/examples/02.Digital/toneKeyboard/toneKeyboard.ino index 8521f8ab6..fbd4f726c 100644 --- a/build/shared/examples/02.Digital/toneKeyboard/toneKeyboard.ino +++ b/build/shared/examples/02.Digital/toneKeyboard/toneKeyboard.ino @@ -1,21 +1,21 @@ /* keyboard - + Plays a pitch that changes based on a changing analog input - + circuit: * 3 force-sensing resistors from +5V to analog in 0 through 5 * 3 10K resistors from analog in 0 through 5 to ground * 8-ohm speaker on digital pin 8 - + created 21 Jan 2010 modified 9 Apr 2012 - by Tom Igoe + by Tom Igoe This example code is in the public domain. - + http://arduino.cc/en/Tutorial/Tone3 - + */ #include "pitches.h" @@ -24,7 +24,8 @@ const int threshold = 10; // minimum reading of the sensors that generates a // notes to play, corresponding to the 3 sensors: int notes[] = { - NOTE_A4, NOTE_B4,NOTE_C3 }; + NOTE_A4, NOTE_B4, NOTE_C3 +}; void setup() { @@ -39,6 +40,6 @@ void loop() { if (sensorReading > threshold) { // play the note corresponding to this sensor: tone(8, notes[thisSensor], 20); - } + } } } diff --git a/build/shared/examples/02.Digital/toneMelody/toneMelody.ino b/build/shared/examples/02.Digital/toneMelody/toneMelody.ino index 8593ab770..bbb987220 100644 --- a/build/shared/examples/02.Digital/toneMelody/toneMelody.ino +++ b/build/shared/examples/02.Digital/toneMelody/toneMelody.ino @@ -1,39 +1,41 @@ /* Melody - - Plays a melody - + + Plays a melody + circuit: * 8-ohm speaker on digital pin 8 - + created 21 Jan 2010 modified 30 Aug 2011 - by Tom Igoe + by Tom Igoe This example code is in the public domain. - + http://arduino.cc/en/Tutorial/Tone - + */ - #include "pitches.h" +#include "pitches.h" // notes in the melody: int melody[] = { - NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4}; + NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4 +}; // note durations: 4 = quarter note, 8 = eighth note, etc.: int noteDurations[] = { - 4, 8, 8, 4,4,4,4,4 }; + 4, 8, 8, 4, 4, 4, 4, 4 +}; void setup() { // iterate over the notes of the melody: for (int thisNote = 0; thisNote < 8; thisNote++) { - // to calculate the note duration, take one second + // to calculate the note duration, take one second // divided by the note type. //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. - int noteDuration = 1000/noteDurations[thisNote]; - tone(8, melody[thisNote],noteDuration); + int noteDuration = 1000 / noteDurations[thisNote]; + tone(8, melody[thisNote], noteDuration); // to distinguish the notes, set a minimum time between them. // the note's duration + 30% seems to work well: diff --git a/build/shared/examples/02.Digital/toneMultiple/toneMultiple.ino b/build/shared/examples/02.Digital/toneMultiple/toneMultiple.ino index 1a92e7fcc..dea838f7d 100644 --- a/build/shared/examples/02.Digital/toneMultiple/toneMultiple.ino +++ b/build/shared/examples/02.Digital/toneMultiple/toneMultiple.ino @@ -1,19 +1,19 @@ /* Multiple tone player - + Plays multiple tones on multiple pins in sequence - + circuit: * 3 8-ohm speaker on digital pins 6, 7, and 8 - + created 8 March 2010 - by Tom Igoe + by Tom Igoe based on a snippet from Greg Borenstein This example code is in the public domain. - + http://arduino.cc/en/Tutorial/Tone4 - + */ void setup() { @@ -22,7 +22,7 @@ void setup() { void loop() { // turn off tone function for pin 8: - noTone(8); + noTone(8); // play a note on pin 6 for 200 ms: tone(6, 440, 200); delay(200); @@ -32,9 +32,9 @@ void loop() { // play a note on pin 7 for 500 ms: tone(7, 494, 500); delay(500); - + // turn off tone function for pin 7: - noTone(7); + noTone(7); // play a note on pin 8 for 500 ms: tone(8, 523, 300); delay(300); diff --git a/build/shared/examples/02.Digital/tonePitchFollower/tonePitchFollower.ino b/build/shared/examples/02.Digital/tonePitchFollower/tonePitchFollower.ino index 69caff744..3e6899911 100644 --- a/build/shared/examples/02.Digital/tonePitchFollower/tonePitchFollower.ino +++ b/build/shared/examples/02.Digital/tonePitchFollower/tonePitchFollower.ino @@ -1,21 +1,21 @@ /* Pitch follower - + Plays a pitch that changes based on a changing analog input - + circuit: * 8-ohm speaker on digital pin 9 * photoresistor on analog 0 to 5V * 4.7K resistor on analog 0 to ground - + created 21 Jan 2010 modified 31 May 2012 by Tom Igoe, with suggestion from Michael Flynn This example code is in the public domain. - + http://arduino.cc/en/Tutorial/Tone2 - + */ diff --git a/build/shared/examples/03.Analog/AnalogInOutSerial/AnalogInOutSerial.ino b/build/shared/examples/03.Analog/AnalogInOutSerial/AnalogInOutSerial.ino index a16f7eb2a..42b5c1880 100644 --- a/build/shared/examples/03.Analog/AnalogInOutSerial/AnalogInOutSerial.ino +++ b/build/shared/examples/03.Analog/AnalogInOutSerial/AnalogInOutSerial.ino @@ -1,22 +1,22 @@ /* Analog input, analog output, serial output - + Reads an analog input pin, maps the result to a range from 0 to 255 and uses the result to set the pulsewidth modulation (PWM) of an output pin. Also prints the results to the serial monitor. - + The circuit: * potentiometer connected to analog pin 0. Center pin of the potentiometer goes to the analog pin. side pins of the potentiometer go to +5V and ground * LED connected from digital pin 9 to ground - + created 29 Dec. 2008 modified 9 Apr 2012 by Tom Igoe - + This example code is in the public domain. - + */ // These constants won't change. They're used to give names @@ -29,25 +29,25 @@ int outputValue = 0; // value output to the PWM (analog out) void setup() { // initialize serial communications at 9600 bps: - Serial.begin(9600); + Serial.begin(9600); } void loop() { // read the analog in value: - sensorValue = analogRead(analogInPin); + sensorValue = analogRead(analogInPin); // map it to the range of the analog out: - outputValue = map(sensorValue, 0, 1023, 0, 255); + outputValue = map(sensorValue, 0, 1023, 0, 255); // change the analog out value: - analogWrite(analogOutPin, outputValue); + analogWrite(analogOutPin, outputValue); // print the results to the serial monitor: - Serial.print("sensor = " ); - Serial.print(sensorValue); - Serial.print("\t output = "); - Serial.println(outputValue); + Serial.print("sensor = " ); + Serial.print(sensorValue); + Serial.print("\t output = "); + Serial.println(outputValue); // wait 2 milliseconds before the next loop // for the analog-to-digital converter to settle // after the last reading: - delay(2); + delay(2); } diff --git a/build/shared/examples/03.Analog/AnalogInput/AnalogInput.ino b/build/shared/examples/03.Analog/AnalogInput/AnalogInput.ino index 5d685883b..32d44c625 100644 --- a/build/shared/examples/03.Analog/AnalogInput/AnalogInput.ino +++ b/build/shared/examples/03.Analog/AnalogInput/AnalogInput.ino @@ -1,10 +1,10 @@ /* Analog Input Demonstrates analog input by reading an analog sensor on analog pin 0 and - turning on and off a light emitting diode(LED) connected to digital pin 13. + turning on and off a light emitting diode(LED) connected to digital pin 13. The amount of time the LED will be on and off depends on - the value obtained by analogRead(). - + the value obtained by analogRead(). + The circuit: * Potentiometer attached to analog input 0 * center pin of the potentiometer to the analog pin @@ -12,19 +12,19 @@ * the other side pin to +5V * LED anode (long leg) attached to digital output 13 * LED cathode (short leg) attached to ground - - * Note: because most Arduinos have a built-in LED attached + + * Note: because most Arduinos have a built-in LED attached to pin 13 on the board, the LED is optional. - - + + Created by David Cuartielles modified 30 Aug 2011 By Tom Igoe - + This example code is in the public domain. - + http://arduino.cc/en/Tutorial/AnalogInput - + */ int sensorPin = A0; // select the input pin for the potentiometer @@ -33,18 +33,18 @@ int sensorValue = 0; // variable to store the value coming from the sensor void setup() { // declare the ledPin as an OUTPUT: - pinMode(ledPin, OUTPUT); + pinMode(ledPin, OUTPUT); } void loop() { // read the value from the sensor: - sensorValue = analogRead(sensorPin); + sensorValue = analogRead(sensorPin); // turn the ledPin on - digitalWrite(ledPin, HIGH); + digitalWrite(ledPin, HIGH); // stop the program for milliseconds: - delay(sensorValue); - // turn the ledPin off: - digitalWrite(ledPin, LOW); + delay(sensorValue); + // turn the ledPin off: + digitalWrite(ledPin, LOW); // stop the program for for milliseconds: - delay(sensorValue); + delay(sensorValue); } \ No newline at end of file diff --git a/build/shared/examples/03.Analog/AnalogWriteMega/AnalogWriteMega.ino b/build/shared/examples/03.Analog/AnalogWriteMega/AnalogWriteMega.ino index 04e50c86c..08e9e0455 100644 --- a/build/shared/examples/03.Analog/AnalogWriteMega/AnalogWriteMega.ino +++ b/build/shared/examples/03.Analog/AnalogWriteMega/AnalogWriteMega.ino @@ -1,17 +1,17 @@ /* Mega analogWrite() test - - This sketch fades LEDs up and down one at a time on digital pins 2 through 13. + + This sketch fades LEDs up and down one at a time on digital pins 2 through 13. This sketch was written for the Arduino Mega, and will not work on previous boards. - + The circuit: * LEDs attached from pins 2 through 13 to ground. created 8 Feb 2009 by Tom Igoe - + This example code is in the public domain. - + */ // These constants won't change. They're used to give names // to the pins used: @@ -21,24 +21,24 @@ const int highestPin = 13; void setup() { // set pins 2 through 13 as outputs: - for (int thisPin =lowestPin; thisPin <= highestPin; thisPin++) { - pinMode(thisPin, OUTPUT); + for (int thisPin = lowestPin; thisPin <= highestPin; thisPin++) { + pinMode(thisPin, OUTPUT); } } void loop() { // iterate over the pins: - for (int thisPin =lowestPin; thisPin <= highestPin; thisPin++) { + for (int thisPin = lowestPin; thisPin <= highestPin; thisPin++) { // fade the LED on thisPin from off to brightest: for (int brightness = 0; brightness < 255; brightness++) { analogWrite(thisPin, brightness); delay(2); - } + } // fade the LED on thisPin from brithstest to off: for (int brightness = 255; brightness >= 0; brightness--) { analogWrite(thisPin, brightness); delay(2); - } + } // pause between LEDs: delay(100); } diff --git a/build/shared/examples/03.Analog/Calibration/Calibration.ino b/build/shared/examples/03.Analog/Calibration/Calibration.ino index c3f88fdf0..bd87cad58 100644 --- a/build/shared/examples/03.Analog/Calibration/Calibration.ino +++ b/build/shared/examples/03.Analog/Calibration/Calibration.ino @@ -1,29 +1,29 @@ /* Calibration - + Demonstrates one technique for calibrating sensor input. The sensor readings during the first five seconds of the sketch execution define the minimum and maximum of expected values attached to the sensor pin. - + The sensor minimum and maximum initial values may seem backwards. - Initially, you set the minimum high and listen for anything + Initially, you set the minimum high and listen for anything lower, saving it as the new minimum. Likewise, you set the maximum low and listen for anything higher as the new maximum. - + The circuit: * Analog sensor (potentiometer will do) attached to analog input 0 * LED attached from digital pin 9 to ground - + created 29 Oct 2008 By David A Mellis modified 30 Aug 2011 By Tom Igoe - + http://arduino.cc/en/Tutorial/Calibration - + This example code is in the public domain. - + */ // These constants won't change: @@ -41,7 +41,7 @@ void setup() { pinMode(13, OUTPUT); digitalWrite(13, HIGH); - // calibrate during the first five seconds + // calibrate during the first five seconds while (millis() < 5000) { sensorValue = analogRead(sensorPin); diff --git a/build/shared/examples/03.Analog/Fading/Fading.ino b/build/shared/examples/03.Analog/Fading/Fading.ino index 858d3616c..2ed8bc4f4 100644 --- a/build/shared/examples/03.Analog/Fading/Fading.ino +++ b/build/shared/examples/03.Analog/Fading/Fading.ino @@ -1,45 +1,45 @@ /* Fading - + This example shows how to fade an LED using the analogWrite() function. - + The circuit: * LED attached from digital pin 9 to ground. - + Created 1 Nov 2008 By David A. Mellis modified 30 Aug 2011 By Tom Igoe - + http://arduino.cc/en/Tutorial/Fading - + This example code is in the public domain. - + */ int ledPin = 9; // LED connected to digital pin 9 -void setup() { - // nothing happens in setup -} +void setup() { + // nothing happens in setup +} -void loop() { +void loop() { // fade in from min to max in increments of 5 points: - for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) { + for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) { // sets the value (range from 0 to 255): - analogWrite(ledPin, fadeValue); - // wait for 30 milliseconds to see the dimming effect - delay(30); - } + analogWrite(ledPin, fadeValue); + // wait for 30 milliseconds to see the dimming effect + delay(30); + } // fade out from max to min in increments of 5 points: - for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) { + for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) { // sets the value (range from 0 to 255): - analogWrite(ledPin, fadeValue); - // wait for 30 milliseconds to see the dimming effect - delay(30); - } + analogWrite(ledPin, fadeValue); + // wait for 30 milliseconds to see the dimming effect + delay(30); + } } diff --git a/build/shared/examples/03.Analog/Smoothing/Smoothing.ino b/build/shared/examples/03.Analog/Smoothing/Smoothing.ino index cf6935de3..72f389c05 100644 --- a/build/shared/examples/03.Analog/Smoothing/Smoothing.ino +++ b/build/shared/examples/03.Analog/Smoothing/Smoothing.ino @@ -3,9 +3,9 @@ Smoothing Reads repeatedly from an analog input, calculating a running average - and printing it to the computer. Keeps ten readings in an array and + and printing it to the computer. Keeps ten readings in an array and continually averages them. - + The circuit: * Analog sensor (potentiometer will do) attached to analog input 0 @@ -14,7 +14,7 @@ modified 9 Apr 2012 by Tom Igoe http://www.arduino.cc/en/Tutorial/Smoothing - + This example code is in the public domain. @@ -37,32 +37,32 @@ int inputPin = A0; void setup() { // initialize serial communication with computer: - Serial.begin(9600); - // initialize all the readings to 0: + Serial.begin(9600); + // initialize all the readings to 0: for (int thisReading = 0; thisReading < numReadings; thisReading++) - readings[thisReading] = 0; + readings[thisReading] = 0; } void loop() { // subtract the last reading: - total= total - readings[index]; - // read from the sensor: - readings[index] = analogRead(inputPin); + total = total - readings[index]; + // read from the sensor: + readings[index] = analogRead(inputPin); // add the reading to the total: - total= total + readings[index]; - // advance to the next position in the array: - index = index + 1; + total = total + readings[index]; + // advance to the next position in the array: + index = index + 1; // if we're at the end of the array... - if (index >= numReadings) - // ...wrap around to the beginning: - index = 0; + if (index >= numReadings) + // ...wrap around to the beginning: + index = 0; // calculate the average: - average = total / numReadings; + average = total / numReadings; // send it to the computer as ASCII digits - Serial.println(average); - delay(1); // delay in between reads for stability + Serial.println(average); + delay(1); // delay in between reads for stability } diff --git a/build/shared/examples/04.Communication/ASCIITable/ASCIITable.ino b/build/shared/examples/04.Communication/ASCIITable/ASCIITable.ino index 9d8524784..d49a6f5a3 100644 --- a/build/shared/examples/04.Communication/ASCIITable/ASCIITable.ino +++ b/build/shared/examples/04.Communication/ASCIITable/ASCIITable.ino @@ -1,78 +1,78 @@ /* ASCII table - - Prints out byte values in all possible formats: + + Prints out byte values in all possible formats: * as raw binary values * as ASCII-encoded decimal, hex, octal, and binary values - + For more on ASCII, see http://www.asciitable.com and http://en.wikipedia.org/wiki/ASCII - + The circuit: No external hardware needed. - + created 2006 - by Nicholas Zambetti + by Nicholas Zambetti modified 9 Apr 2012 by Tom Igoe - + This example code is in the public domain. - - + + */ -void setup() { - //Initialize serial and wait for port to open: - Serial.begin(9600); +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } - - // prints title with ending line break - Serial.println("ASCII Table ~ Character Map"); -} + + // prints title with ending line break + Serial.println("ASCII Table ~ Character Map"); +} // first visible ASCIIcharacter '!' is number 33: -int thisByte = 33; +int thisByte = 33; // you can also write ASCII characters in single quotes. // for example. '!' is the same as 33, so you could also use this: -//int thisByte = '!'; +//int thisByte = '!'; -void loop() { - // prints value unaltered, i.e. the raw binary version of the - // byte. The serial monitor interprets all bytes as - // ASCII, so 33, the first number, will show up as '!' - Serial.write(thisByte); +void loop() { + // prints value unaltered, i.e. the raw binary version of the + // byte. The serial monitor interprets all bytes as + // ASCII, so 33, the first number, will show up as '!' + Serial.write(thisByte); - Serial.print(", dec: "); + Serial.print(", dec: "); // prints value as string as an ASCII-encoded decimal (base 10). // Decimal is the default format for Serial.print() and Serial.println(), // so no modifier is needed: - Serial.print(thisByte); + Serial.print(thisByte); // But you can declare the modifier for decimal if you want to. //this also works if you uncomment it: - // Serial.print(thisByte, DEC); + // Serial.print(thisByte, DEC); - Serial.print(", hex: "); + Serial.print(", hex: "); // prints value as string in hexadecimal (base 16): - Serial.print(thisByte, HEX); + Serial.print(thisByte, HEX); - Serial.print(", oct: "); + Serial.print(", oct: "); // prints value as string in octal (base 8); - Serial.print(thisByte, OCT); + Serial.print(thisByte, OCT); - Serial.print(", bin: "); - // prints value as string in binary (base 2) + Serial.print(", bin: "); + // prints value as string in binary (base 2) // also prints ending line break: - Serial.println(thisByte, BIN); + Serial.println(thisByte, BIN); - // if printed last visible character '~' or 126, stop: - if(thisByte == 126) { // you could also use if (thisByte == '~') { + // if printed last visible character '~' or 126, stop: + if (thisByte == 126) { // you could also use if (thisByte == '~') { // This loop loops forever and does nothing - while(true) { - continue; - } - } + while (true) { + continue; + } + } // go on to the next character - thisByte++; -} + thisByte++; +} diff --git a/build/shared/examples/04.Communication/Dimmer/Dimmer.ino b/build/shared/examples/04.Communication/Dimmer/Dimmer.ino index 78849c2c9..3cceb12e2 100644 --- a/build/shared/examples/04.Communication/Dimmer/Dimmer.ino +++ b/build/shared/examples/04.Communication/Dimmer/Dimmer.ino @@ -1,24 +1,24 @@ /* Dimmer - + Demonstrates the sending data from the computer to the Arduino board, in this case to control the brightness of an LED. The data is sent in individual bytes, each of which ranges from 0 to 255. Arduino reads these bytes and uses them to set the brightness of the LED. - + The circuit: LED attached from digital pin 9 to ground. Serial connection to Processing, Max/MSP, or another serial application - + created 2006 by David A. Mellis modified 30 Aug 2011 by Tom Igoe and Scott Fitzgerald - + This example code is in the public domain. - + http://www.arduino.cc/en/Tutorial/Dimmer - + */ const int ledPin = 9; // the pin that the LED is attached to @@ -47,35 +47,35 @@ void loop() { // Dimmer - sends bytes over a serial port // by David A. Mellis //This example code is in the public domain. - + import processing.serial.*; Serial port; - + void setup() { size(256, 150); - + println("Available serial ports:"); println(Serial.list()); - + // Uses the first port in this list (number 0). Change this to // select the port corresponding to your Arduino board. The last // parameter (e.g. 9600) is the speed of the communication. It // has to correspond to the value passed to Serial.begin() in your // Arduino sketch. - port = new Serial(this, Serial.list()[0], 9600); - + port = new Serial(this, Serial.list()[0], 9600); + // If you know the name of the port used by the Arduino board, you // can specify it directly like this. //port = new Serial(this, "COM1", 9600); } - + void draw() { // draw a gradient from black to white for (int i = 0; i < 256; i++) { stroke(i); line(i, 0, i, 150); } - + // write the current X-position of the mouse to the serial port as // a single byte port.write(mouseX); @@ -83,7 +83,7 @@ void loop() { */ /* Max/MSP v5 patch for this example - + ----------begin_max5_patcher---------- 1008.3ocuXszaiaCD9r8uhA5rqAeHIa0aAMaAVf1S6hdoYQAsDiL6JQZHQ2M YWr+2KeX4vjnjXKKkKhhiGQ9MeyCNz+X9rnMp63sQvuB+MLa1OlOalSjUvrC diff --git a/build/shared/examples/04.Communication/Graph/Graph.ino b/build/shared/examples/04.Communication/Graph/Graph.ino index c2e4637b6..92e9ecec0 100644 --- a/build/shared/examples/04.Communication/Graph/Graph.ino +++ b/build/shared/examples/04.Communication/Graph/Graph.ino @@ -1,26 +1,26 @@ /* Graph - + A simple example of communication from the Arduino board to the computer: the value of analog input 0 is sent out the serial port. We call this "serial" communication because the connection appears to both the Arduino and the computer as a serial port, even though it may actually use a USB cable. Bytes are sent one after another (serially) from the Arduino to the computer. - + You can use the Arduino serial monitor to view the sent data, or it can - be read by Processing, PD, Max/MSP, or any other program capable of reading - data from a serial port. The Processing code below graphs the data received + be read by Processing, PD, Max/MSP, or any other program capable of reading + data from a serial port. The Processing code below graphs the data received so you can see the value of the analog input changing over time. - + The circuit: Any analog input sensor is attached to analog in pin 0. - + created 2006 by David A. Mellis modified 9 Apr 2012 by Tom Igoe and Scott Fitzgerald - + This example code is in the public domain. http://www.arduino.cc/en/Tutorial/Graph @@ -34,34 +34,34 @@ void setup() { void loop() { // send the value of analog input 0: Serial.println(analogRead(A0)); - // wait a bit for the analog-to-digital converter + // wait a bit for the analog-to-digital converter // to stabilize after the last reading: delay(2); } /* Processing code for this example - + // Graphing sketch - - + + // This program takes ASCII-encoded strings // from the serial port at 9600 baud and graphs them. It expects values in the // range 0 to 1023, followed by a newline, or newline and carriage return - + // Created 20 Apr 2005 // Updated 18 Jan 2008 // by Tom Igoe // This example code is in the public domain. - + import processing.serial.*; - + Serial myPort; // The serial port int xPos = 1; // horizontal position of the graph - + void setup () { // set the window size: - size(400, 300); - + size(400, 300); + // List all the available serial ports println(Serial.list()); // I know that the first port in the serial list on my mac @@ -76,34 +76,34 @@ void loop() { void draw () { // everything happens in the serialEvent() } - + void serialEvent (Serial myPort) { // get the ASCII string: String inString = myPort.readStringUntil('\n'); - + if (inString != null) { // trim off any whitespace: inString = trim(inString); // convert to an int and map to the screen height: - float inByte = float(inString); + float inByte = float(inString); inByte = map(inByte, 0, 1023, 0, height); - + // draw the line: stroke(127,34,255); line(xPos, height, xPos, height - inByte); - + // at the edge of the screen, go back to the beginning: if (xPos >= width) { xPos = 0; - background(0); - } + background(0); + } else { // increment the horizontal position: xPos++; } } } - + */ /* Max/MSP v5 patch for this example @@ -145,5 +145,5 @@ RnMj5vGl1Fs16drnk7Tf1XOLgv1n0d2iEsCxR.eQsNOZ4FGF7whofgfI3kES 1kCeOX5L2rifbdu0A9ae2X.V33B1Z+.Bj1FrP5iFrCYCG5EUWSG.hhunHJd. HJ5hhnng3h9HPj4lud02.1bxGw. -----------end_max5_patcher----------- - + */ diff --git a/build/shared/examples/04.Communication/MIDI/Midi.ino b/build/shared/examples/04.Communication/MIDI/Midi.ino index 6a411d4fd..e4de8ccb7 100644 --- a/build/shared/examples/04.Communication/MIDI/Midi.ino +++ b/build/shared/examples/04.Communication/MIDI/Midi.ino @@ -1,11 +1,11 @@ /* MIDI note player - + This sketch shows how to use the serial transmit pin (pin 1) to send MIDI note data. - If this circuit is connected to a MIDI synth, it will play + If this circuit is connected to a MIDI synth, it will play the notes F#-0 (0x1E) to F#-5 (0x5A) in sequence. - + The circuit: * digital in 1 connected to MIDI jack pin 5 * MIDI jack pin 2 connected to ground @@ -14,12 +14,12 @@ created 13 Jun 2006 modified 13 Aug 2012 - by Tom Igoe + by Tom Igoe This example code is in the public domain. - + http://www.arduino.cc/en/Tutorial/Midi - + */ void setup() { @@ -34,7 +34,7 @@ void loop() { noteOn(0x90, note, 0x45); delay(100); //Note on channel 1 (0x90), some note value (note), silent velocity (0x00): - noteOn(0x90, note, 0x00); + noteOn(0x90, note, 0x00); delay(100); } } diff --git a/build/shared/examples/04.Communication/MultiSerialMega/MultiSerialMega.ino b/build/shared/examples/04.Communication/MultiSerialMega/MultiSerialMega.ino index 2764cba5a..54e31549b 100644 --- a/build/shared/examples/04.Communication/MultiSerialMega/MultiSerialMega.ino +++ b/build/shared/examples/04.Communication/MultiSerialMega/MultiSerialMega.ino @@ -1,21 +1,21 @@ /* Mega multple serial test - - Receives from the main serial port, sends to the others. + + Receives from the main serial port, sends to the others. Receives from serial port 1, sends to the main serial (Serial 0). - + This example works only on the Arduino Mega - - The circuit: + + The circuit: * Any serial device attached to Serial port 1 * Serial monitor open on Serial port 0: - + created 30 Dec. 2008 modified 20 May 2012 by Tom Igoe & Jed Roach - + This example code is in the public domain. - + */ @@ -29,12 +29,12 @@ void loop() { // read from port 1, send to port 0: if (Serial1.available()) { int inByte = Serial1.read(); - Serial.write(inByte); + Serial.write(inByte); } - + // read from port 0, send to port 1: if (Serial.available()) { int inByte = Serial.read(); - Serial1.write(inByte); + Serial1.write(inByte); } } diff --git a/build/shared/examples/04.Communication/PhysicalPixel/PhysicalPixel.ino b/build/shared/examples/04.Communication/PhysicalPixel/PhysicalPixel.ino index 7ac8231a6..33771aae0 100644 --- a/build/shared/examples/04.Communication/PhysicalPixel/PhysicalPixel.ino +++ b/build/shared/examples/04.Communication/PhysicalPixel/PhysicalPixel.ino @@ -1,23 +1,23 @@ /* Physical Pixel - - An example of using the Arduino board to receive data from the + + An example of using the Arduino board to receive data from the computer. In this case, the Arduino boards turns on an LED when it receives the character 'H', and turns off the LED when it receives the character 'L'. - + The data can be sent from the Arduino serial monitor, or another program like Processing (see code below), Flash (via a serial-net proxy), PD, or Max/MSP. - + The circuit: * LED connected from digital pin 13 to ground - + created 2006 by David A. Mellis modified 30 Aug 2011 by Tom Igoe and Scott Fitzgerald - + This example code is in the public domain. http://www.arduino.cc/en/Tutorial/PhysicalPixel @@ -41,7 +41,7 @@ void loop() { // if it's a capital H (ASCII 72), turn on the LED: if (incomingByte == 'H') { digitalWrite(ledPin, HIGH); - } + } // if it's an L (ASCII 76) turn off the LED: if (incomingByte == 'L') { digitalWrite(ledPin, LOW); @@ -50,76 +50,76 @@ void loop() { } /* Processing code for this example - - // mouseover serial - - // Demonstrates how to send data to the Arduino I/O board, in order to - // turn ON a light if the mouse is over a square and turn it off - // if the mouse is not. - + + // mouseover serial + + // Demonstrates how to send data to the Arduino I/O board, in order to + // turn ON a light if the mouse is over a square and turn it off + // if the mouse is not. + // created 2003-4 // based on examples by Casey Reas and Hernando Barragan // modified 30 Aug 2011 // by Tom Igoe // This example code is in the public domain. - - - import processing.serial.*; - + + + import processing.serial.*; + float boxX; float boxY; int boxSize = 20; boolean mouseOverBox = false; - - Serial port; - - void setup() { + + Serial port; + + void setup() { 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. - 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); - + 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. + 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() - { + + void draw() + { background(0); - - // Test if the cursor is over the box - if (mouseX > boxX-boxSize && mouseX < boxX+boxSize && + + // Test if the cursor is over the box + if (mouseX > boxX-boxSize && mouseX < boxX+boxSize && mouseY > boxY-boxSize && mouseY < boxY+boxSize) { - mouseOverBox = true; + mouseOverBox = true; // draw a line around the box and change its color: - stroke(255); + stroke(255); fill(153); // send an 'H' to indicate mouse is over square: - port.write('H'); - } + port.write('H'); + } else { // return the box to it's inactive state: stroke(153); fill(153); - // send an 'L' to turn the LED off: - port.write('L'); + // send an 'L' to turn the LED off: + port.write('L'); mouseOverBox = false; } - + // Draw the box rect(boxX, boxY, boxSize, boxSize); } - - + + */ /* @@ -165,6 +165,6 @@ uVr3PO8wWwEoTW8lsfraX7ZqzZDDXCRqNkztHsGCYpIDDAOqxDpMVUMKcOrp hN97JSnSfLUXGUoj6ujWXd6Pk1SAC+Pkogm.tZ.1lX1qL.pe6PE11DPeMMZ2 .P0K+3peBt3NskC -----------end_max5_patcher----------- - - + + */ diff --git a/build/shared/examples/04.Communication/ReadASCIIString/ReadASCIIString.ino b/build/shared/examples/04.Communication/ReadASCIIString/ReadASCIIString.ino index cb77a38f2..acb9386f4 100644 --- a/build/shared/examples/04.Communication/ReadASCIIString/ReadASCIIString.ino +++ b/build/shared/examples/04.Communication/ReadASCIIString/ReadASCIIString.ino @@ -1,19 +1,19 @@ /* Reading a serial ASCII-encoded string. - + This sketch demonstrates the Serial parseInt() function. It looks for an ASCII string of comma-separated values. It parses them into ints, and uses those to fade an RGB LED. - + Circuit: Common-anode RGB LED wired like so: * Red cathode: digital pin 3 * Green cathode: digital pin 5 * blue cathode: digital pin 6 * anode: +5V - + created 13 Apr 2012 by Tom Igoe - + This example code is in the public domain. */ @@ -26,9 +26,9 @@ void setup() { // initialize serial: Serial.begin(9600); // make the pins outputs: - pinMode(redPin, OUTPUT); - pinMode(greenPin, OUTPUT); - pinMode(bluePin, OUTPUT); + pinMode(redPin, OUTPUT); + pinMode(greenPin, OUTPUT); + pinMode(bluePin, OUTPUT); } @@ -37,11 +37,11 @@ void loop() { while (Serial.available() > 0) { // look for the next valid integer in the incoming serial stream: - int red = Serial.parseInt(); + int red = Serial.parseInt(); // do it again: - int green = Serial.parseInt(); + int green = Serial.parseInt(); // do it again: - int blue = Serial.parseInt(); + int blue = Serial.parseInt(); // look for the newline. That's the end of your // sentence: @@ -52,7 +52,7 @@ void loop() { green = 255 - constrain(green, 0, 255); blue = 255 - constrain(blue, 0, 255); - // fade the red, green, and blue legs of the LED: + // fade the red, green, and blue legs of the LED: analogWrite(redPin, red); analogWrite(greenPin, green); analogWrite(bluePin, blue); diff --git a/build/shared/examples/04.Communication/SerialCallResponse/SerialCallResponse.ino b/build/shared/examples/04.Communication/SerialCallResponse/SerialCallResponse.ino index dc004c9b2..f73a5d044 100644 --- a/build/shared/examples/04.Communication/SerialCallResponse/SerialCallResponse.ino +++ b/build/shared/examples/04.Communication/SerialCallResponse/SerialCallResponse.ino @@ -1,18 +1,18 @@ /* Serial Call and Response Language: Wiring/Arduino - + This program sends an ASCII A (byte of value 65) on startup and repeats that until it gets some data in. - Then it waits for a byte in the serial port, and + Then it waits for a byte in the serial port, and sends three sensor values whenever it gets a byte in. - + Thanks to Greg Shakar and Scott Fitzgerald for the improvements - + The circuit: - * potentiometers attached to analog inputs 0 and 1 + * potentiometers attached to analog inputs 0 and 1 * pushbutton attached to digital I/O 2 - + Created 26 Sept. 2005 by Tom Igoe modified 24 April 2012 @@ -38,7 +38,7 @@ void setup() } pinMode(2, INPUT); // digital sensor is on digital pin 2 - establishContact(); // send a byte to establish contact until receiver responds + establishContact(); // send a byte to establish contact until receiver responds } void loop() @@ -48,17 +48,17 @@ void loop() // get incoming byte: inByte = Serial.read(); // read first analog input, divide by 4 to make the range 0-255: - firstSensor = analogRead(A0)/4; + firstSensor = analogRead(A0) / 4; // delay 10ms to let the ADC recover: delay(10); // read second analog input, divide by 4 to make the range 0-255: - secondSensor = analogRead(1)/4; + secondSensor = analogRead(1) / 4; // read switch, map it to 0 or 255L - thirdSensor = map(digitalRead(2), 0, 1, 0, 255); + thirdSensor = map(digitalRead(2), 0, 1, 0, 255); // send sensor values: Serial.write(firstSensor); Serial.write(secondSensor); - Serial.write(thirdSensor); + Serial.write(thirdSensor); } } @@ -115,15 +115,15 @@ void serialEvent(Serial myPort) { int inByte = myPort.read(); // if this is the first byte received, and it's an A, // clear the serial buffer and note that you've - // had first contact from the microcontroller. + // had first contact from the microcontroller. // Otherwise, add the incoming byte to the array: if (firstContact == false) { - if (inByte == 'A') { + if (inByte == 'A') { myPort.clear(); // clear the serial port buffer firstContact = true; // you've had first contact from the microcontroller myPort.write('A'); // ask for more - } - } + } + } else { // Add the latest byte from the serial port to array: serialInArray[serialCount] = inByte; diff --git a/build/shared/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino b/build/shared/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino index 3c6f94ed2..da94455e8 100644 --- a/build/shared/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino +++ b/build/shared/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino @@ -1,31 +1,31 @@ /* Serial Call and Response in ASCII Language: Wiring/Arduino - + This program sends an ASCII A (byte of value 65) on startup and repeats that until it gets some data in. - Then it waits for a byte in the serial port, and - sends three ASCII-encoded, comma-separated sensor values, - truncated by a linefeed and carriage return, + Then it waits for a byte in the serial port, and + sends three ASCII-encoded, comma-separated sensor values, + truncated by a linefeed and carriage return, whenever it gets a byte in. - + Thanks to Greg Shakar and Scott Fitzgerald for the improvements - + The circuit: - * potentiometers attached to analog inputs 0 and 1 + * potentiometers attached to analog inputs 0 and 1 * pushbutton attached to digital I/O 2 - - - + + + Created 26 Sept. 2005 by Tom Igoe modified 24 Apr 2012 by Tom Igoe and Scott Fitzgerald - + This example code is in the public domain. - + http://www.arduino.cc/en/Tutorial/SerialCallResponseASCII - + */ int firstSensor = 0; // first analog sensor @@ -41,9 +41,9 @@ void setup() ; // wait for serial port to connect. Needed for Leonardo only } - + pinMode(2, INPUT); // digital sensor is on digital pin 2 - establishContact(); // send a byte to establish contact until receiver responds + establishContact(); // send a byte to establish contact until receiver responds } void loop() @@ -57,13 +57,13 @@ void loop() // read second analog input: secondSensor = analogRead(A1); // read switch, map it to 0 or 255L - thirdSensor = map(digitalRead(2), 0, 1, 0, 255); + thirdSensor = map(digitalRead(2), 0, 1, 0, 255); // send sensor values: Serial.print(firstSensor); Serial.print(","); Serial.print(secondSensor); Serial.print(","); - Serial.println(thirdSensor); + Serial.println(thirdSensor); } } @@ -101,7 +101,7 @@ void setup() { // read bytes into a buffer until you get a linefeed (ASCII 10): myPort.bufferUntil('\n'); - + // draw with smooth edges: smooth(); } @@ -114,22 +114,22 @@ void draw() { } // serialEvent method is run automatically by the Processing applet -// whenever the buffer reaches the byte value set in the bufferUntil() +// whenever the buffer reaches the byte value set in the bufferUntil() // method in the setup(): -void serialEvent(Serial myPort) { +void serialEvent(Serial myPort) { // read the serial buffer: String myString = myPort.readStringUntil('\n'); // if you got any bytes other than the linefeed: myString = trim(myString); - + // split the string at the commas // and convert the sections into integers: int sensors[] = int(split(myString, ',')); // print out the values you got: for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) { - print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t"); + print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t"); } // add a linefeed after all the sensor values are printed: println(); diff --git a/build/shared/examples/04.Communication/SerialEvent/SerialEvent.ino b/build/shared/examples/04.Communication/SerialEvent/SerialEvent.ino index 11de7adfb..cbaaf88f3 100644 --- a/build/shared/examples/04.Communication/SerialEvent/SerialEvent.ino +++ b/build/shared/examples/04.Communication/SerialEvent/SerialEvent.ino @@ -1,20 +1,20 @@ /* Serial Event example - + When new serial data arrives, this sketch adds it to a String. - When a newline is received, the loop prints the string and + When a newline is received, the loop prints the string and clears it. - - A good test for this is to try it with a GPS receiver - that sends out NMEA 0183 sentences. - + + A good test for this is to try it with a GPS receiver + that sends out NMEA 0183 sentences. + Created 9 May 2011 by Tom Igoe - + This example code is in the public domain. - + http://www.arduino.cc/en/Tutorial/SerialEvent - + */ String inputString = ""; // a string to hold incoming data @@ -30,7 +30,7 @@ void setup() { void loop() { // print the string when a newline arrives: if (stringComplete) { - Serial.println(inputString); + Serial.println(inputString); // clear the string: inputString = ""; stringComplete = false; @@ -46,14 +46,14 @@ void loop() { void serialEvent() { while (Serial.available()) { // get the new byte: - char inChar = (char)Serial.read(); + char inChar = (char)Serial.read(); // add it to the inputString: inputString += inChar; // if the incoming character is a newline, set a flag // so the main loop can do something about it: if (inChar == '\n') { stringComplete = true; - } + } } } diff --git a/build/shared/examples/04.Communication/VirtualColorMixer/VirtualColorMixer.ino b/build/shared/examples/04.Communication/VirtualColorMixer/VirtualColorMixer.ino index 39e4b5761..24c1e3eb8 100644 --- a/build/shared/examples/04.Communication/VirtualColorMixer/VirtualColorMixer.ino +++ b/build/shared/examples/04.Communication/VirtualColorMixer/VirtualColorMixer.ino @@ -2,17 +2,17 @@ This example reads three analog sensors (potentiometers are easiest) and sends their values serially. The Processing and Max/MSP programs at the bottom take those three values and use them to change the background color of the screen. - + The circuit: * potentiometers attached to analog inputs 0, 1, and 2 - + http://www.arduino.cc/en/Tutorial/VirtualColorMixer - + created 2 Dec 2006 by David A. Mellis modified 30 Aug 2011 by Tom Igoe and Scott Fitzgerald - + This example code is in the public domain. */ @@ -35,20 +35,20 @@ void loop() } /* Processing code for this example - + // This example code is in the public domain. - + import processing.serial.*; - + float redValue = 0; // red value float greenValue = 0; // green value float blueValue = 0; // blue value - + Serial myPort; - + void setup() { size(200, 200); - + // List all the available serial ports println(Serial.list()); // I know that the first port in the serial list on my mac @@ -58,20 +58,20 @@ void loop() // don't generate a serialEvent() unless you get a newline character: myPort.bufferUntil('\n'); } - + void draw() { // set the background color with the color values: background(redValue, greenValue, blueValue); } - - void serialEvent(Serial myPort) { + + void serialEvent(Serial myPort) { // get the ASCII string: String inString = myPort.readStringUntil('\n'); - + if (inString != null) { // trim off any whitespace: inString = trim(inString); - // split the string on the commas and convert the + // split the string on the commas and convert the // resulting substrings into an integer array: float[] colors = float(split(inString, ",")); // if the array has at least three elements, you know @@ -126,5 +126,5 @@ ASi6Zyw8.RQi65J8ZsNx3ho93OhGWENtWpowepae4YhCFeLErOLENtXJrOSc iadi39rf4hwc8xdhHz3gn3dBI7iDRlFe8huAfIZhq -----------end_max5_patcher----------- - + */ diff --git a/build/shared/examples/05.Control/Arrays/Arrays.ino b/build/shared/examples/05.Control/Arrays/Arrays.ino index d1cdea8c8..37b7a5e98 100644 --- a/build/shared/examples/05.Control/Arrays/Arrays.ino +++ b/build/shared/examples/05.Control/Arrays/Arrays.ino @@ -1,52 +1,53 @@ /* Arrays - + Demonstrates the use of an array to hold pin numbers - in order to iterate over the pins in a sequence. + in order to iterate over the pins in a sequence. Lights multiple LEDs in sequence, then in reverse. - + Unlike the For Loop tutorial, where the pins have to be contiguous, here the pins can be in any random order. - + The circuit: * LEDs from pins 2 through 7 to ground - + created 2006 by David A. Mellis modified 30 Aug 2011 - by Tom Igoe + by Tom Igoe This example code is in the public domain. - + http://www.arduino.cc/en/Tutorial/Array */ int timer = 100; // The higher the number, the slower the timing. -int ledPins[] = { - 2, 7, 4, 6, 5, 3 }; // an array of pin numbers to which LEDs are attached +int ledPins[] = { + 2, 7, 4, 6, 5, 3 +}; // an array of pin numbers to which LEDs are attached int pinCount = 6; // the number of pins (i.e. the length of the array) void setup() { // the array elements are numbered from 0 to (pinCount - 1). // use a for loop to initialize each pin as an output: - for (int thisPin = 0; thisPin < pinCount; thisPin++) { - pinMode(ledPins[thisPin], OUTPUT); + for (int thisPin = 0; thisPin < pinCount; thisPin++) { + pinMode(ledPins[thisPin], OUTPUT); } } void loop() { // loop from the lowest pin to the highest: - for (int thisPin = 0; thisPin < pinCount; thisPin++) { + for (int thisPin = 0; thisPin < pinCount; thisPin++) { // turn the pin on: - digitalWrite(ledPins[thisPin], HIGH); - delay(timer); + digitalWrite(ledPins[thisPin], HIGH); + delay(timer); // turn the pin off: - digitalWrite(ledPins[thisPin], LOW); + digitalWrite(ledPins[thisPin], LOW); } // loop from the highest pin to the lowest: - for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) { + for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) { // turn the pin on: digitalWrite(ledPins[thisPin], HIGH); delay(timer); diff --git a/build/shared/examples/05.Control/ForLoopIteration/ForLoopIteration.ino b/build/shared/examples/05.Control/ForLoopIteration/ForLoopIteration.ino index d9ce32b8f..0aa922b24 100644 --- a/build/shared/examples/05.Control/ForLoopIteration/ForLoopIteration.ino +++ b/build/shared/examples/05.Control/ForLoopIteration/ForLoopIteration.ino @@ -1,19 +1,19 @@ /* For Loop Iteration - - Demonstrates the use of a for() loop. + + Demonstrates the use of a for() loop. Lights multiple LEDs in sequence, then in reverse. - + The circuit: * LEDs from pins 2 through 7 to ground - + created 2006 by David A. Mellis modified 30 Aug 2011 - by Tom Igoe + by Tom Igoe This example code is in the public domain. - + http://www.arduino.cc/en/Tutorial/ForLoop */ @@ -21,23 +21,23 @@ int timer = 100; // The higher the number, the slower the timing. void setup() { // use a for loop to initialize each pin as an output: - for (int thisPin = 2; thisPin < 8; thisPin++) { - pinMode(thisPin, OUTPUT); + for (int thisPin = 2; thisPin < 8; thisPin++) { + pinMode(thisPin, OUTPUT); } } void loop() { // loop from the lowest pin to the highest: - for (int thisPin = 2; thisPin < 8; thisPin++) { + for (int thisPin = 2; thisPin < 8; thisPin++) { // turn the pin on: - digitalWrite(thisPin, HIGH); - delay(timer); + digitalWrite(thisPin, HIGH); + delay(timer); // turn the pin off: - digitalWrite(thisPin, LOW); + digitalWrite(thisPin, LOW); } // loop from the highest pin to the lowest: - for (int thisPin = 7; thisPin >= 2; thisPin--) { + for (int thisPin = 7; thisPin >= 2; thisPin--) { // turn the pin on: digitalWrite(thisPin, HIGH); delay(timer); diff --git a/build/shared/examples/05.Control/IfStatementConditional/IfStatementConditional.ino b/build/shared/examples/05.Control/IfStatementConditional/IfStatementConditional.ino index e6c18017a..15cd822da 100644 --- a/build/shared/examples/05.Control/IfStatementConditional/IfStatementConditional.ino +++ b/build/shared/examples/05.Control/IfStatementConditional/IfStatementConditional.ino @@ -1,30 +1,30 @@ /* Conditionals - If statement - + This example demonstrates the use of if() statements. It reads the state of a potentiometer (an analog input) and turns on an LED only if the LED goes above a certain threshold level. It prints the analog value regardless of the level. - + The circuit: * potentiometer connected to analog pin 0. Center pin of the potentiometer goes to the analog pin. side pins of the potentiometer go to +5V and ground * LED connected from digital pin 13 to ground - + * Note: On most Arduino boards, there is already an LED on the board connected to pin 13, so you don't need any extra components for this example. - + created 17 Jan 2009 modified 9 Apr 2012 by Tom Igoe This example code is in the public domain. - + http://arduino.cc/en/Tutorial/IfStatement - + */ - + // These constants won't change: const int analogPin = A0; // pin that the sensor is attached to const int ledPin = 13; // pin that the LED is attached to @@ -44,9 +44,9 @@ void loop() { // if the analog value is high enough, turn on the LED: if (analogValue > threshold) { digitalWrite(ledPin, HIGH); - } + } else { - digitalWrite(ledPin,LOW); + digitalWrite(ledPin, LOW); } // print the analog value: diff --git a/build/shared/examples/05.Control/WhileStatementConditional/WhileStatementConditional.ino b/build/shared/examples/05.Control/WhileStatementConditional/WhileStatementConditional.ino index 9cffeef22..36d25a191 100644 --- a/build/shared/examples/05.Control/WhileStatementConditional/WhileStatementConditional.ino +++ b/build/shared/examples/05.Control/WhileStatementConditional/WhileStatementConditional.ino @@ -1,29 +1,29 @@ /* Conditionals - while statement - + This example demonstrates the use of while() statements. - + While the pushbutton is pressed, the sketch runs the calibration routine. - The sensor readings during the while loop define the minimum and maximum + The sensor readings during the while loop define the minimum and maximum of expected values from the photo resistor. - + This is a variation on the calibrate example. - + The circuit: * photo resistor connected from +5V to analog in pin 0 * 10K resistor connected from ground to analog in pin 0 * LED connected from digital pin 9 to ground through 220 ohm resistor * pushbutton attached from pin 2 to +5V * 10K resistor attached from pin 2 to ground - + created 17 Jan 2009 modified 30 Aug 2011 by Tom Igoe - + This example code is in the public domain. http://arduino.cc/en/Tutorial/WhileLoop - + */ @@ -50,10 +50,10 @@ void setup() { void loop() { // while the button is pressed, take calibration readings: while (digitalRead(buttonPin) == HIGH) { - calibrate(); + calibrate(); } // signal the end of the calibration period - digitalWrite(indicatorLedPin, LOW); + digitalWrite(indicatorLedPin, LOW); // read the sensor: sensorValue = analogRead(sensorPin); diff --git a/build/shared/examples/05.Control/switchCase/switchCase.ino b/build/shared/examples/05.Control/switchCase/switchCase.ino index 93004b3de..1572f73e4 100644 --- a/build/shared/examples/05.Control/switchCase/switchCase.ino +++ b/build/shared/examples/05.Control/switchCase/switchCase.ino @@ -1,24 +1,24 @@ /* Switch statement - + Demonstrates the use of a switch statement. The switch statement allows you to choose from among a set of discrete values of a variable. It's like a series of if statements. - + To see this sketch in action, but the board and sensor in a well-lit room, open the serial monitor, and and move your hand gradually down over the sensor. - + The circuit: * photoresistor from analog in 0 to +5V * 10K resistor from analog in 0 to ground - + created 1 Jul 2009 modified 9 Apr 2012 - by Tom Igoe - + by Tom Igoe + This example code is in the public domain. - + http://www.arduino.cc/en/Tutorial/SwitchCase */ @@ -29,7 +29,7 @@ const int sensorMax = 600; // sensor maximum, discovered through experiment void setup() { // initialize serial communication: - Serial.begin(9600); + Serial.begin(9600); } void loop() { @@ -38,22 +38,22 @@ void loop() { // map the sensor range to a range of four options: int range = map(sensorReading, sensorMin, sensorMax, 0, 3); - // do something different depending on the + // do something different depending on the // range value: switch (range) { - case 0: // your hand is on the sensor - Serial.println("dark"); - break; - case 1: // your hand is close to the sensor - Serial.println("dim"); - break; - case 2: // your hand is a few inches from the sensor - Serial.println("medium"); - break; - case 3: // your hand is nowhere near the sensor - Serial.println("bright"); - break; - } + case 0: // your hand is on the sensor + Serial.println("dark"); + break; + case 1: // your hand is close to the sensor + Serial.println("dim"); + break; + case 2: // your hand is a few inches from the sensor + Serial.println("medium"); + break; + case 3: // your hand is nowhere near the sensor + Serial.println("bright"); + break; + } delay(1); // delay in between reads for stability } diff --git a/build/shared/examples/05.Control/switchCase2/switchCase2.ino b/build/shared/examples/05.Control/switchCase2/switchCase2.ino index b6d78865a..19215d9ea 100644 --- a/build/shared/examples/05.Control/switchCase2/switchCase2.ino +++ b/build/shared/examples/05.Control/switchCase2/switchCase2.ino @@ -1,66 +1,66 @@ /* Switch statement with serial input - + Demonstrates the use of a switch statement. The switch statement allows you to choose from among a set of discrete values of a variable. It's like a series of if statements. - + To see this sketch in action, open the Serial monitor and send any character. The characters a, b, c, d, and e, will turn on LEDs. Any other character will turn the LEDs off. - + The circuit: * 5 LEDs attached to digital pins 2 through 6 through 220-ohm resistors - + created 1 Jul 2009 - by Tom Igoe - + by Tom Igoe + This example code is in the public domain. - + http://www.arduino.cc/en/Tutorial/SwitchCase2 */ void setup() { // initialize serial communication: - Serial.begin(9600); - // initialize the LED pins: - for (int thisPin = 2; thisPin < 7; thisPin++) { - pinMode(thisPin, OUTPUT); - } + Serial.begin(9600); + // initialize the LED pins: + for (int thisPin = 2; thisPin < 7; thisPin++) { + pinMode(thisPin, OUTPUT); + } } void loop() { // read the sensor: if (Serial.available() > 0) { int inByte = Serial.read(); - // do something different depending on the character received. + // do something different depending on the character received. // The switch statement expects single number values for each case; // in this exmaple, though, you're using single quotes to tell - // the controller to get the ASCII value for the character. For + // the controller to get the ASCII value for the character. For // example 'a' = 97, 'b' = 98, and so forth: switch (inByte) { - case 'a': - digitalWrite(2, HIGH); - break; - case 'b': - digitalWrite(3, HIGH); - break; - case 'c': - digitalWrite(4, HIGH); - break; - case 'd': - digitalWrite(5, HIGH); - break; - case 'e': - digitalWrite(6, HIGH); - break; - default: - // turn all the LEDs off: - for (int thisPin = 2; thisPin < 7; thisPin++) { - digitalWrite(thisPin, LOW); - } - } + case 'a': + digitalWrite(2, HIGH); + break; + case 'b': + digitalWrite(3, HIGH); + break; + case 'c': + digitalWrite(4, HIGH); + break; + case 'd': + digitalWrite(5, HIGH); + break; + case 'e': + digitalWrite(6, HIGH); + break; + default: + // turn all the LEDs off: + for (int thisPin = 2; thisPin < 7; thisPin++) { + digitalWrite(thisPin, LOW); + } + } } } diff --git a/build/shared/examples/06.Sensors/ADXL3xx/ADXL3xx.ino b/build/shared/examples/06.Sensors/ADXL3xx/ADXL3xx.ino index a55cc016a..19b073a4f 100644 --- a/build/shared/examples/06.Sensors/ADXL3xx/ADXL3xx.ino +++ b/build/shared/examples/06.Sensors/ADXL3xx/ADXL3xx.ino @@ -1,7 +1,7 @@ /* ADXL3xx - + Reads an Analog Devices ADXL3xx accelerometer and communicates the acceleration to the computer. The pins used are designed to be easily compatible with the breakout boards from Sparkfun, available from: @@ -16,12 +16,12 @@ analog 3: x-axis analog 4: ground analog 5: vcc - + created 2 Jul 2008 by David A. Mellis modified 30 Aug 2011 - by Tom Igoe - + by Tom Igoe + This example code is in the public domain. */ @@ -37,14 +37,14 @@ void setup() { // initialize the serial communications: Serial.begin(9600); - + // Provide ground and power by using the analog inputs as normal // digital pins. This makes it possible to directly connect the // breakout board to the Arduino. If you use the normal 5V and // GND pins on the Arduino, you can remove these lines. pinMode(groundpin, OUTPUT); pinMode(powerpin, OUTPUT); - digitalWrite(groundpin, LOW); + digitalWrite(groundpin, LOW); digitalWrite(powerpin, HIGH); } diff --git a/build/shared/examples/06.Sensors/Knock/Knock.ino b/build/shared/examples/06.Sensors/Knock/Knock.ino index 6f8c2c55a..98c64ffb0 100644 --- a/build/shared/examples/06.Sensors/Knock/Knock.ino +++ b/build/shared/examples/06.Sensors/Knock/Knock.ino @@ -1,26 +1,26 @@ /* Knock Sensor - - This sketch reads a piezo element to detect a knocking sound. - It reads an analog pin and compares the result to a set threshold. + + This sketch reads a piezo element to detect a knocking sound. + It reads an analog pin and compares the result to a set threshold. If the result is greater than the threshold, it writes "knock" to the serial port, and toggles the LED on pin 13. - + The circuit: * + connection of the piezo attached to analog in 0 * - connection of the piezo attached to ground * 1-megohm resistor attached from analog in 0 to ground http://www.arduino.cc/en/Tutorial/Knock - + created 25 Mar 2007 by David Cuartielles modified 30 Aug 2011 by Tom Igoe - + This example code is in the public domain. */ - + // these constants won't change: const int ledPin = 13; // led connected to digital pin 13 @@ -33,22 +33,22 @@ int sensorReading = 0; // variable to store the value read from the sensor int ledState = LOW; // variable used to store the last LED status, to toggle the light void setup() { - pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT - Serial.begin(9600); // use the serial port + pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT + Serial.begin(9600); // use the serial port } void loop() { // read the sensor and store it in the variable sensorReading: - sensorReading = analogRead(knockSensor); - + sensorReading = analogRead(knockSensor); + // if the sensor reading is greater than the threshold: if (sensorReading >= threshold) { // toggle the status of the ledPin: - ledState = !ledState; - // update the LED pin itself: + ledState = !ledState; + // update the LED pin itself: digitalWrite(ledPin, ledState); // send the string "Knock!" back to the computer, followed by newline - Serial.println("Knock!"); + Serial.println("Knock!"); } delay(100); // delay to avoid overloading the serial port buffer } diff --git a/build/shared/examples/06.Sensors/Memsic2125/Memsic2125.ino b/build/shared/examples/06.Sensors/Memsic2125/Memsic2125.ino index 974ccb52f..74c504bb8 100644 --- a/build/shared/examples/06.Sensors/Memsic2125/Memsic2125.ino +++ b/build/shared/examples/06.Sensors/Memsic2125/Memsic2125.ino @@ -1,24 +1,24 @@ /* Memsic2125 - + Read the Memsic 2125 two-axis accelerometer. Converts the pulses output by the 2125 into milli-g's (1/1000 of earth's gravity) and prints them over the serial connection to the computer. - + The circuit: * X output of accelerometer to digital pin 2 * Y output of accelerometer to digital pin 3 * +V of accelerometer to +5V * GND of accelerometer to ground - + http://www.arduino.cc/en/Tutorial/Memsic2125 - + created 6 Nov 2008 by David A. Mellis modified 30 Aug 2011 by Tom Igoe - + This example code is in the public domain. */ @@ -41,13 +41,13 @@ void loop() { int pulseX, pulseY; // variables to contain the resulting accelerations int accelerationX, accelerationY; - + // read pulse from x- and y-axes: - pulseX = pulseIn(xPin,HIGH); - pulseY = pulseIn(yPin,HIGH); - + pulseX = pulseIn(xPin, HIGH); + pulseY = pulseIn(yPin, HIGH); + // convert the pulse width into acceleration - // accelerationX and accelerationY are in milli-g's: + // accelerationX and accelerationY are in milli-g's: // earth's gravity is 1000 milli-g's, or 1g. accelerationX = ((pulseX / 10) - 500) * 8; accelerationY = ((pulseY / 10) - 500) * 8; diff --git a/build/shared/examples/06.Sensors/Ping/Ping.ino b/build/shared/examples/06.Sensors/Ping/Ping.ino index 5de46d603..77adcb733 100644 --- a/build/shared/examples/06.Sensors/Ping/Ping.ino +++ b/build/shared/examples/06.Sensors/Ping/Ping.ino @@ -1,23 +1,23 @@ /* Ping))) Sensor - + This sketch reads a PING))) ultrasonic rangefinder and returns the distance to the closest object in range. To do this, it sends a pulse - to the sensor to initiate a reading, then listens for a pulse - to return. The length of the returning pulse is proportional to + to the sensor to initiate a reading, then listens for a pulse + to return. The length of the returning pulse is proportional to the distance of the object from the sensor. - + The circuit: * +V connection of the PING))) attached to +5V * GND connection of the PING))) attached to ground * SIG connection of the PING))) attached to digital pin 7 http://www.arduino.cc/en/Tutorial/Ping - + created 3 Nov 2008 by David A. Mellis modified 30 Aug 2011 by Tom Igoe - + This example code is in the public domain. */ @@ -33,7 +33,7 @@ void setup() { void loop() { - // establish variables for duration of the ping, + // establish variables for duration of the ping, // and the distance result in inches and centimeters: long duration, inches, cm; @@ -55,13 +55,13 @@ void loop() // convert the time into a distance inches = microsecondsToInches(duration); cm = microsecondsToCentimeters(duration); - + Serial.print(inches); Serial.print("in, "); Serial.print(cm); Serial.print("cm"); Serial.println(); - + delay(100); } diff --git a/build/shared/examples/07.Display/RowColumnScanning/RowColumnScanning.ino b/build/shared/examples/07.Display/RowColumnScanning/RowColumnScanning.ino index f841c6857..a7f623a5e 100644 --- a/build/shared/examples/07.Display/RowColumnScanning/RowColumnScanning.ino +++ b/build/shared/examples/07.Display/RowColumnScanning/RowColumnScanning.ino @@ -1,23 +1,23 @@ /* Row-Column Scanning an 8x8 LED matrix with X-Y input - + This example controls an 8x8 LED matrix using two analog inputs - + created 27 May 2009 modified 30 Aug 2011 by Tom Igoe - - This example works for the Lumex LDM-24488NI Matrix. See + + This example works for the Lumex LDM-24488NI Matrix. See http://sigma.octopart.com/140413/datasheet/Lumex-LDM-24488NI.pdf for the pin connections - - For other LED cathode column matrixes, you should only need to change + + For other LED cathode column matrixes, you should only need to change the pin numbers in the row[] and column[] arrays - + rows are the anodes cols are the cathodes --------- - + Pin numbers: Matrix: * Digital pins 2 through 13, @@ -25,25 +25,27 @@ Potentiometers: * center pins are attached to analog pins 0 and 1, respectively * side pins attached to +5V and ground, respectively. - + This example code is in the public domain. - + http://www.arduino.cc/en/Tutorial/RowColumnScanning - + see also http://www.tigoe.net/pcomp/code/category/arduinowiring/514 for more */ // 2-dimensional array of row pin numbers: const int row[8] = { - 2,7,19,5,13,18,12,16 }; + 2, 7, 19, 5, 13, 18, 12, 16 +}; // 2-dimensional array of column pin numbers: const int col[8] = { - 6,11,10,3,17,4,8,9 }; + 6, 11, 10, 3, 17, 4, 8, 9 +}; // 2-dimensional array of pixels: -int pixels[8][8]; +int pixels[8][8]; // cursor position: int x = 5; @@ -54,11 +56,11 @@ void setup() { // iterate over the pins: for (int thisPin = 0; thisPin < 8; thisPin++) { // initialize the output pins: - pinMode(col[thisPin], OUTPUT); - pinMode(row[thisPin], OUTPUT); + pinMode(col[thisPin], OUTPUT); + pinMode(row[thisPin], OUTPUT); // take the col pins (i.e. the cathodes) high to ensure that - // the LEDS are off: - digitalWrite(col[thisPin], HIGH); + // the LEDS are off: + digitalWrite(col[thisPin], HIGH); } // initialize the pixel matrix: diff --git a/build/shared/examples/07.Display/barGraph/barGraph.ino b/build/shared/examples/07.Display/barGraph/barGraph.ino index 646cd4744..2de75b8a4 100644 --- a/build/shared/examples/07.Display/barGraph/barGraph.ino +++ b/build/shared/examples/07.Display/barGraph/barGraph.ino @@ -1,22 +1,22 @@ /* LED bar graph - + Turns on a series of LEDs based on the value of an analog sensor. This is a simple way to make a bar graph display. Though this graph uses 10 LEDs, you can use any number by changing the LED count and the pins in the array. - + This method can be used to control any series of digital outputs that depends on an analog input. - + The circuit: * LEDs from pins 2 through 11 to ground - + created 4 Sep 2010 - by Tom Igoe + by Tom Igoe This example code is in the public domain. - + http://www.arduino.cc/en/Tutorial/BarGraph */ @@ -25,14 +25,15 @@ const int analogPin = A0; // the pin that the potentiometer is attached to const int ledCount = 10; // the number of LEDs in the bar graph -int ledPins[] = { - 2, 3, 4, 5, 6, 7,8,9,10,11 }; // an array of pin numbers to which LEDs are attached +int ledPins[] = { + 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 +}; // an array of pin numbers to which LEDs are attached void setup() { // loop over the pin array and set them all to output: for (int thisLed = 0; thisLed < ledCount; thisLed++) { - pinMode(ledPins[thisLed], OUTPUT); + pinMode(ledPins[thisLed], OUTPUT); } } @@ -48,10 +49,10 @@ void loop() { // turn the pin for this element on: if (thisLed < ledLevel) { digitalWrite(ledPins[thisLed], HIGH); - } + } // turn off all pins higher than the ledLevel: else { - digitalWrite(ledPins[thisLed], LOW); + digitalWrite(ledPins[thisLed], LOW); } } } diff --git a/build/shared/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino b/build/shared/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino index b640403b0..d78a5ad21 100644 --- a/build/shared/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino +++ b/build/shared/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino @@ -1,13 +1,13 @@ /* - Character analysis operators - + Character analysis operators + Examples using the character analysis operators. Send any byte and the sketch will tell you about it. - + created 29 Nov 2010 modified 2 Apr 2012 by Tom Igoe - + This example code is in the public domain. */ @@ -35,40 +35,40 @@ void loop() { Serial.println(thisChar); // analyze what was sent: - if(isAlphaNumeric(thisChar)) { + if (isAlphaNumeric(thisChar)) { Serial.println("it's alphanumeric"); } - if(isAlpha(thisChar)) { + if (isAlpha(thisChar)) { Serial.println("it's alphabetic"); } - if(isAscii(thisChar)) { + if (isAscii(thisChar)) { Serial.println("it's ASCII"); } - if(isWhitespace(thisChar)) { + if (isWhitespace(thisChar)) { Serial.println("it's whitespace"); } - if(isControl(thisChar)) { + if (isControl(thisChar)) { Serial.println("it's a control character"); } - if(isDigit(thisChar)) { + if (isDigit(thisChar)) { Serial.println("it's a numeric digit"); } - if(isGraph(thisChar)) { + if (isGraph(thisChar)) { Serial.println("it's a printable character that's not whitespace"); } - if(isLowerCase(thisChar)) { + if (isLowerCase(thisChar)) { Serial.println("it's lower case"); } - if(isPrintable(thisChar)) { + if (isPrintable(thisChar)) { Serial.println("it's printable"); } - if(isPunct(thisChar)) { + if (isPunct(thisChar)) { Serial.println("it's punctuation"); } - if(isSpace(thisChar)) { + if (isSpace(thisChar)) { Serial.println("it's a space character"); } - if(isUpperCase(thisChar)) { + if (isUpperCase(thisChar)) { Serial.println("it's upper case"); } if (isHexadecimalDigit(thisChar)) { diff --git a/build/shared/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino b/build/shared/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino index d7c2c4493..ff8f393d6 100644 --- a/build/shared/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino +++ b/build/shared/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino @@ -1,16 +1,16 @@ /* Adding Strings together - + Examples of how to add strings together You can also add several different data types to string, as shown here: - + created 27 July 2010 modified 2 Apr 2012 by Tom Igoe - + http://arduino.cc/en/Tutorial/StringAdditionOperator - - This example code is in the public domain. + + This example code is in the public domain. */ // declare three strings: @@ -59,10 +59,10 @@ void loop() { // adding a variable long integer to a string: long currentTime = millis(); - stringOne="millis() value: "; + stringOne = "millis() value: "; stringThree = stringOne + millis(); Serial.println(stringThree); // prints "The millis: 345345" or whatever value currentTime has // do nothing while true: - while(true); + while (true); } diff --git a/build/shared/examples/08.Strings/StringAppendOperator/StringAppendOperator.ino b/build/shared/examples/08.Strings/StringAppendOperator/StringAppendOperator.ino index 1ef19f21b..4e9062fef 100644 --- a/build/shared/examples/08.Strings/StringAppendOperator/StringAppendOperator.ino +++ b/build/shared/examples/08.Strings/StringAppendOperator/StringAppendOperator.ino @@ -1,14 +1,14 @@ /* Appending to Strings using the += operator and concat() - + Examples of how to append different data types to strings - + created 27 July 2010 modified 2 Apr 2012 by Tom Igoe - + http://arduino.cc/en/Tutorial/StringAppendOperator - + This example code is in the public domain. */ @@ -68,6 +68,6 @@ void loop() { Serial.println(stringTwo); // prints "The millis(): 43534" or whatever the value of the millis() is // do nothing while true: - while(true); + while (true); } diff --git a/build/shared/examples/08.Strings/StringCaseChanges/StringCaseChanges.ino b/build/shared/examples/08.Strings/StringCaseChanges/StringCaseChanges.ino index 675ab8e19..6efc3aed7 100644 --- a/build/shared/examples/08.Strings/StringCaseChanges/StringCaseChanges.ino +++ b/build/shared/examples/08.Strings/StringCaseChanges/StringCaseChanges.ino @@ -1,14 +1,14 @@ /* String Case changes - + Examples of how to change the case of a string - + created 27 July 2010 modified 2 Apr 2012 by Tom Igoe - + http://arduino.cc/en/Tutorial/StringCaseChanges - + This example code is in the public domain. */ @@ -31,7 +31,7 @@ void loop() { stringOne.toUpperCase(); Serial.println(stringOne); - // toLowerCase() changes all letters to lower case: + // toLowerCase() changes all letters to lower case: String stringTwo = ""; Serial.println(stringTwo); stringTwo.toLowerCase(); @@ -39,5 +39,5 @@ void loop() { // do nothing while true: - while(true); + while (true); } diff --git a/build/shared/examples/08.Strings/StringCharacters/StringCharacters.ino b/build/shared/examples/08.Strings/StringCharacters/StringCharacters.ino index 5db17b44c..f961c0738 100644 --- a/build/shared/examples/08.Strings/StringCharacters/StringCharacters.ino +++ b/build/shared/examples/08.Strings/StringCharacters/StringCharacters.ino @@ -1,14 +1,14 @@ /* String charAt() and setCharAt() - + Examples of how to get and set characters of a String - + created 27 July 2010 modified 2 Apr 2012 by Tom Igoe - + http://arduino.cc/en/Tutorial/StringCharacters - + This example code is in the public domain. */ @@ -30,17 +30,17 @@ void loop() { // the reading's most significant digit is at position 15 in the reportString: char mostSignificantDigit = reportString.charAt(15); - String message = "Most significant digit of the sensor reading is: "; + String message = "Most significant digit of the sensor reading is: "; Serial.println(message + mostSignificantDigit); // add blank space: Serial.println(); // you can alo set the character of a string. Change the : to a = character - reportString.setCharAt(13, '='); + reportString.setCharAt(13, '='); Serial.println(reportString); // do nothing while true: - while(true); + while (true); } diff --git a/build/shared/examples/08.Strings/StringComparisonOperators/StringComparisonOperators.ino b/build/shared/examples/08.Strings/StringComparisonOperators/StringComparisonOperators.ino index dc468ee4e..85bcfb5a3 100644 --- a/build/shared/examples/08.Strings/StringComparisonOperators/StringComparisonOperators.ino +++ b/build/shared/examples/08.Strings/StringComparisonOperators/StringComparisonOperators.ino @@ -1,14 +1,14 @@ /* - Comparing Strings - + Comparing Strings + Examples of how to compare strings using the comparison operators - + created 27 July 2010 modified 2 Apr 2012 by Tom Igoe - + http://arduino.cc/en/Tutorial/StringComparisonOperators - + This example code is in the public domain. */ @@ -33,7 +33,7 @@ void setup() { void loop() { // two strings equal: if (stringOne == "this") { - Serial.println("StringOne == \"this\""); + Serial.println("StringOne == \"this\""); } // two strings not equal: if (stringOne != stringTwo) { @@ -49,7 +49,7 @@ 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 { Serial.println(stringOne + " does not equal " + stringTwo); } @@ -57,7 +57,7 @@ void loop() { // or perhaps you want to ignore case: if (stringOne.equalsIgnoreCase(stringTwo)) { Serial.println(stringOne + " equals (ignoring case) " + stringTwo); - } + } else { Serial.println(stringOne + " does not equal (ignoring case) " + stringTwo); } @@ -81,20 +81,20 @@ void loop() { // comparison operators can be used to compare strings for alphabetic sorting too: stringOne = String("Brown"); if (stringOne < "Charles") { - Serial.println(stringOne + " < Charles"); + Serial.println(stringOne + " < Charles"); } if (stringOne > "Adams") { - Serial.println(stringOne + " > Adams"); + Serial.println(stringOne + " > Adams"); } if (stringOne <= "Browne") { - Serial.println(stringOne + " <= Browne"); + Serial.println(stringOne + " <= Browne"); } if (stringOne >= "Brow") { - Serial.println(stringOne + " >= Brow"); + Serial.println(stringOne + " >= Brow"); } // the compareTo() operator also allows you to compare strings @@ -104,10 +104,10 @@ void loop() { stringOne = "Cucumber"; stringTwo = "Cucuracha"; if (stringOne.compareTo(stringTwo) < 0 ) { - Serial.println(stringOne + " comes before " + stringTwo); - } + Serial.println(stringOne + " comes before " + stringTwo); + } else { - Serial.println(stringOne + " comes after " + stringTwo); + Serial.println(stringOne + " comes after " + stringTwo); } delay(10000); // because the next part is a loop: @@ -116,16 +116,16 @@ void loop() { while (true) { stringOne = "Sensor: "; - stringTwo= "Sensor: "; + stringTwo = "Sensor: "; - stringOne += analogRead(A0); + stringOne += analogRead(A0); stringTwo += analogRead(A5); if (stringOne.compareTo(stringTwo) < 0 ) { - Serial.println(stringOne + " comes before " + stringTwo); - } + Serial.println(stringOne + " comes before " + stringTwo); + } else { - Serial.println(stringOne + " comes after " + stringTwo); + Serial.println(stringOne + " comes after " + stringTwo); } } diff --git a/build/shared/examples/08.Strings/StringConstructors/StringConstructors.ino b/build/shared/examples/08.Strings/StringConstructors/StringConstructors.ino index d823cda10..08810e448 100644 --- a/build/shared/examples/08.Strings/StringConstructors/StringConstructors.ino +++ b/build/shared/examples/08.Strings/StringConstructors/StringConstructors.ino @@ -1,14 +1,14 @@ /* String constructors - + Examples of how to create strings from other data types - + created 27 July 2010 modified 30 Aug 2011 by Tom Igoe - + http://arduino.cc/en/Tutorial/StringConstructors - + This example code is in the public domain. */ @@ -18,7 +18,7 @@ void setup() { while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } - + // send an intro: Serial.println("\n\nString Constructors:"); Serial.println(); @@ -26,47 +26,47 @@ void setup() { void loop() { // using a constant String: - String stringOne = "Hello String"; + String stringOne = "Hello String"; Serial.println(stringOne); // prints "Hello String" // converting a constant char into a String: - stringOne = String('a'); + stringOne = String('a'); Serial.println(stringOne); // prints "a" // converting a constant string into a String object: - String stringTwo = String("This is a string"); + String stringTwo = String("This is a string"); Serial.println(stringTwo); // prints "This is a string" // concatenating two strings: - stringOne = String(stringTwo + " with more"); + stringOne = String(stringTwo + " with more"); // prints "This is a string with more": - Serial.println(stringOne); + Serial.println(stringOne); // using a constant integer: - stringOne = String(13); + stringOne = String(13); Serial.println(stringOne); // prints "13" // using an int and a base: - stringOne = String(analogRead(A0), DEC); + stringOne = String(analogRead(A0), DEC); // prints "453" or whatever the value of analogRead(A0) is - Serial.println(stringOne); + Serial.println(stringOne); // using an int and a base (hexadecimal): - stringOne = String(45, HEX); + stringOne = String(45, HEX); // prints "2d", which is the hexadecimal version of decimal 45: - Serial.println(stringOne); + Serial.println(stringOne); // using an int and a base (binary) - stringOne = String(255, BIN); + stringOne = String(255, BIN); // prints "11111111" which is the binary value of 255 - Serial.println(stringOne); + Serial.println(stringOne); // using a long and a base: stringOne = String(millis(), DEC); - // prints "123456" or whatever the value of millis() is: - Serial.println(stringOne); + // prints "123456" or whatever the value of millis() is: + Serial.println(stringOne); // do nothing while true: - while(true); + while (true); } diff --git a/build/shared/examples/08.Strings/StringIndexOf/StringIndexOf.ino b/build/shared/examples/08.Strings/StringIndexOf/StringIndexOf.ino index b943c1639..97b5c84a1 100644 --- a/build/shared/examples/08.Strings/StringIndexOf/StringIndexOf.ino +++ b/build/shared/examples/08.Strings/StringIndexOf/StringIndexOf.ino @@ -1,15 +1,15 @@ /* String indexOf() and lastIndexOf() functions - + Examples of how to evaluate, look for, and replace characters in a String - + created 27 July 2010 modified 2 Apr 2012 by Tom Igoe - + http://arduino.cc/en/Tutorial/StringIndexOf - - This example code is in the public domain. + + This example code is in the public domain. */ void setup() { @@ -61,6 +61,6 @@ void loop() { Serial.println("The index of the second last paragraph tag " + stringOne + " is " + secondLastGraf); // do nothing while true: - while(true); + while (true); } diff --git a/build/shared/examples/08.Strings/StringLength/StringLength.ino b/build/shared/examples/08.Strings/StringLength/StringLength.ino index 152169813..070412462 100644 --- a/build/shared/examples/08.Strings/StringLength/StringLength.ino +++ b/build/shared/examples/08.Strings/StringLength/StringLength.ino @@ -1,14 +1,14 @@ /* - String length() - - Examples of how to use length() in a String. + String length() + + Examples of how to use length() in a String. Open the Serial Monitor and start sending characters to see the results. - + created 1 Aug 2010 by Tom Igoe - + http://arduino.cc/en/Tutorial/StringLengthTrim - + This example code is in the public domain. */ @@ -32,7 +32,7 @@ void loop() { while (Serial.available() > 0) { char inChar = Serial.read(); txtMsg += inChar; - } + } // print the message and a notice if it's changed: if (txtMsg.length() != lastStringLength) { @@ -41,9 +41,9 @@ 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 { - Serial.println("That's too long for a text message."); + Serial.println("That's too long for a text message."); } // note the length for next time through the loop: lastStringLength = txtMsg.length(); diff --git a/build/shared/examples/08.Strings/StringLengthTrim/StringLengthTrim.ino b/build/shared/examples/08.Strings/StringLengthTrim/StringLengthTrim.ino index 8f7009248..055b24945 100644 --- a/build/shared/examples/08.Strings/StringLengthTrim/StringLengthTrim.ino +++ b/build/shared/examples/08.Strings/StringLengthTrim/StringLengthTrim.ino @@ -1,14 +1,14 @@ /* String length() and trim() - + Examples of how to use length() and trim() in a String - + created 27 July 2010 modified 2 Apr 2012 by Tom Igoe - + http://arduino.cc/en/Tutorial/StringLengthTrim - + This example code is in the public domain. */ @@ -38,5 +38,5 @@ void loop() { Serial.println(stringOne.length()); // do nothing while true: - while(true); + while (true); } diff --git a/build/shared/examples/08.Strings/StringReplace/StringReplace.ino b/build/shared/examples/08.Strings/StringReplace/StringReplace.ino index b5e39dc38..311974168 100644 --- a/build/shared/examples/08.Strings/StringReplace/StringReplace.ino +++ b/build/shared/examples/08.Strings/StringReplace/StringReplace.ino @@ -1,15 +1,15 @@ /* String replace() - + Examples of how to replace characters or substrings of a string - + created 27 July 2010 modified 2 Apr 2012 by Tom Igoe - + http://arduino.cc/en/Tutorial/StringReplace - - This example code is in the public domain. + + This example code is in the public domain. */ void setup() { @@ -46,5 +46,5 @@ void loop() { Serial.println("l33tspeak: " + leetString); // do nothing while true: - while(true); + while (true); } diff --git a/build/shared/examples/08.Strings/StringStartsWithEndsWith/StringStartsWithEndsWith.ino b/build/shared/examples/08.Strings/StringStartsWithEndsWith/StringStartsWithEndsWith.ino index b2509e56d..db9dc9979 100644 --- a/build/shared/examples/08.Strings/StringStartsWithEndsWith/StringStartsWithEndsWith.ino +++ b/build/shared/examples/08.Strings/StringStartsWithEndsWith/StringStartsWithEndsWith.ino @@ -1,14 +1,14 @@ /* String startWith() and endsWith() - + Examples of how to use startsWith() and endsWith() in a String - + created 27 July 2010 modified 2 Apr 2012 by Tom Igoe - + http://arduino.cc/en/Tutorial/StringStartsWithEndsWith - + This example code is in the public domain. */ @@ -29,27 +29,27 @@ void loop() { String stringOne = "HTTP/1.1 200 OK"; Serial.println(stringOne); if (stringOne.startsWith("HTTP/1.1")) { - Serial.println("Server's using http version 1.1"); - } + Serial.println("Server's using http version 1.1"); + } // you can also look for startsWith() at an offset position in the string: stringOne = "HTTP/1.1 200 OK"; if (stringOne.startsWith("200 OK", 9)) { - Serial.println("Got an OK from the server"); - } + Serial.println("Got an OK from the server"); + } // endsWith() checks to see if a String ends with a particular character: String sensorReading = "sensor = "; sensorReading += analogRead(A0); Serial.print (sensorReading); if (sensorReading.endsWith(0)) { - Serial.println(". This reading is divisible by ten"); - } + Serial.println(". This reading is divisible by ten"); + } else { - Serial.println(". This reading is not divisible by ten"); + Serial.println(". This reading is not divisible by ten"); } // do nothing while true: - while(true); + while (true); } diff --git a/build/shared/examples/08.Strings/StringSubstring/StringSubstring.ino b/build/shared/examples/08.Strings/StringSubstring/StringSubstring.ino index 4d6cff0fd..80404270e 100644 --- a/build/shared/examples/08.Strings/StringSubstring/StringSubstring.ino +++ b/build/shared/examples/08.Strings/StringSubstring/StringSubstring.ino @@ -1,14 +1,14 @@ /* String substring() - + Examples of how to use substring in a String - - created 27 July 2010, + + created 27 July 2010, modified 2 Apr 2012 by Zach Eveland - + http://arduino.cc/en/Tutorial/StringSubstring - + This example code is in the public domain. */ @@ -31,13 +31,13 @@ void loop() { // substring(index) looks for the substring from the index position to the end: if (stringOne.substring(19) == "html") { - Serial.println("It's an html file"); - } + Serial.println("It's an html file"); + } // you can also look for a substring in the middle of a string: - if (stringOne.substring(14,18) == "text") { - Serial.println("It's a text-based file"); - } + if (stringOne.substring(14, 18) == "text") { + Serial.println("It's a text-based file"); + } // do nothing while true: - while(true); + while (true); } diff --git a/build/shared/examples/08.Strings/StringToInt/StringToInt.ino b/build/shared/examples/08.Strings/StringToInt/StringToInt.ino index 68b96cec5..89f7e8b1e 100644 --- a/build/shared/examples/08.Strings/StringToInt/StringToInt.ino +++ b/build/shared/examples/08.Strings/StringToInt/StringToInt.ino @@ -1,16 +1,16 @@ /* String to Integer conversion - + Reads a serial input string until it sees a newline, then converts the string to a number if the characters are digits. - + The circuit: No external components needed. - + created 29 Nov 2010 by Tom Igoe - - This example code is in the public domain. + + This example code is in the public domain. */ String inString = ""; // string to hold input @@ -32,9 +32,9 @@ void loop() { while (Serial.available() > 0) { int inChar = Serial.read(); if (isDigit(inChar)) { - // convert the incoming byte to a char + // convert the incoming byte to a char // and add it to the string: - inString += (char)inChar; + inString += (char)inChar; } // if you get a newline, print the string, // then the string's value: @@ -44,7 +44,7 @@ void loop() { Serial.print("String: "); Serial.println(inString); // clear the string for new input: - inString = ""; + inString = ""; } } } diff --git a/build/shared/examples/08.Strings/StringToIntRGB/StringToIntRGB.ino b/build/shared/examples/08.Strings/StringToIntRGB/StringToIntRGB.ino index 9f1658fd5..f79b95283 100644 --- a/build/shared/examples/08.Strings/StringToIntRGB/StringToIntRGB.ino +++ b/build/shared/examples/08.Strings/StringToIntRGB/StringToIntRGB.ino @@ -1,23 +1,23 @@ /* Serial RGB controller - + Reads a serial input string looking for three comma-separated - integers with a newline at the end. Values should be between - 0 and 255. The sketch uses those values to set the color + integers with a newline at the end. Values should be between + 0 and 255. The sketch uses those values to set the color of an RGB LED attached to pins 9 - 11. - + The circuit: * Common-anode RGB LED cathodes attached to pins 9 - 11 * LED anode connected to pin 13 - - To turn on any given channel, set the pin LOW. + + To turn on any given channel, set the pin LOW. To turn off, set the pin HIGH. The higher the analogWrite level, the lower the brightness. - + created 29 Nov 2010 by Tom Igoe - - This example code is in the public domain. + + This example code is in the public domain. */ String inString = ""; // string to hold input @@ -52,9 +52,9 @@ void loop() { } if (isDigit(inChar)) { - // convert the incoming byte to a char + // convert the incoming byte to a char // and add it to the string: - inString += (char)inChar; + inString += (char)inChar; } // if you get a comma, convert to a number, @@ -63,16 +63,16 @@ void loop() { if (inChar == ',') { // do something different for each value of currentColor: switch (currentColor) { - case 0: // 0 = red - red = inString.toInt(); - // clear the string for new input: - inString = ""; - break; - case 1: // 1 = green: - green = inString.toInt(); - // clear the string for new input: - inString = ""; - break; + case 0: // 0 = red + red = inString.toInt(); + // clear the string for new input: + inString = ""; + break; + case 1: // 1 = green: + green = inString.toInt(); + // clear the string for new input: + inString = ""; + break; } currentColor++; } @@ -98,7 +98,7 @@ void loop() { Serial.println(blue); // clear the string for new input: - inString = ""; + inString = ""; // reset the color counter: currentColor = 0; } @@ -109,33 +109,33 @@ void loop() { /* Here's a Processing sketch that will draw a color wheel and send a serial string with the color you click on: - + // Subtractive Color Wheel with Serial - // Based on a Processing example by Ira Greenberg. + // Based on a Processing example by Ira Greenberg. // Serial output added by Tom Igoe - // - // The primaries are red, yellow, and blue. The secondaries are green, - // purple, and orange. The tertiaries are yellow-orange, red-orange, + // + // The primaries are red, yellow, and blue. The secondaries are green, + // purple, and orange. The tertiaries are yellow-orange, red-orange, // red-purple, blue-purple, blue-green, and yellow-green. - // + // // Create a shade or tint of the subtractive color wheel using // SHADE or TINT parameters. - + // Updated 29 November 2010. - - - + + + import processing.serial.*; - + int segs = 12; int steps = 6; float rotAdjust = TWO_PI / segs / 2; float radius; float segWidth; float interval = TWO_PI / segs; - + Serial myPort; - + void setup() { size(200, 200); background(127); @@ -145,70 +145,70 @@ Here's a Processing sketch that will draw a color wheel and send a serial // make the diameter 90% of the sketch area radius = min(width, height) * 0.45; segWidth = radius / steps; - + // swap which line is commented out to draw the other version // drawTintWheel(); drawShadeWheel(); // open the first serial port in your computer's list myPort = new Serial(this, Serial.list()[0], 9600); } - - + + void drawShadeWheel() { for (int j = 0; j < steps; j++) { - color[] cols = { - color(255-(255/steps)*j, 255-(255/steps)*j, 0), - color(255-(255/steps)*j, (255/1.5)-((255/1.5)/steps)*j, 0), - color(255-(255/steps)*j, (255/2)-((255/2)/steps)*j, 0), - color(255-(255/steps)*j, (255/2.5)-((255/2.5)/steps)*j, 0), - color(255-(255/steps)*j, 0, 0), - color(255-(255/steps)*j, 0, (255/2)-((255/2)/steps)*j), - color(255-(255/steps)*j, 0, 255-(255/steps)*j), - color((255/2)-((255/2)/steps)*j, 0, 255-(255/steps)*j), + color[] cols = { + color(255-(255/steps)*j, 255-(255/steps)*j, 0), + color(255-(255/steps)*j, (255/1.5)-((255/1.5)/steps)*j, 0), + color(255-(255/steps)*j, (255/2)-((255/2)/steps)*j, 0), + color(255-(255/steps)*j, (255/2.5)-((255/2.5)/steps)*j, 0), + color(255-(255/steps)*j, 0, 0), + color(255-(255/steps)*j, 0, (255/2)-((255/2)/steps)*j), + color(255-(255/steps)*j, 0, 255-(255/steps)*j), + color((255/2)-((255/2)/steps)*j, 0, 255-(255/steps)*j), color(0, 0, 255-(255/steps)*j), - color(0, 255-(255/steps)*j, (255/2.5)-((255/2.5)/steps)*j), - color(0, 255-(255/steps)*j, 0), + color(0, 255-(255/steps)*j, (255/2.5)-((255/2.5)/steps)*j), + color(0, 255-(255/steps)*j, 0), color((255/2)-((255/2)/steps)*j, 255-(255/steps)*j, 0) }; for (int i = 0; i < segs; i++) { fill(cols[i]); - arc(width/2, height/2, radius, radius, + arc(width/2, height/2, radius, radius, interval*i+rotAdjust, interval*(i+1)+rotAdjust); } radius -= segWidth; } } - - + + void drawTintWheel() { for (int j = 0; j < steps; j++) { - color[] cols = { - color((255/steps)*j, (255/steps)*j, 0), - color((255/steps)*j, ((255/1.5)/steps)*j, 0), - color((255/steps)*j, ((255/2)/steps)*j, 0), - color((255/steps)*j, ((255/2.5)/steps)*j, 0), - color((255/steps)*j, 0, 0), - color((255/steps)*j, 0, ((255/2)/steps)*j), - color((255/steps)*j, 0, (255/steps)*j), - color(((255/2)/steps)*j, 0, (255/steps)*j), + color[] cols = { + color((255/steps)*j, (255/steps)*j, 0), + color((255/steps)*j, ((255/1.5)/steps)*j, 0), + color((255/steps)*j, ((255/2)/steps)*j, 0), + color((255/steps)*j, ((255/2.5)/steps)*j, 0), + color((255/steps)*j, 0, 0), + color((255/steps)*j, 0, ((255/2)/steps)*j), + color((255/steps)*j, 0, (255/steps)*j), + color(((255/2)/steps)*j, 0, (255/steps)*j), color(0, 0, (255/steps)*j), - color(0, (255/steps)*j, ((255/2.5)/steps)*j), - color(0, (255/steps)*j, 0), + color(0, (255/steps)*j, ((255/2.5)/steps)*j), + color(0, (255/steps)*j, 0), color(((255/2)/steps)*j, (255/steps)*j, 0) }; for (int i = 0; i < segs; i++) { fill(cols[i]); - arc(width/2, height/2, radius, radius, + arc(width/2, height/2, radius, radius, interval*i+rotAdjust, interval*(i+1)+rotAdjust); } radius -= segWidth; } } - + void draw() { // nothing happens here } - + void mouseReleased() { // get the color of the mouse position's pixel: color targetColor = get(mouseX, mouseY); @@ -221,7 +221,7 @@ Here's a Processing sketch that will draw a color wheel and send a serial // send it out the serial port: myPort.write(colorString ); } - + */ diff --git a/build/shared/examples/09.USB/Keyboard/KeyboardLogout/KeyboardLogout.ino b/build/shared/examples/09.USB/Keyboard/KeyboardLogout/KeyboardLogout.ino index 9abaaf88f..f00256fa7 100644 --- a/build/shared/examples/09.USB/Keyboard/KeyboardLogout/KeyboardLogout.ino +++ b/build/shared/examples/09.USB/Keyboard/KeyboardLogout/KeyboardLogout.ino @@ -1,30 +1,30 @@ /* Keyboard logout - + This sketch demonstrates the Keyboard library. - - When you connect pin 2 to ground, it performs a logout. + + When you connect pin 2 to ground, it performs a logout. It uses keyboard combinations to do this, as follows: - + On Windows, CTRL-ALT-DEL followed by ALT-l On Ubuntu, CTRL-ALT-DEL, and ENTER On OSX, CMD-SHIFT-q - - To wake: Spacebar. - + + To wake: Spacebar. + Circuit: * Arduino Leonardo or Micro * wire to connect D2 to ground. - + created 6 Mar 2012 modified 27 Mar 2012 by Tom Igoe - + This example is in the public domain - + http://www.arduino.cc/en/Tutorial/KeyboardLogout */ - + #define OSX 0 #define WINDOWS 1 #define UBUNTU 2 @@ -33,13 +33,13 @@ int platform = OSX; void setup() { - // make pin 2 an input and turn on the + // make pin 2 an input and turn on the // pullup resistor so it goes high unless // connected to ground: pinMode(2, INPUT_PULLUP); Keyboard.begin(); } - + void loop() { while (digitalRead(2) == HIGH) { // do nothing until pin 2 goes low @@ -48,43 +48,43 @@ void loop() { delay(1000); switch (platform) { - case OSX: - Keyboard.press(KEY_LEFT_GUI); - // Shift-Q logs out: - Keyboard.press(KEY_LEFT_SHIFT); - Keyboard.press('Q'); - delay(100); - Keyboard.releaseAll(); - // enter: - Keyboard.write(KEY_RETURN); - break; - case WINDOWS: - // CTRL-ALT-DEL: - Keyboard.press(KEY_LEFT_CTRL); - Keyboard.press(KEY_LEFT_ALT); - Keyboard.press(KEY_DELETE); - delay(100); - Keyboard.releaseAll(); - //ALT-s: - delay(2000); - Keyboard.press(KEY_LEFT_ALT); - Keyboard.press('l'); - Keyboard.releaseAll(); - break; - case UBUNTU: - // CTRL-ALT-DEL: - Keyboard.press(KEY_LEFT_CTRL); - Keyboard.press(KEY_LEFT_ALT); - Keyboard.press(KEY_DELETE); - delay(1000); - Keyboard.releaseAll(); - // Enter to confirm logout: - Keyboard.write(KEY_RETURN); - break; + case OSX: + Keyboard.press(KEY_LEFT_GUI); + // Shift-Q logs out: + Keyboard.press(KEY_LEFT_SHIFT); + Keyboard.press('Q'); + delay(100); + Keyboard.releaseAll(); + // enter: + Keyboard.write(KEY_RETURN); + break; + case WINDOWS: + // CTRL-ALT-DEL: + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press(KEY_LEFT_ALT); + Keyboard.press(KEY_DELETE); + delay(100); + Keyboard.releaseAll(); + //ALT-s: + delay(2000); + Keyboard.press(KEY_LEFT_ALT); + Keyboard.press('l'); + Keyboard.releaseAll(); + break; + case UBUNTU: + // CTRL-ALT-DEL: + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press(KEY_LEFT_ALT); + Keyboard.press(KEY_DELETE); + delay(1000); + Keyboard.releaseAll(); + // Enter to confirm logout: + Keyboard.write(KEY_RETURN); + break; } // do nothing: - while(true); + while (true); } diff --git a/build/shared/examples/09.USB/Keyboard/KeyboardMessage/KeyboardMessage.ino b/build/shared/examples/09.USB/Keyboard/KeyboardMessage/KeyboardMessage.ino index f84891352..de2889814 100644 --- a/build/shared/examples/09.USB/Keyboard/KeyboardMessage/KeyboardMessage.ino +++ b/build/shared/examples/09.USB/Keyboard/KeyboardMessage/KeyboardMessage.ino @@ -1,21 +1,21 @@ -/* +/* Keyboard Button test For the Arduino Leonardo, Micro and Due boards. - + Sends a text string when a button is pressed. - + The circuit: - * pushbutton attached from pin 2 to +5V on AVR boards + * pushbutton attached from pin 2 to +5V on AVR boards and to +3.3V to the Arduino Due * 10-kilohm resistor attached from pin 2 to ground - + created 24 Oct 2011 modified 27 Mar 2012 by Tom Igoe - + This example code is in the public domain. - + http://www.arduino.cc/en/Tutorial/KeyboardButton */ @@ -33,18 +33,18 @@ void setup() { void loop() { // read the pushbutton: int buttonState = digitalRead(buttonPin); - // if the button state has changed, - if ((buttonState != previousButtonState) - // and it's currently pressed: - && (buttonState == HIGH)) { + // if the button state has changed, + if ((buttonState != previousButtonState) + // and it's currently pressed: + && (buttonState == HIGH)) { // increment the button counter counter++; // type out a message Keyboard.print("You pressed the button "); - Keyboard.print(counter); + Keyboard.print(counter); Keyboard.println(" times."); } // save the current button state for comparison next time: - previousButtonState = buttonState; + previousButtonState = buttonState; } diff --git a/build/shared/examples/09.USB/Keyboard/KeyboardReprogram/KeyboardReprogram.ino b/build/shared/examples/09.USB/Keyboard/KeyboardReprogram/KeyboardReprogram.ino index 196fb1c76..c4f578689 100644 --- a/build/shared/examples/09.USB/Keyboard/KeyboardReprogram/KeyboardReprogram.ino +++ b/build/shared/examples/09.USB/Keyboard/KeyboardReprogram/KeyboardReprogram.ino @@ -1,40 +1,40 @@ /* Arduino Programs Blink - + This sketch demonstrates the Keyboard library. - + For Leonardo and Due boards only. - + When you connect pin 2 to ground, it creates a new window with a key combination (CTRL-N), then types in the Blink sketch, then auto-formats the text - using another key combination (CTRL-T), then - uploads the sketch to the currently selected Arduino using + using another key combination (CTRL-T), then + uploads the sketch to the currently selected Arduino using a final key combination (CTRL-U). - + Circuit: * Arduino Leonardo, Micro or Due * wire to connect D2 to ground. - + created 5 Mar 2012 modified 29 Mar 2012 by Tom Igoe - + This example is in the public domain - + http://www.arduino.cc/en/Tutorial/KeyboardReprogram */ -// use this option for OSX. +// use this option for OSX. // Comment it out if using Windows or Linux: char ctrlKey = KEY_LEFT_GUI; // use this option for Windows and Linux. // leave commented out if using OSX: -// char ctrlKey = KEY_LEFT_CTRL; +// char ctrlKey = KEY_LEFT_CTRL; void setup() { - // make pin 2 an input and turn on the + // make pin 2 an input and turn on the // pullup resistor so it goes high unless // connected to ground: pinMode(2, INPUT_PULLUP); @@ -65,9 +65,9 @@ void loop() { Keyboard.println("digitalWrite(13, HIGH);"); Keyboard.print("delay(3000);"); // 3000 ms is too long. Delete it: - for (int keystrokes=0; keystrokes < 6; keystrokes++) { + for (int keystrokes = 0; keystrokes < 6; keystrokes++) { delay(500); - Keyboard.write(KEY_BACKSPACE); + Keyboard.write(KEY_BACKSPACE); } // make it 1000 instead: Keyboard.println("1000);"); @@ -87,7 +87,7 @@ void loop() { Keyboard.releaseAll(); // wait for the sweet oblivion of reprogramming: - while(true); + while (true); } diff --git a/build/shared/examples/09.USB/Keyboard/KeyboardSerial/KeyboardSerial.ino b/build/shared/examples/09.USB/Keyboard/KeyboardSerial/KeyboardSerial.ino index 9c485455c..2f98c9116 100644 --- a/build/shared/examples/09.USB/Keyboard/KeyboardSerial/KeyboardSerial.ino +++ b/build/shared/examples/09.USB/Keyboard/KeyboardSerial/KeyboardSerial.ino @@ -1,21 +1,21 @@ -/* +/* Keyboard test - + For the Arduino Leonardo, Micro or Due - + Reads a byte from the serial port, sends a keystroke back. The sent keystroke is one higher than what's received, e.g. if you send a, you get b, send A you get B, and so forth. - + The circuit: * none - + created 21 Oct 2011 modified 27 Mar 2012 by Tom Igoe - + This example code is in the public domain. - + http://www.arduino.cc/en/Tutorial/KeyboardSerial */ @@ -32,7 +32,7 @@ void loop() { // read incoming serial data: char inChar = Serial.read(); // Type the next ASCII value from what you received: - Keyboard.write(inChar+1); - } + Keyboard.write(inChar + 1); + } } diff --git a/build/shared/examples/09.USB/KeyboardAndMouseControl/KeyboardAndMouseControl.ino b/build/shared/examples/09.USB/KeyboardAndMouseControl/KeyboardAndMouseControl.ino index 3c684f654..b41512ac3 100644 --- a/build/shared/examples/09.USB/KeyboardAndMouseControl/KeyboardAndMouseControl.ino +++ b/build/shared/examples/09.USB/KeyboardAndMouseControl/KeyboardAndMouseControl.ino @@ -3,38 +3,38 @@ KeyboardAndMouseControl Controls the mouse from five pushbuttons on an Arduino Leonardo, Micro or Due. - + Hardware: * 5 pushbuttons attached to D2, D3, D4, D5, D6 - - The mouse movement is always relative. This sketch reads + + The mouse movement is always relative. This sketch reads four pushbuttons, and uses them to set the movement of the mouse. - + WARNING: When you use the Mouse.move() command, the Arduino takes over your mouse! Make sure you have control before you use the mouse commands. - + created 15 Mar 2012 modified 27 Mar 2012 by Tom Igoe - + this code is in the public domain - + */ // set pin numbers for the five buttons: -const int upButton = 2; -const int downButton = 3; +const int upButton = 2; +const int downButton = 3; const int leftButton = 4; const int rightButton = 5; const int mouseButton = 6; void setup() { // initialize the buttons' inputs: - pinMode(upButton, INPUT); - pinMode(downButton, INPUT); - pinMode(leftButton, INPUT); - pinMode(rightButton, INPUT); + pinMode(upButton, INPUT); + pinMode(downButton, INPUT); + pinMode(leftButton, INPUT); + pinMode(rightButton, INPUT); pinMode(mouseButton, INPUT); - + Serial.begin(9600); // initialize mouse control: Mouse.begin(); @@ -46,45 +46,45 @@ void loop() { if (Serial.available() > 0) { char inChar = Serial.read(); - switch (inChar) { - case 'u': - // move mouse up - Mouse.move(0, -40); - break; - case 'd': - // move mouse down - Mouse.move(0, 40); - break; - case 'l': - // move mouse left - Mouse.move(-40, 0); - break; - case 'r': - // move mouse right - Mouse.move(40, 0); - break; - case 'm': - // perform mouse left click - Mouse.click(MOUSE_LEFT); - break; + switch (inChar) { + case 'u': + // move mouse up + Mouse.move(0, -40); + break; + case 'd': + // move mouse down + Mouse.move(0, 40); + break; + case 'l': + // move mouse left + Mouse.move(-40, 0); + break; + case 'r': + // move mouse right + Mouse.move(40, 0); + break; + case 'm': + // perform mouse left click + Mouse.click(MOUSE_LEFT); + break; } } // use the pushbuttons to control the keyboard: if (digitalRead(upButton) == HIGH) { - Keyboard.write('u'); + Keyboard.write('u'); } if (digitalRead(downButton) == HIGH) { - Keyboard.write('d'); + Keyboard.write('d'); } if (digitalRead(leftButton) == HIGH) { - Keyboard.write('l'); + Keyboard.write('l'); } if (digitalRead(rightButton) == HIGH) { - Keyboard.write('r'); + Keyboard.write('r'); } if (digitalRead(mouseButton) == HIGH) { - Keyboard.write('m'); + Keyboard.write('m'); } } diff --git a/build/shared/examples/09.USB/Mouse/ButtonMouseControl/ButtonMouseControl.ino b/build/shared/examples/09.USB/Mouse/ButtonMouseControl/ButtonMouseControl.ino index 7b7cf98f7..3a5629fb1 100644 --- a/build/shared/examples/09.USB/Mouse/ButtonMouseControl/ButtonMouseControl.ino +++ b/build/shared/examples/09.USB/Mouse/ButtonMouseControl/ButtonMouseControl.ino @@ -2,31 +2,31 @@ /* ButtonMouseControl - For Leonardo and Due boards only. - + For Leonardo and Due boards only. + Controls the mouse from five pushbuttons on an Arduino Leonardo, Micro or Due. - + Hardware: * 5 pushbuttons attached to D2, D3, D4, D5, D6 - - - The mouse movement is always relative. This sketch reads + + + The mouse movement is always relative. This sketch reads four pushbuttons, and uses them to set the movement of the mouse. - + WARNING: When you use the Mouse.move() command, the Arduino takes over your mouse! Make sure you have control before you use the mouse commands. - + created 15 Mar 2012 modified 27 Mar 2012 by Tom Igoe - + this code is in the public domain - + */ // set pin numbers for the five buttons: -const int upButton = 2; -const int downButton = 3; +const int upButton = 2; +const int downButton = 3; const int leftButton = 4; const int rightButton = 5; const int mouseButton = 6; @@ -37,10 +37,10 @@ int responseDelay = 10; // response delay of the mouse, in ms void setup() { // initialize the buttons' inputs: - pinMode(upButton, INPUT); - pinMode(downButton, INPUT); - pinMode(leftButton, INPUT); - pinMode(rightButton, INPUT); + pinMode(upButton, INPUT); + pinMode(downButton, INPUT); + pinMode(leftButton, INPUT); + pinMode(rightButton, INPUT); pinMode(mouseButton, INPUT); // initialize mouse control: Mouse.begin(); @@ -55,8 +55,8 @@ void loop() { int clickState = digitalRead(mouseButton); // calculate the movement distance based on the button states: - int xDistance = (leftState - rightState)*range; - int yDistance = (upState - downState)*range; + int xDistance = (leftState - rightState) * range; + int yDistance = (upState - downState) * range; // if X or Y is non-zero, move: if ((xDistance != 0) || (yDistance != 0)) { @@ -67,14 +67,14 @@ void loop() { if (clickState == HIGH) { // if the mouse is not pressed, press it: if (!Mouse.isPressed(MOUSE_LEFT)) { - Mouse.press(MOUSE_LEFT); + Mouse.press(MOUSE_LEFT); } - } + } // else the mouse button is not pressed: else { // if the mouse is pressed, release it: if (Mouse.isPressed(MOUSE_LEFT)) { - Mouse.release(MOUSE_LEFT); + Mouse.release(MOUSE_LEFT); } } diff --git a/build/shared/examples/09.USB/Mouse/JoystickMouseControl/JoystickMouseControl.ino b/build/shared/examples/09.USB/Mouse/JoystickMouseControl/JoystickMouseControl.ino index 5e42ce834..1fcf269cd 100644 --- a/build/shared/examples/09.USB/Mouse/JoystickMouseControl/JoystickMouseControl.ino +++ b/build/shared/examples/09.USB/Mouse/JoystickMouseControl/JoystickMouseControl.ino @@ -1,53 +1,53 @@ /* JoystickMouseControl - + Controls the mouse from a joystick on an Arduino Leonardo, Micro or Due. Uses a pushbutton to turn on and off mouse control, and a second pushbutton to click the left mouse button - + Hardware: * 2-axis joystick connected to pins A0 and A1 * pushbuttons connected to pin D2 and D3 - - The mouse movement is always relative. This sketch reads + + The mouse movement is always relative. This sketch reads two analog inputs that range from 0 to 1023 (or less on either end) - and translates them into ranges of -6 to 6. - The sketch assumes that the joystick resting values are around the + and translates them into ranges of -6 to 6. + The sketch assumes that the joystick resting values are around the middle of the range, but that they vary within a threshold. - + WARNING: When you use the Mouse.move() command, the Arduino takes over your mouse! Make sure you have control before you use the command. This sketch includes a pushbutton to toggle the mouse control state, so you can turn on and off mouse control. - + created 15 Sept 2011 updated 28 Mar 2012 by Tom Igoe - + this code is in the public domain - + */ // set pin numbers for switch, joystick axes, and LED: const int switchPin = 2; // switch to turn on and off mouse control const int mouseButton = 3; // input pin for the mouse pushButton -const int xAxis = A0; // joystick X axis +const int xAxis = A0; // joystick X axis const int yAxis = A1; // joystick Y axis -const int ledPin = 5; // Mouse control LED +const int ledPin = 5; // Mouse control LED // parameters for reading the joystick: int range = 12; // output range of X or Y movement int responseDelay = 5; // response delay of the mouse, in ms -int threshold = range/4; // resting threshold -int center = range/2; // resting position value +int threshold = range / 4; // resting threshold +int center = range / 2; // resting position value boolean mouseIsActive = false; // whether or not to control the mouse int lastSwitchState = LOW; // previous switch state void setup() { pinMode(switchPin, INPUT); // the switch pin - pinMode(ledPin, OUTPUT); // the LED pin - // take control of the mouse: + pinMode(ledPin, OUTPUT); // the LED pin + // take control of the mouse: Mouse.begin(); } @@ -60,7 +60,7 @@ void loop() { mouseIsActive = !mouseIsActive; // turn on LED to indicate mouse state: digitalWrite(ledPin, mouseIsActive); - } + } } // save switch state for next comparison: lastSwitchState = switchState; @@ -72,21 +72,21 @@ void loop() { // if the mouse control state is active, move the mouse: if (mouseIsActive) { Mouse.move(xReading, yReading, 0); - } + } // read the mouse button and click or not click: // if the mouse button is pressed: if (digitalRead(mouseButton) == HIGH) { // if the mouse is not pressed, press it: if (!Mouse.isPressed(MOUSE_LEFT)) { - Mouse.press(MOUSE_LEFT); + Mouse.press(MOUSE_LEFT); } - } + } // else the mouse button is not pressed: else { // if the mouse is pressed, release it: if (Mouse.isPressed(MOUSE_LEFT)) { - Mouse.release(MOUSE_LEFT); + Mouse.release(MOUSE_LEFT); } } @@ -94,11 +94,11 @@ void loop() { } /* - reads an axis (0 or 1 for x or y) and scales the + reads an axis (0 or 1 for x or y) and scales the analog input range to a range from 0 to */ -int readAxis(int thisAxis) { +int readAxis(int thisAxis) { // read the analog input: int reading = analogRead(thisAxis); @@ -111,7 +111,7 @@ int readAxis(int thisAxis) { if (abs(distance) < threshold) { distance = 0; - } + } // return the distance for this axis: return distance; diff --git a/build/shared/examples/10.StarterKit/p02_SpaceshipInterface/p02_SpaceshipInterface.ino b/build/shared/examples/10.StarterKit/p02_SpaceshipInterface/p02_SpaceshipInterface.ino index 84893529a..be2af64a7 100644 --- a/build/shared/examples/10.StarterKit/p02_SpaceshipInterface/p02_SpaceshipInterface.ino +++ b/build/shared/examples/10.StarterKit/p02_SpaceshipInterface/p02_SpaceshipInterface.ino @@ -1,58 +1,58 @@ /* Arduino Starter Kit example Project 2 - Spaceship Interface - + This sketch is written to accompany Project 2 in the Arduino Starter Kit - + Parts required: - 1 green LED + 1 green LED 2 red LEDs pushbutton 10 kilohm resistor 3 220 ohm resistors - + Created 13 September 2012 by Scott Fitzgerald - + http://arduino.cc/starterKit - This example code is part of the public domain + This example code is part of the public domain */ -// Create a global variable to hold the -// state of the switch. This variable is persistent -// throughout the program. Whenever you refer to +// Create a global variable to hold the +// state of the switch. This variable is persistent +// throughout the program. Whenever you refer to // switchState, you’re talking about the number it holds int switchstate = 0; -void setup(){ - // declare the LED pins as outputs - pinMode(3,OUTPUT); - pinMode(4,OUTPUT); - pinMode(5,OUTPUT); +void setup() { + // declare the LED pins as outputs + pinMode(3, OUTPUT); + pinMode(4, OUTPUT); + pinMode(5, OUTPUT); - // declare the switch pin as an input - pinMode(2,INPUT); + // declare the switch pin as an input + pinMode(2, INPUT); } -void loop(){ +void loop() { // read the value of the switch // digitalRead() checks to see if there is voltage - // on the pin or not + // on the pin or not switchstate = digitalRead(2); // if the button is not pressed - // blink the red LEDs + // blink 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 digitalWrite(5, LOW); // turn the red LED on pin 5 off } - // this else is part of the above if() statement. + // this else is part of the above if() statement. // if the switch is not LOW (the button is pressed) - // the code below will run + // the code below will run else { digitalWrite(3, LOW); // turn the green LED on pin 3 off digitalWrite(4, LOW); // turn the red LED on pin 4 off diff --git a/build/shared/examples/10.StarterKit/p03_LoveOMeter/p03_LoveOMeter.ino b/build/shared/examples/10.StarterKit/p03_LoveOMeter/p03_LoveOMeter.ino index 300febbea..1a937cafa 100644 --- a/build/shared/examples/10.StarterKit/p03_LoveOMeter/p03_LoveOMeter.ino +++ b/build/shared/examples/10.StarterKit/p03_LoveOMeter/p03_LoveOMeter.ino @@ -1,21 +1,21 @@ /* Arduino Starter Kit example Project 3 - Love-O-Meter - + This sketch is written to accompany Project 3 in the Arduino Starter Kit - + Parts required: - 1 TMP36 temperature sensor + 1 TMP36 temperature sensor 3 red LEDs 3 220 ohm resistors - + Created 13 September 2012 by Scott Fitzgerald - + http://arduino.cc/starterKit - - This example code is part of the public domain + + This example code is part of the public domain */ // named constant for the pin the sensor is connected to @@ -23,28 +23,28 @@ const int sensorPin = A0; // room temperature in Celcius const float baselineTemp = 20.0; -void setup(){ +void setup() { // open a serial connection to display values Serial.begin(9600); // set the LED pins as outputs // the for() loop saves some extra coding - for(int pinNumber = 2; pinNumber<5; pinNumber++){ - pinMode(pinNumber,OUTPUT); + for (int pinNumber = 2; pinNumber < 5; pinNumber++) { + pinMode(pinNumber, OUTPUT); digitalWrite(pinNumber, LOW); } } -void loop(){ - // read the value on AnalogIn pin 0 +void loop() { + // read the value on AnalogIn pin 0 // and store it in a variable int sensorVal = analogRead(sensorPin); // send the 10-bit sensor value out the serial port Serial.print("sensor Value: "); - Serial.print(sensorVal); + Serial.print(sensorVal); // convert the ADC reading to voltage - float voltage = (sensorVal/1024.0) * 5.0; + float voltage = (sensorVal / 1024.0) * 5.0; // Send the voltage level out the Serial port Serial.print(", Volts: "); @@ -54,28 +54,28 @@ void loop(){ // the sensor changes 10 mV per degree // the datasheet says there's a 500 mV offset // ((volatge - 500mV) times 100) - Serial.print(", degrees C: "); + Serial.print(", degrees C: "); float temperature = (voltage - .5) * 100; Serial.println(temperature); // if the current temperature is lower than the baseline // turn off all LEDs - if(temperature < baselineTemp){ + if (temperature < baselineTemp) { digitalWrite(2, LOW); digitalWrite(3, LOW); digitalWrite(4, LOW); - } // if the temperature rises 2-4 degrees, turn an LED on - else if(temperature >= baselineTemp+2 && temperature < baselineTemp+4){ + } // if the temperature rises 2-4 degrees, turn an LED on + else if (temperature >= baselineTemp + 2 && temperature < baselineTemp + 4) { digitalWrite(2, HIGH); digitalWrite(3, LOW); digitalWrite(4, LOW); - } // if the temperature rises 4-6 degrees, turn a second LED on - else if(temperature >= baselineTemp+4 && temperature < baselineTemp+6){ + } // if the temperature rises 4-6 degrees, turn a second LED on + else if (temperature >= baselineTemp + 4 && temperature < baselineTemp + 6) { digitalWrite(2, HIGH); digitalWrite(3, HIGH); digitalWrite(4, LOW); } // if the temperature rises more than 6 degrees, turn all LEDs on - else if(temperature >= baselineTemp+6){ + else if (temperature >= baselineTemp + 6) { digitalWrite(2, HIGH); digitalWrite(3, HIGH); digitalWrite(4, HIGH); diff --git a/build/shared/examples/10.StarterKit/p04_ColorMixingLamp/p04_ColorMixingLamp.ino b/build/shared/examples/10.StarterKit/p04_ColorMixingLamp/p04_ColorMixingLamp.ino index c1908007d..5114694f8 100644 --- a/build/shared/examples/10.StarterKit/p04_ColorMixingLamp/p04_ColorMixingLamp.ino +++ b/build/shared/examples/10.StarterKit/p04_ColorMixingLamp/p04_ColorMixingLamp.ino @@ -1,56 +1,56 @@ /* Arduino Starter Kit example Project 4 - Color Mixing Lamp - + This sketch is written to accompany Project 3 in the Arduino Starter Kit - + Parts required: - 1 RGB LED + 1 RGB LED three 10 kilohm resistors 3 220 ohm resistors 3 photoresistors red green and blue colored gels - + Created 13 September 2012 Modified 14 November 2012 by Scott Fitzgerald Thanks to Federico Vanzati for improvements http://arduino.cc/starterKit - - This example code is part of the public domain + + This example code is part of the public domain */ const int greenLEDPin = 9; // LED connected to digital pin 9 const int redLEDPin = 10; // LED connected to digital pin 10 const int blueLEDPin = 11; // LED connected to digital pin 11 -const int redSensorPin = A0; // pin with the photoresistor with the red gel -const int greenSensorPin = A1; // pin with the photoresistor with the green gel -const int blueSensorPin = A2; // pin with the photoresistor with the blue gel +const int redSensorPin = A0; // pin with the photoresistor with the red gel +const int greenSensorPin = A1; // pin with the photoresistor with the green gel +const int blueSensorPin = A2; // pin with the photoresistor with the blue gel int redValue = 0; // value to write to the red LED int greenValue = 0; // value to write to the green LED int blueValue = 0; // value to write to the blue LED -int redSensorValue = 0; // variable to hold the value from the red sensor -int greenSensorValue = 0; // variable to hold the value from the green sensor -int blueSensorValue = 0; // variable to hold the value from the blue sensor +int redSensorValue = 0; // variable to hold the value from the red sensor +int greenSensorValue = 0; // variable to hold the value from the green sensor +int blueSensorValue = 0; // variable to hold the value from the blue sensor void setup() { // initialize serial communications at 9600 bps: - Serial.begin(9600); + Serial.begin(9600); // set the digital pins as outputs - pinMode(greenLEDPin,OUTPUT); - pinMode(redLEDPin,OUTPUT); - pinMode(blueLEDPin,OUTPUT); + pinMode(greenLEDPin, OUTPUT); + pinMode(redLEDPin, OUTPUT); + pinMode(blueLEDPin, OUTPUT); } void loop() { // Read the sensors first: - + // read the value from the red-filtered photoresistor: redSensorValue = analogRead(redSensorPin); // give the ADC a moment to settle @@ -60,9 +60,9 @@ void loop() { // give the ADC a moment to settle delay(5); // read the value from the blue-filtered photoresistor: - blueSensorValue = analogRead(blueSensorPin); + blueSensorValue = analogRead(blueSensorPin); - // print out the values to the serial monitor + // print out the values to the serial monitor Serial.print("raw sensor Values \t red: "); Serial.print(redSensorValue); Serial.print("\t green: "); @@ -71,22 +71,22 @@ void loop() { Serial.println(blueSensorValue); /* - In order to use the values from the sensor for the LED, - you need to do some math. The ADC provides a 10-bit number, - but analogWrite() uses 8 bits. You'll want to divide your - sensor readings by 4 to keep them in range of the output. + In order to use the values from the sensor for the LED, + you need to do some math. The ADC provides a 10-bit number, + but analogWrite() uses 8 bits. You'll want to divide your + sensor readings by 4 to keep them in range of the output. */ - redValue = redSensorValue/4; - greenValue = greenSensorValue/4; - blueValue = blueSensorValue/4; + redValue = redSensorValue / 4; + greenValue = greenSensorValue / 4; + blueValue = blueSensorValue / 4; - // print out the mapped values + // print out the mapped values Serial.print("Mapped sensor Values \t red: "); Serial.print(redValue); Serial.print("\t green: "); Serial.print(greenValue); Serial.print("\t Blue: "); - Serial.println(blueValue); + Serial.println(blueValue); /* Now that you have a usable value, it's time to PWM the LED. diff --git a/build/shared/examples/10.StarterKit/p05_ServoMoodIndicator/p05_ServoMoodIndicator.ino b/build/shared/examples/10.StarterKit/p05_ServoMoodIndicator/p05_ServoMoodIndicator.ino index 78dd6e8e4..5a6ca0e18 100644 --- a/build/shared/examples/10.StarterKit/p05_ServoMoodIndicator/p05_ServoMoodIndicator.ino +++ b/build/shared/examples/10.StarterKit/p05_ServoMoodIndicator/p05_ServoMoodIndicator.ino @@ -1,34 +1,34 @@ /* Arduino Starter Kit example Project 5 - Servo Mood Indicator - + This sketch is written to accompany Project 5 in the Arduino Starter Kit - + Parts required: - servo motor - 10 kilohm potentiometer + servo motor + 10 kilohm potentiometer 2 100 uF electrolytic capacitors - + Created 13 September 2012 by Scott Fitzgerald - + http://arduino.cc/starterKit - - This example code is part of the public domain + + This example code is part of the public domain */ // include the servo library #include -Servo myServo; // create a servo object +Servo myServo; // create a servo object int const potPin = A0; // analog pin used to connect the potentiometer -int potVal; // variable to read the value from the analog pin -int angle; // variable to hold the angle for the servo motor +int potVal; // variable to read the value from the analog pin +int angle; // variable to hold the angle for the servo motor void setup() { - myServo.attach(9); // attaches the servo on pin 9 to the servo object + myServo.attach(9); // attaches the servo on pin 9 to the servo object Serial.begin(9600); // open a serial connection to your computer } @@ -38,17 +38,17 @@ void loop() { Serial.print("potVal: "); Serial.print(potVal); - // scale the numbers from the pot + // scale the numbers from the pot angle = map(potVal, 0, 1023, 0, 179); - // print out the angle for the servo motor + // print out the angle for the servo motor Serial.print(", angle: "); - Serial.println(angle); + Serial.println(angle); - // set the servo position + // set the servo position myServo.write(angle); - // wait for the servo to get there + // wait for the servo to get there delay(15); } diff --git a/build/shared/examples/10.StarterKit/p06_LightTheremin/p06_LightTheremin.ino b/build/shared/examples/10.StarterKit/p06_LightTheremin/p06_LightTheremin.ino index 4c9b7aa2b..04196c491 100644 --- a/build/shared/examples/10.StarterKit/p06_LightTheremin/p06_LightTheremin.ino +++ b/build/shared/examples/10.StarterKit/p06_LightTheremin/p06_LightTheremin.ino @@ -1,21 +1,21 @@ /* Arduino Starter Kit example Project 6 - Light Theremin - + This sketch is written to accompany Project 6 in the Arduino Starter Kit - + Parts required: photoresistor - 10 kilohm resistor + 10 kilohm resistor piezo - + Created 13 September 2012 by Scott Fitzgerald - + http://arduino.cc/starterKit - - This example code is part of the public domain + + This example code is part of the public domain */ // variable to hold sensor value diff --git a/build/shared/examples/10.StarterKit/p07_Keyboard/p07_Keyboard.ino b/build/shared/examples/10.StarterKit/p07_Keyboard/p07_Keyboard.ino index 202393891..0521b0a69 100644 --- a/build/shared/examples/10.StarterKit/p07_Keyboard/p07_Keyboard.ino +++ b/build/shared/examples/10.StarterKit/p07_Keyboard/p07_Keyboard.ino @@ -1,32 +1,32 @@ /* Arduino Starter Kit example Project 7 - Keyboard - + This sketch is written to accompany Project 7 in the Arduino Starter Kit - + Parts required: two 10 kilohm resistors - 1 Megohm resistor + 1 Megohm resistor 220 ohm resistor 4 pushbuttons piezo - + Created 13 September 2012 by Scott Fitzgerald - + http://arduino.cc/starterKit - - This example code is part of the public domain + + This example code is part of the public domain */ // create an array of notes -// the numbers below correspond to +// the numbers below correspond to // the frequencies of middle C, D, E, and F int notes[] = {262, 294, 330, 349}; void setup() { - //start serial communication + //start serial communication Serial.begin(9600); } @@ -35,27 +35,27 @@ void loop() { int keyVal = analogRead(A0); // send the value from A0 to the Serial Monitor Serial.println(keyVal); - + // play the note corresponding to each value on A0 - if(keyVal == 1023){ + 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); } } - + diff --git a/build/shared/examples/10.StarterKit/p08_DigitalHourglass/p08_DigitalHourglass.ino b/build/shared/examples/10.StarterKit/p08_DigitalHourglass/p08_DigitalHourglass.ino index 0eff2e7ca..2716a21ff 100644 --- a/build/shared/examples/10.StarterKit/p08_DigitalHourglass/p08_DigitalHourglass.ino +++ b/build/shared/examples/10.StarterKit/p08_DigitalHourglass/p08_DigitalHourglass.ino @@ -1,22 +1,22 @@ /* Arduino Starter Kit example Project 8 - Digital Hourglass - + This sketch is written to accompany Project 8 in the Arduino Starter Kit - + Parts required: 10 kilohm resistor six 220 ohm resistors six LEDs tilt switch - + Created 13 September 2012 by Scott Fitzgerald - + http://arduino.cc/starterKit - - This example code is part of the public domain + + This example code is part of the public domain */ // named constant for the switch pin @@ -28,50 +28,50 @@ int prevSwitchState = 0; // the previous switch state int led = 2; // a variable to refer to the LEDs // 600000 = 10 minutes in milliseconds -long interval = 600000; // interval at which to light the next LED +long interval = 600000; // interval at which to light the next LED void setup() { // set the LED pins as outputs - for(int x = 2;x<8;x++){ + for (int x = 2; x < 8; x++) { pinMode(x, OUTPUT); } - // set the tilt switch pin as input + // set the tilt switch pin as input pinMode(switchPin, INPUT); } -void loop(){ - // store the time since the Arduino started running in a variable - unsigned long currentTime = millis(); +void loop() { + // store the time since the Arduino started running in a variable + unsigned long currentTime = millis(); // compare the current time to the previous time an LED turned on // if it is greater than your interval, run the if statement - if(currentTime - previousTime > interval) { - // save the current time as the last time you changed an LED - previousTime = currentTime; + if (currentTime - previousTime > interval) { + // save the current time as the last time you changed an LED + previousTime = currentTime; // Turn the LED on digitalWrite(led, HIGH); // increment the led variable - // in 10 minutes the next LED will light up - led++; - - if(led == 7){ + // in 10 minutes the next LED will light up + led++; + + if (led == 7) { // the hour is up } } // read the switch value - switchState = digitalRead(switchPin); - + switchState = digitalRead(switchPin); + // if the switch has changed - if(switchState != prevSwitchState){ + if (switchState != prevSwitchState) { // turn all the LEDs low - for(int x = 2;x<8;x++){ + for (int x = 2; x < 8; x++) { digitalWrite(x, LOW); - } - + } + // reset the LED variable to the first one led = 2; - + //reset the timer previousTime = currentTime; } diff --git a/build/shared/examples/10.StarterKit/p09_MotorizedPinwheel/p09_MotorizedPinwheel.ino b/build/shared/examples/10.StarterKit/p09_MotorizedPinwheel/p09_MotorizedPinwheel.ino index 4232189d8..a531ded7b 100644 --- a/build/shared/examples/10.StarterKit/p09_MotorizedPinwheel/p09_MotorizedPinwheel.ino +++ b/build/shared/examples/10.StarterKit/p09_MotorizedPinwheel/p09_MotorizedPinwheel.ino @@ -1,10 +1,10 @@ /* Arduino Starter Kit example Project 9 - Motorized Pinwheel - + This sketch is written to accompany Project 9 in the Arduino Starter Kit - + Parts required: 10 kilohm resistor pushbutton @@ -12,13 +12,13 @@ 9V battery IRF520 MOSFET 1N4007 diode - + Created 13 September 2012 by Scott Fitzgerald - + http://arduino.cc/starterKit - - This example code is part of the public domain + + This example code is part of the public domain */ // named constants for the switch and motor pins @@ -29,22 +29,22 @@ int switchState = 0; // variable for reading the switch's status void setup() { // initialize the motor pin as an output: - pinMode(motorPin, OUTPUT); + pinMode(motorPin, OUTPUT); // initialize the switch pin as an input: - pinMode(switchPin, INPUT); + pinMode(switchPin, INPUT); } -void loop(){ +void loop() { // read the state of the switch value: switchState = digitalRead(switchPin); // check if the switch is pressed. - if (switchState == HIGH) { - // turn motor on: - digitalWrite(motorPin, HIGH); - } + if (switchState == HIGH) { + // turn motor on: + digitalWrite(motorPin, HIGH); + } else { // turn motor off: - digitalWrite(motorPin, LOW); + digitalWrite(motorPin, LOW); } } diff --git a/build/shared/examples/10.StarterKit/p10_Zoetrope/p10_Zoetrope.ino b/build/shared/examples/10.StarterKit/p10_Zoetrope/p10_Zoetrope.ino index 44e8c5af9..d0cfbe3c9 100644 --- a/build/shared/examples/10.StarterKit/p10_Zoetrope/p10_Zoetrope.ino +++ b/build/shared/examples/10.StarterKit/p10_Zoetrope/p10_Zoetrope.ino @@ -1,10 +1,10 @@ /* Arduino Starter Kit example Project 10 - Zoetrope - + This sketch is written to accompany Project 10 in the Arduino Starter Kit - + Parts required: two 10 kilohm resistors 2 momentary pushbuttons @@ -12,14 +12,14 @@ motor 9V battery H-Bridge - + Created 13 September 2012 by Scott Fitzgerald Thanks to Federico Vanzati for improvements http://arduino.cc/starterKit - - This example code is part of the public domain + + This example code is part of the public domain */ const int controlPin1 = 2; // connected to pin 7 on the H-bridge @@ -39,7 +39,7 @@ int motorEnabled = 0; // Turns the motor on/off int motorSpeed = 0; // speed of the motor int motorDirection = 1; // current direction of the motor -void setup(){ +void setup() { // intialize the inputs and outputs pinMode(directionSwitchPin, INPUT); pinMode(onOffSwitchStateSwitchPin, INPUT); @@ -51,44 +51,44 @@ void setup(){ digitalWrite(enablePin, LOW); } -void loop(){ +void loop() { // read the value of the on/off switch onOffSwitchState = digitalRead(onOffSwitchStateSwitchPin); delay(1); - + // read the value of the direction switch directionSwitchState = digitalRead(directionSwitchPin); - - // read the value of the pot and divide by 4 to get + + // read the value of the pot and divide by 4 to get // a value that can be used for PWM - motorSpeed = analogRead(potPin)/4; + motorSpeed = analogRead(potPin) / 4; // if the on/off button changed state since the last loop() - if(onOffSwitchState != previousOnOffSwitchState){ + if (onOffSwitchState != previousOnOffSwitchState) { // change the value of motorEnabled if pressed - if(onOffSwitchState == HIGH){ + if (onOffSwitchState == HIGH) { motorEnabled = !motorEnabled; } } // if the direction button changed state since the last loop() if (directionSwitchState != previousDirectionSwitchState) { - // change the value of motorDirection if pressed + // change the value of motorDirection if pressed if (directionSwitchState == HIGH) { motorDirection = !motorDirection; } - } + } // change the direction the motor spins by talking // to the control pins on the H-Bridge if (motorDirection == 1) { digitalWrite(controlPin1, HIGH); digitalWrite(controlPin2, LOW); - } + } else { digitalWrite(controlPin1, LOW); digitalWrite(controlPin2, HIGH); - } + } // if the motor is supposed to be on if (motorEnabled == 1) { @@ -99,7 +99,7 @@ void loop(){ //turn the motor off analogWrite(enablePin, 0); } - // save the current On/Offswitch state as the previous + // save the current On/Offswitch state as the previous previousDirectionSwitchState = directionSwitchState; // save the current switch state as the previous previousOnOffSwitchState = onOffSwitchState; diff --git a/build/shared/examples/10.StarterKit/p11_CrystalBall/p11_CrystalBall.ino b/build/shared/examples/10.StarterKit/p11_CrystalBall/p11_CrystalBall.ino index 820438b1d..b60f60bb4 100644 --- a/build/shared/examples/10.StarterKit/p11_CrystalBall/p11_CrystalBall.ino +++ b/build/shared/examples/10.StarterKit/p11_CrystalBall/p11_CrystalBall.ino @@ -1,24 +1,24 @@ /* Arduino Starter Kit example Project 11 - Crystal Ball - + This sketch is written to accompany Project 11 in the Arduino Starter Kit - + Parts required: 220 ohm resistor 10 kilohm resistor 10 kilohm potentiometer 16x2 LCD screen tilt switch - - + + Created 13 September 2012 by Scott Fitzgerald - + http://arduino.cc/starterKit - - This example code is part of the public domain + + This example code is part of the public domain */ // include the library code: @@ -40,12 +40,12 @@ int prevSwitchState = 0; int reply; void setup() { - // set up the number of columns and rows on the LCD + // set up the number of columns and rows on the LCD lcd.begin(16, 2); - + // set up the switch pin as an input - pinMode(switchPin,INPUT); - + pinMode(switchPin, INPUT); + // Print a message to the LCD. lcd.print("Ask the"); // set the cursor to column 0, line 1 @@ -62,57 +62,57 @@ void loop() { // compare the switchState to its previous state if (switchState != prevSwitchState) { // if the state has changed from HIGH to LOW - // you know that the ball has been tilted from - // one direction to the other + // you know that the ball has been tilted from + // one direction to the other if (switchState == LOW) { // randomly chose a reply reply = random(8); // clean up the screen before printing a new reply lcd.clear(); - // set the cursor to column 0, line 0 + // set the cursor to column 0, line 0 lcd.setCursor(0, 0); // print some text lcd.print("the ball says:"); // move the cursor to the second line lcd.setCursor(0, 1); - // choose a saying to print baed on the value in reply - switch(reply){ - case 0: - lcd.print("Yes"); - break; + // choose a saying to print baed on the value in reply + switch (reply) { + case 0: + lcd.print("Yes"); + break; - case 1: - lcd.print("Most likely"); - break; + case 1: + lcd.print("Most likely"); + break; - case 2: - lcd.print("Certainly"); - break; + case 2: + lcd.print("Certainly"); + break; - case 3: - lcd.print("Outlook good"); - break; + case 3: + lcd.print("Outlook good"); + break; - case 4: - lcd.print("Unsure"); - break; + case 4: + lcd.print("Unsure"); + break; - case 5: - lcd.print("Ask again"); - break; + case 5: + lcd.print("Ask again"); + break; - case 6: - lcd.print("Doubtful"); - break; + case 6: + lcd.print("Doubtful"); + break; - case 7: - lcd.print("No"); - break; + case 7: + lcd.print("No"); + break; } } } - // save the current switch state as the last state + // save the current switch state as the last state prevSwitchState = switchState; } diff --git a/build/shared/examples/10.StarterKit/p12_KnockLock/p12_KnockLock.ino b/build/shared/examples/10.StarterKit/p12_KnockLock/p12_KnockLock.ino index f3132bfb6..6c0cbb427 100644 --- a/build/shared/examples/10.StarterKit/p12_KnockLock/p12_KnockLock.ino +++ b/build/shared/examples/10.StarterKit/p12_KnockLock/p12_KnockLock.ino @@ -1,10 +1,10 @@ /* Arduino Starter Kit example Project 12 - Knock Lock - + This sketch is written to accompany Project 12 in the Arduino Starter Kit - + Parts required: 1 Megohm resistor 10 kilohm resistor @@ -16,17 +16,17 @@ one yellow LED one green LED 100 uF capacitor - + Created 18 September 2012 by Scott Fitzgerald Thanks to Federico Vanzati for improvements - + http://arduino.cc/starterKit - - This example code is part of the public domain + + This example code is part of the public domain */ -// import the library +// import the library #include // create an instance of the servo library Servo myServo; @@ -51,7 +51,7 @@ boolean locked = false; // how many valid knocks you've received int numberOfKnocks = 0; -void setup(){ +void setup() { // attach the servo to pin 9 myServo.attach(9); @@ -76,22 +76,22 @@ void setup(){ Serial.println("the box is unlocked!"); } -void loop(){ +void loop() { // if the box is unlocked - if(locked == false){ + if (locked == false) { // read the value of the switch pin switchVal = digitalRead(switchPin); // if the button is pressed, lock the box - if(switchVal == HIGH){ + if (switchVal == HIGH) { // set the locked variable to "true" locked = true; // change the status LEDs - digitalWrite(greenLed,LOW); - digitalWrite(redLed,HIGH); + digitalWrite(greenLed, LOW); + digitalWrite(redLed, HIGH); // move the servo to the locked position myServo.write(90); @@ -105,16 +105,16 @@ void loop(){ } // if the box is locked - if(locked == true){ + if (locked == true) { // check the value of the piezo knockVal = analogRead(piezo); // if there are not enough valid knocks - if(numberOfKnocks < 3 && knockVal > 0){ + if (numberOfKnocks < 3 && knockVal > 0) { // check to see if the knock is in range - if(checkForKnock(knockVal) == true){ + if (checkForKnock(knockVal) == true) { // increment the number of valid knocks numberOfKnocks++; @@ -126,7 +126,7 @@ void loop(){ } // if there are three knocks - if(numberOfKnocks >= 3){ + if (numberOfKnocks >= 3) { // unlock the box locked = false; @@ -137,19 +137,19 @@ void loop(){ delay(20); // change status LEDs - digitalWrite(greenLed,HIGH); - digitalWrite(redLed,LOW); + digitalWrite(greenLed, HIGH); + digitalWrite(redLed, LOW); Serial.println("the box is unlocked!"); } } } -// this function checks to see if a +// this function checks to see if a // detected knock is within max and min range -boolean checkForKnock(int value){ +boolean checkForKnock(int value) { // if the value of the knock is greater than // the minimum, and larger than the maximum - if(value > quietKnock && value < loudKnock){ + if (value > quietKnock && value < loudKnock) { // turn the status LED on digitalWrite(yellowLed, HIGH); delay(50); @@ -164,7 +164,7 @@ boolean checkForKnock(int value){ else { // print status Serial.print("Bad knock value "); - Serial.println(value); + Serial.println(value); // return false return false; } diff --git a/build/shared/examples/10.StarterKit/p13_TouchSensorLamp/p13_TouchSensorLamp.ino b/build/shared/examples/10.StarterKit/p13_TouchSensorLamp/p13_TouchSensorLamp.ino index bda2424cb..2ba3e9ee6 100644 --- a/build/shared/examples/10.StarterKit/p13_TouchSensorLamp/p13_TouchSensorLamp.ino +++ b/build/shared/examples/10.StarterKit/p13_TouchSensorLamp/p13_TouchSensorLamp.ino @@ -1,26 +1,26 @@ /* Arduino Starter Kit example Project 13 - Touch Sensor Lamp - + This sketch is written to accompany Project 13 in the Arduino Starter Kit - + Parts required: 1 Megohm resistor metal foil or copper mesh 220 ohm resistor LED - - Software required : + + Software required : CapacitiveSensor library by Paul Badger http://arduino.cc/playground/Main/CapacitiveSensor - + Created 18 September 2012 by Scott Fitzgerald - + http://arduino.cc/starterKit - - This example code is part of the public domain + + This example code is part of the public domain */ // import the library (must be located in the @@ -30,7 +30,7 @@ // create an instance of the library // pin 4 sends electrical energy // pin 2 senses senses a change -CapacitiveSensor capSensor = CapacitiveSensor(4,2); +CapacitiveSensor capSensor = CapacitiveSensor(4, 2); // threshold for turning the lamp on int threshold = 1000; @@ -51,10 +51,10 @@ void loop() { long sensorValue = capSensor.capacitiveSensor(30); // print out the sensor value - Serial.println(sensorValue); + Serial.println(sensorValue); // if the value is greater than the threshold - if(sensorValue > threshold) { + if (sensorValue > threshold) { // turn the LED on digitalWrite(ledPin, HIGH); } diff --git a/build/shared/examples/10.StarterKit/p14_TweakTheArduinoLogo/p14_TweakTheArduinoLogo.ino b/build/shared/examples/10.StarterKit/p14_TweakTheArduinoLogo/p14_TweakTheArduinoLogo.ino index 6c70a59f0..a6a2b0d02 100644 --- a/build/shared/examples/10.StarterKit/p14_TweakTheArduinoLogo/p14_TweakTheArduinoLogo.ino +++ b/build/shared/examples/10.StarterKit/p14_TweakTheArduinoLogo/p14_TweakTheArduinoLogo.ino @@ -1,23 +1,23 @@ /* Arduino Starter Kit example Project 14 - Tweak the Arduino Logo - + This sketch is written to accompany Project 14 in the Arduino Starter Kit - + Parts required: 10 kilohm potentiometer - - Software required : + + Software required : Processing http://processing.org Active internet connection - + Created 18 September 2012 by Scott Fitzgerald - + http://arduino.cc/starterKit - - This example code is part of the public domain + + This example code is part of the public domain */ @@ -27,9 +27,9 @@ void setup() { } void loop() { - // read the value of A0, divide by 4 and + // read the value of A0, divide by 4 and // send it as a byte over the serial connection - Serial.write(analogRead(A0)/4); + Serial.write(analogRead(A0) / 4); delay(1); } @@ -37,68 +37,68 @@ void loop() { // Tweak the Arduno Logo // by Scott Fitzgerald // This example code is in the public domain - + // import the serial library import processing.serial.*; - + // create an instance of the serial library Serial myPort; - + // create an instance of PImage PImage logo; - + // a variable to hold the background color int bgcolor = 0; - + void setup() { // set the color mode to Hue/Saturation/Brightness colorMode(HSB, 255); - + // load the Arduino logo into the PImage instance logo = loadImage("http://arduino.cc/en/pub/skins/arduinoWide/img/logo.png"); - + // make the window the same size as the image size(logo.width, logo.height); - - // print a list of available serial ports to the + + // print a list of available serial ports to the // Processing staus window println("Available serial ports:"); println(Serial.list()); - + // Tell the serial object the information it needs to communicate - // with the Arduno. Change Serial.list()[0] to the correct + // with the Arduno. Change Serial.list()[0] to the correct // port corresponding to your Arduino board. The last // parameter (e.g. 9600) is the speed of the communication. It // has to correspond to the value passed to Serial.begin() in your - // Arduino sketch. + // Arduino sketch. myPort = new Serial(this, Serial.list()[0], 9600); - + // If you know the name of the port used by the Arduino board, you // can specify it directly like this. - // port = new Serial(this, "COM1", 9600); - + // port = new Serial(this, "COM1", 9600); + } - + void draw() { - + // if there is information in the serial port if ( myPort.available() > 0) { // read the value and store it in a variable bgcolor = myPort.read(); - + // print the value to the status window - println(bgcolor); + println(bgcolor); } - + // Draw the background. the variable bgcolor // contains the Hue, determined by the value // from the serial port background(bgcolor, 255, 255); - + // draw the Arduino logo image(logo, 0, 0); } - + */ diff --git a/build/shared/examples/10.StarterKit/p15_HackingButtons/p15_HackingButtons.ino b/build/shared/examples/10.StarterKit/p15_HackingButtons/p15_HackingButtons.ino index 4a131e316..9e2ebcbcf 100644 --- a/build/shared/examples/10.StarterKit/p15_HackingButtons/p15_HackingButtons.ino +++ b/build/shared/examples/10.StarterKit/p15_HackingButtons/p15_HackingButtons.ino @@ -1,37 +1,37 @@ /* Arduino Starter Kit example Project 15 - Hacking Buttons - + This sketch is written to accompany Project 15 in the Arduino Starter Kit - + Parts required: batery powered component 220 ohm resistor 4N35 optocoupler - + Created 18 September 2012 by Scott Fitzgerald - + http://arduino.cc/starterKit - - This example code is part of the public domain + + This example code is part of the public domain */ const int optoPin = 2; // the pin the optocoupler is connected to -void setup(){ - // make the pin with the optocoupler an output +void setup() { + // make the pin with the optocoupler an output pinMode(optoPin, OUTPUT); } -void loop(){ - digitalWrite(optoPin, HIGH); // pull pin 2 HIGH, activating the optocoupler - - delay(15); // give the optocoupler a moment to activate - - digitalWrite(optoPin, LOW); // pull pin 2 low until you're ready to activate again - delay(21000); // wait for 21 seconds +void loop() { + digitalWrite(optoPin, HIGH); // pull pin 2 HIGH, activating the optocoupler + + delay(15); // give the optocoupler a moment to activate + + digitalWrite(optoPin, LOW); // pull pin 2 low until you're ready to activate again + delay(21000); // wait for 21 seconds } diff --git a/build/shared/examples/ArduinoISP/ArduinoISP.ino b/build/shared/examples/ArduinoISP/ArduinoISP.ino index 9ed0bc7df..7aaf1e680 100644 --- a/build/shared/examples/ArduinoISP/ArduinoISP.ino +++ b/build/shared/examples/ArduinoISP/ArduinoISP.ino @@ -1,16 +1,16 @@ // ArduinoISP version 04m3 // Copyright (c) 2008-2011 Randall Bohn -// If you require a license, see +// If you require a license, see // http://www.opensource.org/licenses/bsd-license.php // // This sketch turns the Arduino into a AVRISP // using the following arduino pins: // // pin name: not-mega: mega(1280 and 2560) -// slave reset: 10: 53 -// MOSI: 11: 51 -// MISO: 12: 50 -// SCK: 13: 52 +// slave reset: 10: 53 +// MOSI: 11: 51 +// MISO: 12: 50 +// SCK: 13: 52 // // Put an LED (with resistor) on the following pins: // 9: Heartbeat - shows the programmer is running @@ -31,7 +31,7 @@ // // October 2009 by David A. Mellis // - Added support for the read signature command -// +// // February 2009 by Randall Bohn // - Added support for writing to EEPROM (what took so long?) // Windows users should consider WinAVR's avrdude instead of the @@ -40,7 +40,7 @@ // January 2008 by Randall Bohn // - Thanks to Amplificar for helping me with the STK500 protocol // - The AVRISP/STK500 (mk I) protocol is used in the arduino bootloader -// - The SPI functions herein were developed for the AVR910_ARD programmer +// - The SPI functions herein were developed for the AVR910_ARD programmer // - More information at http://code.google.com/p/mega-isp #include "pins_arduino.h" @@ -75,8 +75,8 @@ void setup() { pulse(LED_HB, 2); } -int error=0; -int pmode=0; +int error = 0; +int pmode = 0; // address for reading and writing, set by 'U' command int here; uint8_t buff[256]; // global block storage @@ -96,14 +96,14 @@ typedef struct param { int pagesize; int eepromsize; int flashsize; -} +} parameter; parameter param; // this provides a heartbeat on pin 9, so you can tell the software is running. -uint8_t hbval=128; -int8_t hbdelta=8; +uint8_t hbval = 128; +int8_t hbdelta = 8; void heartbeat() { if (hbval > 192) hbdelta = -hbdelta; if (hbval < 32) hbdelta = -hbdelta; @@ -115,10 +115,10 @@ void heartbeat() { void loop(void) { // is pmode active? - if (pmode) digitalWrite(LED_PMODE, HIGH); + if (pmode) digitalWrite(LED_PMODE, HIGH); else digitalWrite(LED_PMODE, LOW); // is there an error? - if (error) digitalWrite(LED_ERR, HIGH); + if (error) digitalWrite(LED_ERR, HIGH); else digitalWrite(LED_ERR, LOW); // light the heartbeat LED @@ -129,7 +129,7 @@ void loop(void) { } uint8_t getch() { - while(!Serial.available()); + while (!Serial.available()); return Serial.read(); } void fill(int n) { @@ -145,7 +145,7 @@ void pulse(int pin, int times) { delay(PTIME); digitalWrite(pin, LOW); delay(PTIME); - } + } while (times--); } @@ -157,19 +157,19 @@ void prog_lamp(int state) { void spi_init() { uint8_t x; SPCR = 0x53; - x=SPSR; - x=SPDR; + x = SPSR; + x = SPDR; } void spi_wait() { do { - } + } while (!(SPSR & (1 << SPIF))); } uint8_t spi_send(uint8_t b) { uint8_t reply; - SPDR=b; + SPDR = b; spi_wait(); reply = SPDR; return reply; @@ -177,10 +177,10 @@ uint8_t spi_send(uint8_t b) { uint8_t spi_transaction(uint8_t a, uint8_t b, uint8_t c, uint8_t d) { uint8_t n; - spi_send(a); - n=spi_send(b); + spi_send(a); + n = spi_send(b); //if (n != a) error = -1; - n=spi_send(c); + n = spi_send(c); return spi_send(d); } @@ -188,7 +188,7 @@ void empty_reply() { if (CRC_EOP == getch()) { Serial.print((char)STK_INSYNC); Serial.print((char)STK_OK); - } + } else { error++; Serial.print((char)STK_NOSYNC); @@ -200,7 +200,7 @@ void breply(uint8_t b) { Serial.print((char)STK_INSYNC); Serial.print((char)b); Serial.print((char)STK_OK); - } + } else { error++; Serial.print((char)STK_NOSYNC); @@ -208,21 +208,21 @@ void breply(uint8_t b) { } void get_version(uint8_t c) { - switch(c) { - case 0x80: - breply(HWVER); - break; - case 0x81: - breply(SWMAJ); - break; - case 0x82: - breply(SWMIN); - break; - case 0x93: - breply('S'); // serial programmer - break; - default: - breply(0); + switch (c) { + case 0x80: + breply(HWVER); + break; + case 0x81: + breply(SWMAJ); + break; + case 0x82: + breply(SWMIN); + break; + case 0x93: + breply('S'); // serial programmer + break; + default: + breply(0); } } @@ -236,7 +236,7 @@ void set_parameters() { param.selftimed = buff[5]; param.lockbytes = buff[6]; param.fusebytes = buff[7]; - param.flashpoll = buff[8]; + param.flashpoll = buff[8]; // ignore buff[9] (= buff[8]) // following are 16 bits (big endian) param.eeprompoll = beget16(&buff[10]); @@ -245,9 +245,9 @@ void set_parameters() { // 32 bits flashsize (big endian) param.flashsize = buff[16] * 0x01000000 - + buff[17] * 0x00010000 - + buff[18] * 0x00000100 - + buff[19]; + + buff[17] * 0x00010000 + + buff[18] * 0x00000100 + + buff[19]; } @@ -285,10 +285,10 @@ void universal() { } void flash(uint8_t hilo, int addr, uint8_t data) { - spi_transaction(0x40+8*hilo, - addr>>8 & 0xFF, - addr & 0xFF, - data); + spi_transaction(0x40 + 8 * hilo, + addr >> 8 & 0xFF, + addr & 0xFF, + data); } void commit(int addr) { if (PROG_FLICKER) prog_lamp(LOW); @@ -314,7 +314,7 @@ void write_flash(int length) { if (CRC_EOP == getch()) { Serial.print((char) STK_INSYNC); Serial.print((char) write_flash_pages(length)); - } + } else { error++; Serial.print((char) STK_NOSYNC); @@ -363,11 +363,11 @@ uint8_t write_eeprom_chunk(int start, int length) { fill(length); prog_lamp(LOW); for (int x = 0; x < length; x++) { - int addr = start+x; - spi_transaction(0xC0, (addr>>8) & 0xFF, addr & 0xFF, buff[x]); + int addr = start + x; + spi_transaction(0xC0, (addr >> 8) & 0xFF, addr & 0xFF, buff[x]); delay(45); } - prog_lamp(HIGH); + prog_lamp(HIGH); return STK_OK; } @@ -386,7 +386,7 @@ void program_page() { if (CRC_EOP == getch()) { Serial.print((char) STK_INSYNC); Serial.print(result); - } + } else { error++; Serial.print((char) STK_NOSYNC); @@ -399,13 +399,13 @@ void program_page() { uint8_t flash_read(uint8_t hilo, int addr) { return spi_transaction(0x20 + hilo * 8, - (addr >> 8) & 0xFF, - addr & 0xFF, - 0); + (addr >> 8) & 0xFF, + addr & 0xFF, + 0); } char flash_read_page(int length) { - for (int x = 0; x < length; x+=2) { + for (int x = 0; x < length; x += 2) { uint8_t low = flash_read(LOW, here); Serial.print((char) low); uint8_t high = flash_read(HIGH, here); @@ -464,89 +464,89 @@ void read_signature() { //////////////////////////////////// //////////////////////////////////// -int avrisp() { +int avrisp() { uint8_t data, low, high; uint8_t ch = getch(); switch (ch) { - case '0': // signon - error = 0; - empty_reply(); - break; - case '1': - if (getch() == CRC_EOP) { - Serial.print((char) STK_INSYNC); - Serial.print("AVR ISP"); - Serial.print((char) STK_OK); - } - break; - case 'A': - get_version(getch()); - break; - case 'B': - fill(20); - set_parameters(); - empty_reply(); - break; - case 'E': // extended parameters - ignore for now - fill(5); - empty_reply(); - break; + case '0': // signon + error = 0; + empty_reply(); + break; + case '1': + if (getch() == CRC_EOP) { + Serial.print((char) STK_INSYNC); + Serial.print("AVR ISP"); + Serial.print((char) STK_OK); + } + break; + case 'A': + get_version(getch()); + break; + case 'B': + fill(20); + set_parameters(); + empty_reply(); + break; + case 'E': // extended parameters - ignore for now + fill(5); + empty_reply(); + break; - case 'P': - start_pmode(); - empty_reply(); - break; - case 'U': // set address (word) - here = getch(); - here += 256 * getch(); - empty_reply(); - break; + case 'P': + start_pmode(); + empty_reply(); + break; + case 'U': // set address (word) + here = getch(); + here += 256 * getch(); + empty_reply(); + break; - case 0x60: //STK_PROG_FLASH - low = getch(); - high = getch(); - empty_reply(); - break; - case 0x61: //STK_PROG_DATA - data = getch(); - empty_reply(); - break; + case 0x60: //STK_PROG_FLASH + low = getch(); + high = getch(); + empty_reply(); + break; + case 0x61: //STK_PROG_DATA + data = getch(); + empty_reply(); + break; - case 0x64: //STK_PROG_PAGE - program_page(); - break; + case 0x64: //STK_PROG_PAGE + program_page(); + break; - case 0x74: //STK_READ_PAGE 't' - read_page(); - break; + case 0x74: //STK_READ_PAGE 't' + read_page(); + break; - case 'V': //0x56 - universal(); - break; - case 'Q': //0x51 - error=0; - end_pmode(); - empty_reply(); - break; + case 'V': //0x56 + universal(); + break; + case 'Q': //0x51 + error = 0; + end_pmode(); + empty_reply(); + break; - case 0x75: //STK_READ_SIGN 'u' - read_signature(); - break; + case 0x75: //STK_READ_SIGN 'u' + read_signature(); + break; - // 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; + // 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 - default: - error++; - if (CRC_EOP == getch()) - Serial.print((char)STK_UNKNOWN); - else - Serial.print((char)STK_NOSYNC); + // anything else we will return STK_UNKNOWN + default: + error++; + if (CRC_EOP == getch()) + Serial.print((char)STK_UNKNOWN); + else + Serial.print((char)STK_NOSYNC); } } diff --git a/libraries/Audio/examples/SimpleAudioPlayer/SimpleAudioPlayer.ino b/libraries/Audio/examples/SimpleAudioPlayer/SimpleAudioPlayer.ino index a0f4905e3..1512b85be 100644 --- a/libraries/Audio/examples/SimpleAudioPlayer/SimpleAudioPlayer.ino +++ b/libraries/Audio/examples/SimpleAudioPlayer/SimpleAudioPlayer.ino @@ -2,18 +2,18 @@ Simple Audio Player Demonstrates the use of the Audio library for the Arduino Due - + Hardware required : * Arduino shield with a SD card on CS4 - * A sound file named "test.wav" in the root directory of the SD card + * A sound file named "test.wav" in the root directory of the SD card * An audio amplifier to connect to the DAC0 and ground - * A speaker to connect to the audio amplifier + * A speaker to connect to the audio amplifier Original by Massimo Banzi September 20, 2012 Modified by Scott Fitzgerald October 19, 2012 - + This example code is in the public domain - + http://arduino.cc/en/Tutorial/SimpleAudioPlayer */ @@ -44,7 +44,7 @@ void setup() void loop() { - int count=0; + int count = 0; // open wave file from sdcard File myFile = SD.open("test.wav"); @@ -54,7 +54,7 @@ void loop() while (true); } - const int S=1024; // Number of samples to read in block + const int S = 1024; // Number of samples to read in block short buffer[S]; Serial.print("Playing"); diff --git a/libraries/Bridge/examples/Bridge/Bridge.ino b/libraries/Bridge/examples/Bridge/Bridge.ino index d9c8fd80b..c6a9480df 100644 --- a/libraries/Bridge/examples/Bridge/Bridge.ino +++ b/libraries/Bridge/examples/Bridge/Bridge.ino @@ -1,12 +1,12 @@ /* Arduino Yun Bridge example - - This example for the Arduino Yun shows how to use the - Bridge library to access the digital and analog pins - on the board through REST calls. It demonstrates how - you can create your own API when using REST style + + This example for the Arduino Yun shows how to use the + Bridge library to access the digital and analog pins + on the board through REST calls. It demonstrates how + you can create your own API when using REST style calls through the browser. - + Possible commands created in this shetch: * "/arduino/digital/13" -> digitalRead(13) @@ -15,9 +15,9 @@ * "/arduino/analog/2" -> analogRead(2) * "/arduino/mode/13/input" -> pinMode(13, INPUT) * "/arduino/mode/13/output" -> pinMode(13, OUTPUT) - + This example code is part of the public domain - + http://arduino.cc/en/Tutorial/Bridge */ @@ -32,7 +32,7 @@ YunServer server; void setup() { // Bridge startup - pinMode(13,OUTPUT); + pinMode(13, OUTPUT); digitalWrite(13, LOW); Bridge.begin(); digitalWrite(13, HIGH); @@ -90,7 +90,7 @@ void digitalCommand(YunClient client) { if (client.read() == '/') { value = client.parseInt(); digitalWrite(pin, value); - } + } else { value = digitalRead(pin); } diff --git a/libraries/Bridge/examples/ConsoleAsciiTable/ConsoleAsciiTable.ino b/libraries/Bridge/examples/ConsoleAsciiTable/ConsoleAsciiTable.ino index 78c07b0ab..2b6d87249 100644 --- a/libraries/Bridge/examples/ConsoleAsciiTable/ConsoleAsciiTable.ino +++ b/libraries/Bridge/examples/ConsoleAsciiTable/ConsoleAsciiTable.ino @@ -1,95 +1,95 @@ /* ASCII table - - Prints out byte values in all possible formats: + + Prints out byte values in all possible formats: * as raw binary values * as ASCII-encoded decimal, hex, octal, and binary values - + For more on ASCII, see http://www.asciitable.com and http://en.wikipedia.org/wiki/ASCII - + The circuit: No external hardware needed. - + created 2006 - by Nicholas Zambetti + by Nicholas Zambetti http://www.zambetti.com modified 9 Apr 2012 by Tom Igoe modified 22 May 2013 by Cristian Maglie - + This example code is in the public domain. - + http://arduino.cc/en/Tutorial/ConsoleAsciiTable - + */ - + #include -void setup() { - //Initialize Console and wait for port to open: +void setup() { + //Initialize Console and wait for port to open: Bridge.begin(); - Console.begin(); - + Console.begin(); + // Uncomment the following line to enable buffering: // - better transmission speed and efficiency - // - needs to call Console.flush() to ensure that all + // - needs to call Console.flush() to ensure that all // transmitted data is sent - + //Console.buffer(64); - + while (!Console) { ; // wait for Console port to connect. } - - // prints title with ending line break - Console.println("ASCII Table ~ Character Map"); -} + + // prints title with ending line break + Console.println("ASCII Table ~ Character Map"); +} // first visible ASCIIcharacter '!' is number 33: -int thisByte = 33; +int thisByte = 33; // you can also write ASCII characters in single quotes. // for example. '!' is the same as 33, so you could also use this: -//int thisByte = '!'; +//int thisByte = '!'; -void loop() { - // prints value unaltered, i.e. the raw binary version of the - // byte. The Console monitor interprets all bytes as - // ASCII, so 33, the first number, will show up as '!' - Console.write(thisByte); +void loop() { + // prints value unaltered, i.e. the raw binary version of the + // byte. The Console monitor interprets all bytes as + // ASCII, so 33, the first number, will show up as '!' + Console.write(thisByte); - Console.print(", dec: "); + Console.print(", dec: "); // prints value as string as an ASCII-encoded decimal (base 10). // Decimal is the default format for Console.print() and Console.println(), // so no modifier is needed: - Console.print(thisByte); + Console.print(thisByte); // But you can declare the modifier for decimal if you want to. //this also works if you uncomment it: - // Console.print(thisByte, DEC); + // Console.print(thisByte, DEC); - Console.print(", hex: "); + Console.print(", hex: "); // prints value as string in hexadecimal (base 16): - Console.print(thisByte, HEX); + Console.print(thisByte, HEX); - Console.print(", oct: "); + Console.print(", oct: "); // prints value as string in octal (base 8); - Console.print(thisByte, OCT); + Console.print(thisByte, OCT); - Console.print(", bin: "); - // prints value as string in binary (base 2) + Console.print(", bin: "); + // prints value as string in binary (base 2) // also prints ending line break: - Console.println(thisByte, BIN); + Console.println(thisByte, BIN); - // if printed last visible character '~' or 126, stop: - if(thisByte == 126) { // you could also use if (thisByte == '~') { + // if printed last visible character '~' or 126, stop: + if (thisByte == 126) { // you could also use if (thisByte == '~') { // ensure the latest bit of data is sent Console.flush(); - + // This loop loops forever and does nothing - while(true) { - continue; - } - } + while (true) { + continue; + } + } // go on to the next character - thisByte++; -} + thisByte++; +} diff --git a/libraries/Bridge/examples/ConsolePixel/ConsolePixel.ino b/libraries/Bridge/examples/ConsolePixel/ConsolePixel.ino index 492681656..e90931345 100644 --- a/libraries/Bridge/examples/ConsolePixel/ConsolePixel.ino +++ b/libraries/Bridge/examples/ConsolePixel/ConsolePixel.ino @@ -1,30 +1,30 @@ /* Console Pixel - - An example of using the Arduino board to receive data from the + + An example of using the Arduino board to receive data from the Console on the Arduino Yun. In this case, the Arduino boards turns on an LED when it receives the character 'H', and turns off the LED when it receives the character 'L'. - + To see the Console, pick your Yún's name and IP address in the Port menu then open the Port Monitor. You can also see it by opening a terminal window - and typing + and typing ssh root@ yourYunsName.local 'telnet localhost 6571' then pressing enter. When prompted for the password, enter it. - - + + The circuit: * LED connected from digital pin 13 to ground - + created 2006 by David A. Mellis modified 25 Jun 2013 - by Tom Igoe - + by Tom Igoe + This example code is in the public domain. - + http://arduino.cc/en/Tutorial/ConsolePixel - + */ #include @@ -37,7 +37,7 @@ void setup() { Console.begin(); // Initialize Console // Wait for the Console port to connect - while(!Console); + while (!Console); Console.println("type H or L to turn pin 13 on or off"); @@ -54,7 +54,7 @@ void loop() { // if it's a capital H (ASCII 72), turn on the LED: if (incomingByte == 'H') { digitalWrite(ledPin, HIGH); - } + } // if it's an L (ASCII 76) turn off the LED: if (incomingByte == 'L') { digitalWrite(ledPin, LOW); diff --git a/libraries/Bridge/examples/ConsoleRead/ConsoleRead.ino b/libraries/Bridge/examples/ConsoleRead/ConsoleRead.ino index 1b130e0f9..77846d896 100644 --- a/libraries/Bridge/examples/ConsoleRead/ConsoleRead.ino +++ b/libraries/Bridge/examples/ConsoleRead/ConsoleRead.ino @@ -3,22 +3,22 @@ Read data coming from bridge using the Console.read() function and store it in a string. - + To see the Console, pick your Yún's name and IP address in the Port menu then open the Port Monitor. You can also see it by opening a terminal window - and typing: + and typing: ssh root@ yourYunsName.local 'telnet localhost 6571' then pressing enter. When prompted for the password, enter it. - + created 13 Jun 2013 - by Angelo Scialabba + by Angelo Scialabba modified 16 June 2013 by Tom Igoe - + This example code is in the public domain. - + http://arduino.cc/en/Tutorial/ConsoleRead - + */ #include @@ -28,13 +28,13 @@ String name; void setup() { // Initialize Console and wait for port to open: Bridge.begin(); - Console.begin(); + Console.begin(); // Wait for Console port to connect - while (!Console); - + while (!Console); + Console.println("Hi, what's your name?"); -} +} void loop() { if (Console.available() > 0) { @@ -49,7 +49,7 @@ void loop() { // Ask again for name and clear the old name Console.println("Hi, what's your name?"); name = ""; // clear the name string - } + } else { // if the buffer is empty Cosole.read() returns -1 name += c; // append the read char from Console to the name string } diff --git a/libraries/Bridge/examples/Datalogger/Datalogger.ino b/libraries/Bridge/examples/Datalogger/Datalogger.ino index 219eb94f9..7112389c6 100644 --- a/libraries/Bridge/examples/Datalogger/Datalogger.ino +++ b/libraries/Bridge/examples/Datalogger/Datalogger.ino @@ -1,21 +1,21 @@ /* SD card datalogger - - This example shows how to log data from three analog sensors + + This example shows how to log data from three analog sensors to an SD card mounted on the Arduino Yún using the Bridge library. - + The circuit: * analog sensors on analog pins 0, 1 and 2 * SD card attached to SD card slot of the Arduino Yún - - Prepare your SD card creating an empty folder in the SD root - named "arduino". This will ensure that the Yún will create a link + + Prepare your SD card creating an empty folder in the SD root + named "arduino". This will ensure that the Yún will create a link to the SD to the "/mnt/sd" path. - - You can remove the SD card while the Linux and the + + You can remove the SD card while the Linux and the sketch are running but be careful not to remove it while the system is writing to it. - + created 24 Nov 2010 modified 9 Apr 2012 by Tom Igoe @@ -23,11 +23,11 @@ by Federico Vanzati modified 21 Jun 2013 by Tom Igoe - + This example code is in the public domain. - + http://arduino.cc/en/Tutorial/YunDatalogger - + */ #include @@ -38,7 +38,7 @@ void setup() { Serial.begin(9600); FileSystem.begin(); - while(!Serial); // wait for Serial port to connect. + while (!Serial); // wait for Serial port to connect. Serial.println("Filesystem datalogger\n"); } @@ -69,12 +69,12 @@ void loop () { dataFile.close(); // print to the serial port too: Serial.println(dataString); - } + } // if the file isn't open, pop up an error: else { Serial.println("error opening datalog.txt"); - } - + } + delay(15000); } @@ -83,19 +83,19 @@ void loop () { String getTimeStamp() { String result; Process time; - // date is a command line utility to get the date and the time - // in different formats depending on the additional parameter + // date is a command line utility to get the date and the time + // in different formats depending on the additional parameter time.begin("date"); time.addParameter("+%D-%T"); // parameters: D for the complete date mm/dd/yy - // T for the time hh:mm:ss + // T for the time hh:mm:ss time.run(); // run the command // read the output of the command - while(time.available()>0) { + while (time.available() > 0) { char c = time.read(); - if(c != '\n') + if (c != '\n') result += c; } - + return result; } diff --git a/libraries/Bridge/examples/FileWriteScript/FileWriteScript.ino b/libraries/Bridge/examples/FileWriteScript/FileWriteScript.ino index 722c1a5b4..c59d873d5 100644 --- a/libraries/Bridge/examples/FileWriteScript/FileWriteScript.ino +++ b/libraries/Bridge/examples/FileWriteScript/FileWriteScript.ino @@ -1,18 +1,18 @@ /* Write to file using FileIO classes. - + This sketch demonstrate how to write file into the Yún filesystem. A shell script file is created in /tmp, and it is executed afterwards. created 7 June 2010 - by Cristian Maglie - + by Cristian Maglie + This example code is in the public domain. - + http://arduino.cc/en/Tutorial/FileWriteScript */ - + #include void setup() { @@ -20,16 +20,16 @@ void setup() { Bridge.begin(); // Initialize the Serial Serial.begin(9600); - - while(!Serial); // wait for Serial port to connect. + + while (!Serial); // wait for Serial port to connect. Serial.println("File Write Script example\n\n"); - + // Setup File IO FileSystem.begin(); - // Upload script used to gain network statistics + // Upload script used to gain network statistics uploadScript(); -} +} void loop() { // Run stats script every 5 secs. @@ -41,10 +41,10 @@ void loop() { // to check the network traffic of the WiFi interface void uploadScript() { // Write our shell script in /tmp - // Using /tmp stores the script in RAM this way we can preserve + // Using /tmp stores the script in RAM this way we can preserve // the limited amount of FLASH erase/write cycles File script = FileSystem.open("/tmp/wlan-stats.sh", FILE_WRITE); - // Shell script header + // Shell script header script.print("#!/bin/sh\n"); // shell commands: // ifconfig: is a command line utility for controlling the network interfaces. @@ -53,7 +53,7 @@ void uploadScript() { // and extract the line that contains it script.print("ifconfig wlan0 | grep 'RX bytes'\n"); script.close(); // close the file - + // Make the script executable Process chmod; chmod.begin("chmod"); // chmod: change mode @@ -69,9 +69,9 @@ void runScript() { Process myscript; myscript.begin("/tmp/wlan-stats.sh"); myscript.run(); - + String output = ""; - + // read the output of the script while (myscript.available()) { output += (char)myscript.read(); diff --git a/libraries/Bridge/examples/HttpClient/HttpClient.ino b/libraries/Bridge/examples/HttpClient/HttpClient.ino index d101e47a4..aaee7f954 100644 --- a/libraries/Bridge/examples/HttpClient/HttpClient.ino +++ b/libraries/Bridge/examples/HttpClient/HttpClient.ino @@ -1,9 +1,9 @@ /* Yun HTTP Client - - This example for the Arduino Yún shows how create a basic - HTTP client that connects to the internet and downloads - content. In this case, you'll connect to the Arduino + + This example for the Arduino Yún shows how create a basic + HTTP client that connects to the internet and downloads + content. In this case, you'll connect to the Arduino website and download a version of the logo as ASCII text. created by Tom igoe @@ -21,32 +21,32 @@ void setup() { // Bridge takes about two seconds to start up // it can be helpful to use the on-board LED - // as an indicator for when it has initialized + // as an indicator for when it has initialized pinMode(13, OUTPUT); digitalWrite(13, LOW); Bridge.begin(); digitalWrite(13, HIGH); - + Serial.begin(9600); - - while(!Serial); // wait for a serial connection + + while (!Serial); // wait for a serial connection } void loop() { // Initialize the client library HttpClient client; - + // Make a HTTP request: client.get("http://arduino.cc/asciilogo.txt"); - - // if there are incoming bytes available - // from the server, read them and print them: + + // if there are incoming bytes available + // from the server, read them and print them: while (client.available()) { char c = client.read(); Serial.print(c); } Serial.flush(); - + delay(5000); } diff --git a/libraries/Bridge/examples/Process/Process.ino b/libraries/Bridge/examples/Process/Process.ino index 9496a44d0..409b6d3a2 100644 --- a/libraries/Bridge/examples/Process/Process.ino +++ b/libraries/Bridge/examples/Process/Process.ino @@ -1,14 +1,14 @@ /* - Running process using Process class. - + Running process using Process class. + This sketch demonstrate how to run linux processes - using an Arduino Yún. - + using an Arduino Yún. + created 5 Jun 2013 by Cristian Maglie - + This example code is in the public domain. - + http://arduino.cc/en/Tutorial/Process */ @@ -18,10 +18,10 @@ void setup() { // Initialize Bridge Bridge.begin(); - + // Initialize Serial Serial.begin(9600); - + // Wait until a Serial Monitor is connected. while (!Serial); @@ -44,7 +44,7 @@ void runCurl() { // Print arduino logo over the Serial // A process output can be read with the stream methods - while (p.available()>0) { + while (p.available() > 0) { char c = p.read(); Serial.print(c); } @@ -62,7 +62,7 @@ void runCpuInfo() { // Print command output on the Serial. // A process output can be read with the stream methods - while (p.available()>0) { + while (p.available() > 0) { char c = p.read(); Serial.print(c); } diff --git a/libraries/Bridge/examples/ShellCommands/ShellCommands.ino b/libraries/Bridge/examples/ShellCommands/ShellCommands.ino index bdf2619ab..2f4052e78 100644 --- a/libraries/Bridge/examples/ShellCommands/ShellCommands.ino +++ b/libraries/Bridge/examples/ShellCommands/ShellCommands.ino @@ -1,24 +1,24 @@ /* - Running shell commands using Process class. - + Running shell commands using Process class. + This sketch demonstrate how to run linux shell commands using an Arduino Yún. It runs the wifiCheck script on the linino side of the Yun, then uses grep to get just the signal strength line. Then it uses parseInt() to read the wifi signal strength as an integer, and finally uses that number to fade an LED using analogWrite(). - + The circuit: * Arduino Yun with LED connected to pin 9 - + created 12 Jun 2013 by Cristian Maglie modified 25 June 2013 by Tom Igoe - + This example code is in the public domain. - + http://arduino.cc/en/Tutorial/ShellCommands - + */ #include @@ -28,18 +28,18 @@ void setup() { Serial.begin(9600); // Initialize the Serial // Wait until a Serial Monitor is connected. - while(!Serial); + while (!Serial); } void loop() { Process p; - // This command line runs the WifiStatus script, (/usr/bin/pretty-wifi-info.lua), then + // This command line runs the WifiStatus script, (/usr/bin/pretty-wifi-info.lua), then // sends the result to the grep command to look for a line containing the word // "Signal:" the result is passed to this sketch: p.runShellCommand("/usr/bin/pretty-wifi-info.lua | grep Signal"); // do nothing until the process finishes, so you get the whole output: - while(p.running()); + while (p.running()); // Read command output. runShellCommand() should have passed "Signal: xx&": while (p.available()) { @@ -47,7 +47,7 @@ void loop() { int signal = map(result, 0, 100, 0, 255); // map result from 0-100 range to 0-255 analogWrite(9, signal); // set the brightness of LED on pin 9 Serial.println(result); // print the number as well - } + } delay(5000); // wait 5 seconds before you do it again } diff --git a/libraries/Bridge/examples/SpacebrewYun/inputOutput/inputOutput.ino b/libraries/Bridge/examples/SpacebrewYun/inputOutput/inputOutput.ino index be22850b3..e566be34a 100644 --- a/libraries/Bridge/examples/SpacebrewYun/inputOutput/inputOutput.ino +++ b/libraries/Bridge/examples/SpacebrewYun/inputOutput/inputOutput.ino @@ -2,23 +2,23 @@ Input Output Demonstrates how to create a sketch that sends and receives all standard - spacebrew data types, and a custom data type. Every time data is + spacebrew data types, and a custom data type. Every time data is received it is output to the Serial monitor. - Make sure that your Yun is connected to the internet for this example + Make sure that your Yun is connected to the internet for this example to function properly. - + The circuit: - No circuit required - + created 2013 by Julio Terra - + This example code is in the public domain. - - More information about Spacebrew is available at: + + More information about Spacebrew is available at: http://spacebrew.cc/ - + */ #include @@ -33,98 +33,100 @@ int interval = 2000; int counter = 0; -void setup() { +void setup() { - // start the serial port - Serial.begin(57600); + // start the serial port + Serial.begin(57600); - // for debugging, wait until a serial console is connected - delay(4000); - while (!Serial) { ; } + // for debugging, wait until a serial console is connected + delay(4000); + while (!Serial) { + ; + } - // start-up the bridge - Bridge.begin(); + // start-up the bridge + Bridge.begin(); - // configure the spacebrew object to print status messages to serial - sb.verbose(true); + // configure the spacebrew object to print status messages to serial + sb.verbose(true); - // configure the spacebrew publisher and subscriber - sb.addPublish("string test", "string"); - sb.addPublish("range test", "range"); - sb.addPublish("boolean test", "boolean"); - sb.addPublish("custom test", "crazy"); - sb.addSubscribe("string test", "string"); - sb.addSubscribe("range test", "range"); - sb.addSubscribe("boolean test", "boolean"); - sb.addSubscribe("custom test", "crazy"); + // configure the spacebrew publisher and subscriber + sb.addPublish("string test", "string"); + sb.addPublish("range test", "range"); + sb.addPublish("boolean test", "boolean"); + sb.addPublish("custom test", "crazy"); + sb.addSubscribe("string test", "string"); + sb.addSubscribe("range test", "range"); + sb.addSubscribe("boolean test", "boolean"); + sb.addSubscribe("custom test", "crazy"); - // register the string message handler method - sb.onRangeMessage(handleRange); - sb.onStringMessage(handleString); - sb.onBooleanMessage(handleBoolean); - sb.onCustomMessage(handleCustom); + // register the string message handler method + sb.onRangeMessage(handleRange); + sb.onStringMessage(handleString); + sb.onBooleanMessage(handleBoolean); + sb.onCustomMessage(handleCustom); - // connect to cloud spacebrew server at "sandbox.spacebrew.cc" - sb.connect("sandbox.spacebrew.cc"); + // connect to cloud spacebrew server at "sandbox.spacebrew.cc" + sb.connect("sandbox.spacebrew.cc"); -} +} -void loop() { - // monitor spacebrew connection for new data - sb.monitor(); +void loop() { + // monitor spacebrew connection for new data + sb.monitor(); - // connected to spacebrew then send a string every 2 seconds - if ( sb.connected() ) { + // connected to spacebrew then send a string every 2 seconds + if ( sb.connected() ) { - // check if it is time to send a new message - if ( (millis() - last) > interval ) { - String test_str_msg = "testing, testing, "; - test_str_msg += counter; - counter ++; + // check if it is time to send a new message + if ( (millis() - last) > interval ) { + String test_str_msg = "testing, testing, "; + test_str_msg += counter; + counter ++; - sb.send("string test", test_str_msg); - sb.send("range test", 500); - sb.send("boolean test", true); - sb.send("custom test", "youre loco"); + sb.send("string test", test_str_msg); + sb.send("range test", 500); + sb.send("boolean test", true); + sb.send("custom test", "youre loco"); - last = millis(); + last = millis(); - } - } -} + } + } +} // define handler methods, all standard data type handlers take two appropriate arguments void handleRange (String route, int value) { - Serial.print("Range msg "); - Serial.print(route); - Serial.print(", value "); - Serial.println(value); + Serial.print("Range msg "); + Serial.print(route); + Serial.print(", value "); + Serial.println(value); } void handleString (String route, String value) { - Serial.print("String msg "); - Serial.print(route); - Serial.print(", value "); - Serial.println(value); + Serial.print("String msg "); + Serial.print(route); + Serial.print(", value "); + Serial.println(value); } void handleBoolean (String route, boolean value) { - Serial.print("Boolen msg "); - Serial.print(route); - Serial.print(", value "); - Serial.println(value ? "true" : "false"); + Serial.print("Boolen msg "); + Serial.print(route); + Serial.print(", value "); + Serial.println(value ? "true" : "false"); } // custom data type handlers takes three String arguments void handleCustom (String route, String value, String type) { - Serial.print("Custom msg "); - Serial.print(route); - Serial.print(" of type "); - Serial.print(type); - Serial.print(", value "); - Serial.println(value); + Serial.print("Custom msg "); + Serial.print(route); + Serial.print(" of type "); + Serial.print(type); + Serial.print(", value "); + Serial.println(value); } diff --git a/libraries/Bridge/examples/SpacebrewYun/spacebrewBoolean/spacebrewBoolean.ino b/libraries/Bridge/examples/SpacebrewYun/spacebrewBoolean/spacebrewBoolean.ino index 0f068aa06..3dc0e9285 100644 --- a/libraries/Bridge/examples/SpacebrewYun/spacebrewBoolean/spacebrewBoolean.ino +++ b/libraries/Bridge/examples/SpacebrewYun/spacebrewBoolean/spacebrewBoolean.ino @@ -1,26 +1,26 @@ /* Spacebrew Boolean - + Demonstrates how to create a sketch that sends and receives a - boolean value to and from Spacebrew. Every time the buttton is - pressed (or other digital input component) a spacebrew message - is sent. The sketch also accepts analog range messages from + boolean value to and from Spacebrew. Every time the buttton is + pressed (or other digital input component) a spacebrew message + is sent. The sketch also accepts analog range messages from other Spacebrew apps. - Make sure that your Yun is connected to the internet for this example + Make sure that your Yun is connected to the internet for this example to function properly. - + The circuit: - Button connected to Yun, using the Arduino's internal pullup resistor. - + created 2013 by Julio Terra - + This example code is in the public domain. - - More information about Spacebrew is available at: + + More information about Spacebrew is available at: http://spacebrew.cc/ - + */ #include @@ -33,57 +33,59 @@ SpacebrewYun sb = SpacebrewYun("spacebrewYun Boolean", "Boolean sender and recei int last_value = 0; // create variables to manage interval between each time we send a string -void setup() { +void setup() { - // start the serial port - Serial.begin(57600); + // start the serial port + Serial.begin(57600); - // for debugging, wait until a serial console is connected - delay(4000); - while (!Serial) { ; } + // for debugging, wait until a serial console is connected + delay(4000); + while (!Serial) { + ; + } - // start-up the bridge - Bridge.begin(); + // start-up the bridge + Bridge.begin(); - // configure the spacebrew object to print status messages to serial - sb.verbose(true); + // configure the spacebrew object to print status messages to serial + sb.verbose(true); - // configure the spacebrew publisher and subscriber - sb.addPublish("physical button", "boolean"); - sb.addSubscribe("virtual button", "boolean"); + // configure the spacebrew publisher and subscriber + sb.addPublish("physical button", "boolean"); + sb.addSubscribe("virtual button", "boolean"); - // register the string message handler method - sb.onBooleanMessage(handleBoolean); + // register the string message handler method + sb.onBooleanMessage(handleBoolean); - // connect to cloud spacebrew server at "sandbox.spacebrew.cc" - sb.connect("sandbox.spacebrew.cc"); + // connect to cloud spacebrew server at "sandbox.spacebrew.cc" + sb.connect("sandbox.spacebrew.cc"); - pinMode(3, INPUT); - digitalWrite(3, HIGH); -} - - -void loop() { - // monitor spacebrew connection for new data - sb.monitor(); - - // connected to spacebrew then send a new value whenever the pot value changes - if ( sb.connected() ) { - int cur_value = digitalRead(3); - if ( last_value != cur_value ) { - if (cur_value == HIGH) sb.send("physical button", false); - else sb.send("physical button", true); - last_value = cur_value; - } - } -} - -// handler method that is called whenever a new string message is received -void handleBoolean (String route, boolean value) { - // print the message that was received - Serial.print("From "); - Serial.print(route); - Serial.print(", received msg: "); - Serial.println(value ? "true" : "false"); + pinMode(3, INPUT); + digitalWrite(3, HIGH); +} + + +void loop() { + // monitor spacebrew connection for new data + sb.monitor(); + + // connected to spacebrew then send a new value whenever the pot value changes + if ( sb.connected() ) { + int cur_value = digitalRead(3); + if ( last_value != cur_value ) { + if (cur_value == HIGH) sb.send("physical button", false); + else sb.send("physical button", true); + last_value = cur_value; + } + } +} + +// handler method that is called whenever a new string message is received +void handleBoolean (String route, boolean value) { + // print the message that was received + Serial.print("From "); + Serial.print(route); + Serial.print(", received msg: "); + Serial.println(value ? "true" : "false"); } diff --git a/libraries/Bridge/examples/SpacebrewYun/spacebrewRange/spacebrewRange.ino b/libraries/Bridge/examples/SpacebrewYun/spacebrewRange/spacebrewRange.ino index 6dcbff8bf..3e18e3471 100644 --- a/libraries/Bridge/examples/SpacebrewYun/spacebrewRange/spacebrewRange.ino +++ b/libraries/Bridge/examples/SpacebrewYun/spacebrewRange/spacebrewRange.ino @@ -1,27 +1,27 @@ /* Spacebrew Range - + Demonstrates how to create a sketch that sends and receives analog - range value to and from Spacebrew. Every time the state of the + range value to and from Spacebrew. Every time the state of the potentiometer (or other analog input component) change a spacebrew - message is sent. The sketch also accepts analog range messages from + message is sent. The sketch also accepts analog range messages from other Spacebrew apps. - Make sure that your Yun is connected to the internet for this example + Make sure that your Yun is connected to the internet for this example to function properly. - + The circuit: - - Potentiometer connected to Yun. Middle pin connected to analog pin A0, + - Potentiometer connected to Yun. Middle pin connected to analog pin A0, other pins connected to 5v and GND pins. - + created 2013 by Julio Terra - + This example code is in the public domain. - - More information about Spacebrew is available at: + + More information about Spacebrew is available at: http://spacebrew.cc/ - + */ #include @@ -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); } diff --git a/libraries/Bridge/examples/SpacebrewYun/spacebrewString/spacebrewString.ino b/libraries/Bridge/examples/SpacebrewYun/spacebrewString/spacebrewString.ino index 8c8f1c7c2..e29db7c86 100644 --- a/libraries/Bridge/examples/SpacebrewYun/spacebrewString/spacebrewString.ino +++ b/libraries/Bridge/examples/SpacebrewYun/spacebrewString/spacebrewString.ino @@ -1,24 +1,24 @@ /* Spacebrew String - + Demonstrates how to create a sketch that sends and receives strings - to and from Spacebrew. Every time string data is received it + to and from Spacebrew. Every time string data is received it is output to the Serial monitor. - Make sure that your Yun is connected to the internet for this example + Make sure that your Yun is connected to the internet for this example to function properly. - + The circuit: - No circuit required - + created 2013 by Julio Terra - + This example code is in the public domain. - - More information about Spacebrew is available at: + + More information about Spacebrew is available at: http://spacebrew.cc/ - + */ #include @@ -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); } diff --git a/libraries/Bridge/examples/Temboo/ControlBySMS/ControlBySMS.ino b/libraries/Bridge/examples/Temboo/ControlBySMS/ControlBySMS.ino index 6543935d4..9444980fb 100644 --- a/libraries/Bridge/examples/Temboo/ControlBySMS/ControlBySMS.ino +++ b/libraries/Bridge/examples/Temboo/ControlBySMS/ControlBySMS.ino @@ -8,26 +8,26 @@ Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino - A Temboo account and application key are necessary to run all Temboo examples. - If you don't already have one, you can register for a free Temboo account at + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at http://www.temboo.com - Since this sketch uses Twilio to retrieve the SMS, you'll also need a valid + Since this sketch uses Twilio to retrieve the SMS, you'll also need a valid Twilio account. You can create one for free at https://www.twilio.com. - - The sketch needs your Twilio Account SID and Auth Token you get when you - register with Twilio. Make sure to use the Account SID and Auth Token from + + The sketch needs your Twilio Account SID and Auth Token you get when you + register with Twilio. Make sure to use the Account SID and Auth Token from your Twilio Dashboard (not your test credentials from the Dev Tools panel). Normally, Twilio expects to contact a web site you provide to get a response - when an SMS message is received for your Twilio number. In this case, we + when an SMS message is received for your Twilio number. In this case, we don't want to send any response (and we don't want to have to set up a web site just to receive SMS messages.) You can use a URL that Twilio provides for this purpose. When a message is received and sent to the Twilio "twimlets" URL, it returns a code meaning "no response required." To set this up: 1. Log in to your Twilio account and go to this URL: - + https://www.twilio.com/user/account/phone-numbers/incoming 2. Select the Twilio number you want to receive SMS messages at. @@ -40,7 +40,7 @@ https://www.twilio.com/help/faq/sms/how-can-i-receive-sms-messages-without-responding - 4. Click the "Save Changes" button at the bottom of the page. + 4. Click the "Save Changes" button at the bottom of the page. Your account will now receive SMS messages, but won't send any responses. @@ -48,14 +48,14 @@ to the Internet. Looking for another API? We've got over 100 in our Library! - + This example code is in the public domain. */ #include #include #include "TembooAccount.h" // contains Temboo account information - // as described in the footer comment below +// as described in the footer comment below @@ -85,7 +85,7 @@ unsigned long lastSMSCheckTime = -SMS_CHECK_PERIOD; // (we only need to process newer messages) String lastSid; -// we'll be turning the LED built in to the Yun on and off +// we'll be turning the LED built in to the Yun on and off // to simulate controlling some device. That LED is on pin 13. int LED_PIN = 13; @@ -98,7 +98,7 @@ void setup() { // for debugging, wait until a serial console is connected delay(4000); - while(!Serial); + while (!Serial); // tell the board to treat the LED pin as an output. pinMode(LED_PIN, OUTPUT); @@ -109,7 +109,7 @@ void setup() { // initialize the connection to the Linino processor. Bridge.begin(); - // Twilio will report old SMS messages. We want to + // Twilio will report old SMS messages. We want to // ignore any existing control messages when we start. Serial.println("Ignoring any existing control messages..."); checkForMessages(true); @@ -124,15 +124,15 @@ void loop() // see if it's time to check for new SMS messages. if (now - lastSMSCheckTime >= SMS_CHECK_PERIOD) { - + // it's time to check for new messages // save this time so we know when to check next lastSMSCheckTime = now; - + if (numRuns <= maxRuns) { Serial.println("Checking for new SMS messages - Run #" + String(numRuns++)); - - // execute the choreo and don't ignore control messages. + + // execute the choreo and don't ignore control messages. checkForMessages(false); } else { Serial.println("Already ran " + String(maxRuns) + " times."); @@ -145,7 +145,7 @@ This function executes the Twilio > SMSMessages > ListMessages choreo and processes the results. If ignoreCommands is 'true', this function will read and process messages -updating 'lastSid', but will not actually take any action on any commands +updating 'lastSid', but will not actually take any action on any commands found. This is so we can ignore any old control messages when we start. If ignoreCommands is 'false', control messages WILL be acted on. @@ -156,7 +156,7 @@ void checkForMessages(bool ignoreCommands) { TembooChoreo ListMessagesChoreo; ListMessagesChoreo.begin(); - + // set Temboo account credentials ListMessagesChoreo.setAccountName(TEMBOO_ACCOUNT); ListMessagesChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); @@ -166,12 +166,12 @@ void checkForMessages(bool ignoreCommands) { ListMessagesChoreo.setChoreo("/Library/Twilio/SMSMessages/ListMessages"); // set the choreo inputs - // see https://www.temboo.com/library/Library/Twilio/SMSMessages/ListMessages/ + // see https://www.temboo.com/library/Library/Twilio/SMSMessages/ListMessages/ // for complete details about the inputs for this Choreo // the first input is a your Twilio AccountSID ListMessagesChoreo.addInput("AccountSID", TWILIO_ACCOUNT_SID); - + // next is your Twilio Auth Token ListMessagesChoreo.addInput("AuthToken", TWILIO_AUTH_TOKEN); @@ -179,24 +179,24 @@ void checkForMessages(bool ignoreCommands) { ListMessagesChoreo.addInput("From", FROM_PHONE_NUMBER); // Twilio can return information about up to 1000 messages at a time. - // we're only interested in the 3 most recent ones. Note that if - // this account receives lots of messages in quick succession, + // we're only interested in the 3 most recent ones. Note that if + // this account receives lots of messages in quick succession, // (more than 3 per minute in this case), we might miss some control - // messages. But if we request too many messages, we might run out of + // messages. But if we request too many messages, we might run out of // memory on the Arduino side of the Yun. ListMessagesChoreo.addInput("PageSize", "3"); - // We want the response in XML format to process with our + // We want the response in XML format to process with our // XPath output filters. ListMessagesChoreo.addInput("ResponseFormat", "xml"); - // we don't want everything from the output, just the + // we don't want everything from the output, just the // message IDs (the Sids) and the message texts ListMessagesChoreo.addOutputFilter("sid", "Sid", "Response"); ListMessagesChoreo.addOutputFilter("text", "Body", "Response"); - // tell the Choreo to run and wait for the results. The - // return code (returnCode) will tell us whether the Temboo client + // tell the Choreo to run and wait for the results. The + // return code (returnCode) will tell us whether the Temboo client // was able to send our request to the Temboo servers unsigned int returnCode = ListMessagesChoreo.run(); @@ -204,7 +204,7 @@ void checkForMessages(bool ignoreCommands) { if (returnCode == 0) { // Need a string to hold the list of message IDs. - String messageSids; + String messageSids; // Need a string to hold the texts of the messages. String messageTexts; @@ -214,8 +214,8 @@ void checkForMessages(bool ignoreCommands) { // lists containing the Sids and texts of the messages // from our designated phone number. - while(ListMessagesChoreo.available()) { - + while (ListMessagesChoreo.available()) { + // output names are terminated with '\x1F' characters. String name = ListMessagesChoreo.readStringUntil('\x1F'); name.trim(); @@ -236,46 +236,46 @@ void checkForMessages(bool ignoreCommands) { // done reading output, close the Choreo to free up resources. ListMessagesChoreo.close(); - - // parse the comma delimited lists of messages and Sids + + // parse the comma delimited lists of messages and Sids processMessages(messageTexts, messageSids, ignoreCommands); } else { // a non-zero return code means there was an error // read and print the error message - while(ListMessagesChoreo.available()) { + while (ListMessagesChoreo.available()) { char c = ListMessagesChoreo.read(); Serial.print(c); } } } -/* +/* This function processes the lists of message texts and Sids. -If a message contains a comma as part of the +If a message contains a comma as part of the message text, that message will be enclosed in double quotes (") in the list. Example: A message,"Hey, now",Another message text If the message contains double quotes, it will be enclosed in -double quotes AND the internal quotes will be doubled. +double quotes AND the internal quotes will be doubled. Example: "Hi ""Sam"" the man", Led on NOTE! We are assuming that Twilio returns more recent messages -first. This isn't officially documented by Twilio, but we've +first. This isn't officially documented by Twilio, but we've not seen any other case. 'messageTexts' is a String containing a comma separated list of message texts with commas and quotes escaped as described above. -'messageSids' is a String containing a comma separated list of +'messageSids' is a String containing a comma separated list of message Sids. Sids should not contain embedded commas or quotes. -'ignoreCommands' is a boolean. 'true' means and control messages -will not be acted upon. 'false' means control messages will be +'ignoreCommands' is a boolean. 'true' means and control messages +will not be acted upon. 'false' means control messages will be acted upon in the usual way. */ void processMessages(String messageTexts, String messageSids, bool ignoreCommands) { @@ -297,14 +297,14 @@ void processMessages(String messageTexts, String messageSids, bool ignoreCommand // find the start of the next item in the list i = messageSids.indexOf(',', sidsStart); if (i >= 0) { - + //extract a single Sid from the list. sid = messageSids.substring(sidsStart, i); sidsStart = i + 1; - // find the start of the next text in the list. + // find the start of the next text in the list. // Note that we have to be prepared to handle embedded - // quotes and commans in the message texts. + // quotes and commans in the message texts. // The standard Arduino String class doesn't handle // this, so we have to write our own function to do it. i = quotedIndexOf(messageTexts, ',', textsStart); @@ -314,12 +314,12 @@ void processMessages(String messageTexts, String messageSids, bool ignoreCommand text = messageTexts.substring(textsStart, i); textsStart = i + 1; - // process the Sid and text to see if it's a + // process the Sid and text to see if it's a // control message. ledUpdated = processMessage(sid, text, ignoreCommands); } } else { - + // the last item in the lists won't have a comma at the end, // so we have to handle them specially. // Since we know this is the last item, we can just @@ -333,9 +333,9 @@ void processMessages(String messageTexts, String messageSids, bool ignoreCommand // keep going until either we run out of list items // or we run into a message we processed on a previous run. - } while ((i >=0) && (sid != lastSid)); - - // print what we've found to the serial monitor, + } while ((i >= 0) && (sid != lastSid)); + + // print what we've found to the serial monitor, // just so we can see what's going on. if (sid == lastSid) { if (ledUpdated) @@ -359,17 +359,17 @@ A message with the text "LED ON" turns the LED on. A message with the text "LED OFF" turns the LED off. (Case is ignored.) -If 'ignoreCommands' is true, the actions described above will NOT -take place. +If 'ignoreCommands' is true, the actions described above will NOT +take place. -It also updates the 'lastSid' global variable when +It also updates the 'lastSid' global variable when a control message is processed. It returns 'true' if the message was a control message, and 'false' if it wasn't or if we've already processed this message. */ bool processMessage(String sid, String text, bool ignoreCommands) { - + // a flag to indicate whether this was a control message or not bool ledUpdated = false; @@ -377,7 +377,7 @@ bool processMessage(String sid, String text, bool ignoreCommands) { if (sid != lastSid) { if (text.equalsIgnoreCase("LED ON")) { - + if (!ignoreCommands) { //turn on the LED digitalWrite(LED_PIN, HIGH); @@ -394,7 +394,7 @@ bool processMessage(String sid, String text, bool ignoreCommands) { } // If the LED state was updated, remember the Sid if this message. - if (ledUpdated) + if (ledUpdated) lastSid = sid; } return ledUpdated; @@ -428,16 +428,16 @@ int quotedIndexOf(String s, char delim, int start) { by inserting your own Temboo account name and app key information. The contents of the file should look like: - #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key - You can find your Temboo App Key information on the Temboo website, + You can find your Temboo App Key information on the Temboo website, under My Account > Application Keys The same TembooAccount.h file settings can be used for all Temboo SDK sketches. - Keeping your account information in a separate file means you can save it once, + Keeping your account information in a separate file means you can save it once, then just distribute the main .ino file without worrying that you forgot to delete your credentials. */ diff --git a/libraries/Bridge/examples/Temboo/GetYahooWeatherReport/GetYahooWeatherReport.ino b/libraries/Bridge/examples/Temboo/GetYahooWeatherReport/GetYahooWeatherReport.ino index 669aba5c1..83d5273e7 100644 --- a/libraries/Bridge/examples/Temboo/GetYahooWeatherReport/GetYahooWeatherReport.ino +++ b/libraries/Bridge/examples/Temboo/GetYahooWeatherReport/GetYahooWeatherReport.ino @@ -1,26 +1,26 @@ /* GetYahooWeatherReport - + Demonstrates making a request to the Yahoo! Weather API using Temboo from an Arduino Yun. Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino - - A Temboo account and application key are necessary to run all Temboo examples. - If you don't already have one, you can register for a free Temboo account at + + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at http://www.temboo.com - + This example assumes basic familiarity with Arduino sketches, and that your Yun is connected to the Internet. Looking for another API to use with your Arduino Yun? We've got over 100 in our Library! - + This example code is in the public domain. */ #include #include #include "TembooAccount.h" // contains Temboo account information - // as described in the footer comment below +// as described in the footer comment below // the address for which a weather forecast will be retrieved @@ -32,10 +32,10 @@ int maxRuns = 10; // max number of times the Yahoo WeatherByAddress Choreo shou void setup() { Serial.begin(9600); - + // for debugging, wait until a serial console is connected delay(4000); - while(!Serial); + while (!Serial); Bridge.begin(); } @@ -44,13 +44,13 @@ void loop() { // while we haven't reached the max number of runs... if (numRuns <= maxRuns) { - + // print status Serial.println("Running GetWeatherByAddress - Run #" + String(numRuns++) + "..."); // create a TembooChoreo object to send a Choreo request to Temboo TembooChoreo GetWeatherByAddressChoreo; - + // invoke the Temboo client GetWeatherByAddressChoreo.begin(); @@ -58,30 +58,30 @@ void loop() GetWeatherByAddressChoreo.setAccountName(TEMBOO_ACCOUNT); GetWeatherByAddressChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); GetWeatherByAddressChoreo.setAppKey(TEMBOO_APP_KEY); - + // set the name of the choreo we want to run GetWeatherByAddressChoreo.setChoreo("/Library/Yahoo/Weather/GetWeatherByAddress"); - + // set choreo inputs; in this case, the address for which to retrieve weather data // the Temboo client provides standardized calls to 100+ cloud APIs GetWeatherByAddressChoreo.addInput("Address", ADDRESS_FOR_FORECAST); // add an output filter to extract the name of the city. GetWeatherByAddressChoreo.addOutputFilter("city", "/rss/channel/yweather:location/@city", "Response"); - + // add an output filter to extract the current temperature GetWeatherByAddressChoreo.addOutputFilter("temperature", "/rss/channel/item/yweather:condition/@temp", "Response"); // add an output filter to extract the date and time of the last report. GetWeatherByAddressChoreo.addOutputFilter("date", "/rss/channel/item/yweather:condition/@date", "Response"); - // run the choreo + // run the choreo GetWeatherByAddressChoreo.run(); - + // when the choreo results are available, print them to the serial monitor - while(GetWeatherByAddressChoreo.available()) { - - char c = GetWeatherByAddressChoreo.read(); + while (GetWeatherByAddressChoreo.available()) { + + char c = GetWeatherByAddressChoreo.read(); Serial.print(c); } GetWeatherByAddressChoreo.close(); @@ -101,15 +101,15 @@ void loop() by inserting your own Temboo account name and app key information. The contents of the file should look like: - #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key - You can find your Temboo App Key information on the Temboo website, + You can find your Temboo App Key information on the Temboo website, under My Account > Application Keys The same TembooAccount.h file settings can be used for all Temboo SDK sketches. - Keeping your account information in a separate file means you can share the main .ino file without worrying + Keeping your account information in a separate file means you can share the main .ino file without worrying that you forgot to delete your credentials. */ diff --git a/libraries/Bridge/examples/Temboo/ReadATweet/ReadATweet.ino b/libraries/Bridge/examples/Temboo/ReadATweet/ReadATweet.ino index b2edd1f4b..06b110518 100644 --- a/libraries/Bridge/examples/Temboo/ReadATweet/ReadATweet.ino +++ b/libraries/Bridge/examples/Temboo/ReadATweet/ReadATweet.ino @@ -1,33 +1,33 @@ /* ReadATweet - Demonstrates retrieving the most recent Tweet from a user's home timeline + Demonstrates retrieving the most recent Tweet from a user's home timeline using Temboo from an Arduino Yun. Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino - A Temboo account and application key are necessary to run all Temboo examples. - If you don't already have one, you can register for a free Temboo account at + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at http://www.temboo.com In order to run this sketch, you'll need to register an application using - the Twitter dev console at https://dev.twitter.com. After creating the - app, you'll find OAuth credentials for that application under the "OAuth Tool" tab. - Substitute these values for the placeholders below. + the Twitter dev console at https://dev.twitter.com. After creating the + app, you'll find OAuth credentials for that application under the "OAuth Tool" tab. + Substitute these values for the placeholders below. - This example assumes basic familiarity with Arduino sketches, and that your Yun + This example assumes basic familiarity with Arduino sketches, and that your Yun is connected to the Internet. - Want to use another social API with your Arduino Yun? We've got Facebook, + Want to use another social API with your Arduino Yun? We've got Facebook, Google+, Instagram, Tumblr and more in our Library! - + This example code is in the public domain. */ #include #include #include "TembooAccount.h" // contains Temboo account information - // as described in the footer comment below +// as described in the footer comment below /*** SUBSTITUTE YOUR VALUES BELOW: ***/ @@ -43,10 +43,10 @@ int maxRuns = 10; // the max number of times the Twitter HomeTimeline Choreo s void setup() { Serial.begin(9600); - + // For debugging, wait until a serial console is connected. delay(4000); - while(!Serial); + while (!Serial); Bridge.begin(); } void loop() @@ -54,14 +54,14 @@ void loop() // while we haven't reached the max number of runs... if (numRuns <= maxRuns) { Serial.println("Running ReadATweet - Run #" + String(numRuns++)); - + TembooChoreo HomeTimelineChoreo; // invoke the Temboo client. // NOTE that the client must be reinvoked, and repopulated with // appropriate arguments, each time its run() method is called. HomeTimelineChoreo.begin(); - + // set Temboo account credentials HomeTimelineChoreo.setAccountName(TEMBOO_ACCOUNT); HomeTimelineChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); @@ -69,8 +69,8 @@ void loop() // tell the Temboo client which Choreo to run (Twitter > Timelines > HomeTimeline) HomeTimelineChoreo.setChoreo("/Library/Twitter/Timelines/HomeTimeline"); - - + + // set the required choreo inputs // see https://www.temboo.com/library/Library/Twitter/Timelines/HomeTimeline/ // for complete details about the inputs for this Choreo @@ -78,44 +78,44 @@ void loop() HomeTimelineChoreo.addInput("Count", "1"); // the max number of Tweets to return from each request HomeTimelineChoreo.addInput("AccessToken", TWITTER_ACCESS_TOKEN); HomeTimelineChoreo.addInput("AccessTokenSecret", TWITTER_ACCESS_TOKEN_SECRET); - HomeTimelineChoreo.addInput("ConsumerKey", TWITTER_CONSUMER_KEY); + HomeTimelineChoreo.addInput("ConsumerKey", TWITTER_CONSUMER_KEY); HomeTimelineChoreo.addInput("ConsumerSecret", TWITTER_CONSUMER_SECRET); - // next, we'll define two output filters that let us specify the + // next, we'll define two output filters that let us specify the // elements of the response from Twitter that we want to receive. // see the examples at http://www.temboo.com/arduino // for more on using output filters - + // we want the text of the tweet HomeTimelineChoreo.addOutputFilter("tweet", "/[1]/text", "Response"); - + // and the name of the author HomeTimelineChoreo.addOutputFilter("author", "/[1]/user/screen_name", "Response"); - // tell the Process to run and wait for the results. The - // return code will tell us whether the Temboo client + // tell the Process to run and wait for the results. The + // return code will tell us whether the Temboo client // was able to send our request to the Temboo servers unsigned int returnCode = HomeTimelineChoreo.run(); - - // a response code of 0 means success; print the API response - if(returnCode == 0) { - + + // a response code of 0 means success; print the API response + if (returnCode == 0) { + String author; // a String to hold the tweet author's name String tweet; // a String to hold the text of the tweet - // choreo outputs are returned as key/value pairs, delimited with + // choreo outputs are returned as key/value pairs, delimited with // newlines and record/field terminator characters, for example: // Name1\n\x1F // Value1\n\x1E // Name2\n\x1F - // Value2\n\x1E - + // Value2\n\x1E + // see the examples at http://www.temboo.com/arduino for more details // we can read this format into separate variables, as follows: - - while(HomeTimelineChoreo.available()) { + + while (HomeTimelineChoreo.available()) { // read the name of the output item String name = HomeTimelineChoreo.readStringUntil('\x1F'); name.trim(); @@ -131,13 +131,13 @@ void loop() author = data; } } - + Serial.println("@" + author + " - " + tweet); - + } else { // there was an error // print the raw output from the choreo - while(HomeTimelineChoreo.available()) { + while (HomeTimelineChoreo.available()) { char c = HomeTimelineChoreo.read(); Serial.print(c); } @@ -159,15 +159,15 @@ void loop() by inserting your own Temboo account name and app key information. The contents of the file should look like: - #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key - You can find your Temboo App Key information on the Temboo website, + You can find your Temboo App Key information on the Temboo website, under My Account > Application Keys The same TembooAccount.h file settings can be used for all Temboo SDK sketches. - Keeping your account information in a separate file means you can share the main .ino file without worrying + Keeping your account information in a separate file means you can share the main .ino file without worrying that you forgot to delete your credentials. */ diff --git a/libraries/Bridge/examples/Temboo/SendATweet/SendATweet.ino b/libraries/Bridge/examples/Temboo/SendATweet/SendATweet.ino index 2e34a82ff..324877c99 100644 --- a/libraries/Bridge/examples/Temboo/SendATweet/SendATweet.ino +++ b/libraries/Bridge/examples/Temboo/SendATweet/SendATweet.ino @@ -5,30 +5,30 @@ Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino - A Temboo account and application key are necessary to run all Temboo examples. - If you don't already have one, you can register for a free Temboo account at + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at http://www.temboo.com In order to run this sketch, you'll need to register an application using - the Twitter dev console at https://dev.twitter.com. Note that since this + the Twitter dev console at https://dev.twitter.com. Note that since this sketch creates a new tweet, your application will need to be configured with - read+write permissions. After creating the app, you'll find OAuth credentials - for that application under the "OAuth Tool" tab. Substitute these values for - the placeholders below. + read+write permissions. After creating the app, you'll find OAuth credentials + for that application under the "OAuth Tool" tab. Substitute these values for + the placeholders below. This example assumes basic familiarity with Arduino sketches, and that your Yun is connected to the Internet. - Want to use another social API with your Arduino Yun? We've got Facebook, + Want to use another social API with your Arduino Yun? We've got Facebook, Google+, Instagram, Tumblr and more in our Library! - + This example code is in the public domain. */ #include #include #include "TembooAccount.h" // contains Temboo account information - // as described in the footer comment below +// as described in the footer comment below /*** SUBSTITUTE YOUR VALUES BELOW: ***/ @@ -48,7 +48,7 @@ void setup() { // for debugging, wait until a serial console is connected delay(4000); - while(!Serial); + while (!Serial); Bridge.begin(); } @@ -59,18 +59,18 @@ void loop() if (numRuns <= maxRuns) { Serial.println("Running SendATweet - Run #" + String(numRuns++) + "..."); - + // define the text of the tweet we want to send String tweetText("My Arduino Yun has been running for " + String(millis()) + " milliseconds."); - + TembooChoreo StatusesUpdateChoreo; // invoke the Temboo client // NOTE that the client must be reinvoked, and repopulated with // appropriate arguments, each time its run() method is called. StatusesUpdateChoreo.begin(); - + // set Temboo account credentials StatusesUpdateChoreo.setAccountName(TEMBOO_ACCOUNT); StatusesUpdateChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); @@ -80,26 +80,26 @@ void loop() StatusesUpdateChoreo.setChoreo("/Library/Twitter/Tweets/StatusesUpdate"); // set the required choreo inputs - // see https://www.temboo.com/library/Library/Twitter/Tweets/StatusesUpdate/ + // see https://www.temboo.com/library/Library/Twitter/Tweets/StatusesUpdate/ // for complete details about the inputs for this Choreo - + // add the Twitter account information StatusesUpdateChoreo.addInput("AccessToken", TWITTER_ACCESS_TOKEN); StatusesUpdateChoreo.addInput("AccessTokenSecret", TWITTER_ACCESS_TOKEN_SECRET); - StatusesUpdateChoreo.addInput("ConsumerKey", TWITTER_CONSUMER_KEY); + StatusesUpdateChoreo.addInput("ConsumerKey", TWITTER_CONSUMER_KEY); StatusesUpdateChoreo.addInput("ConsumerSecret", TWITTER_CONSUMER_SECRET); // and the tweet we want to send StatusesUpdateChoreo.addInput("StatusUpdate", tweetText); - // tell the Process to run and wait for the results. The - // return code (returnCode) will tell us whether the Temboo client + // tell the Process to run and wait for the results. The + // return code (returnCode) will tell us whether the Temboo client // was able to send our request to the Temboo servers unsigned int returnCode = StatusesUpdateChoreo.run(); // a return code of zero (0) means everything worked if (returnCode == 0) { - Serial.println("Success! Tweet sent!"); + Serial.println("Success! Tweet sent!"); } else { // a non-zero return code means there was an error // read and print the error message @@ -107,7 +107,7 @@ void loop() char c = StatusesUpdateChoreo.read(); Serial.print(c); } - } + } StatusesUpdateChoreo.close(); // do nothing for the next 90 seconds @@ -124,15 +124,15 @@ void loop() by inserting your own Temboo account name and app key information. The contents of the file should look like: - #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key - You can find your Temboo App Key information on the Temboo website, + You can find your Temboo App Key information on the Temboo website, under My Account > Application Keys The same TembooAccount.h file settings can be used for all Temboo SDK sketches. - Keeping your account information in a separate file means you can share the main .ino file without worrying + Keeping your account information in a separate file means you can share the main .ino file without worrying that you forgot to delete your credentials. */ diff --git a/libraries/Bridge/examples/Temboo/SendAnEmail/SendAnEmail.ino b/libraries/Bridge/examples/Temboo/SendAnEmail/SendAnEmail.ino index 4f841f8e2..84f4b963a 100644 --- a/libraries/Bridge/examples/Temboo/SendAnEmail/SendAnEmail.ino +++ b/libraries/Bridge/examples/Temboo/SendAnEmail/SendAnEmail.ino @@ -5,17 +5,17 @@ Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino - A Temboo account and application key are necessary to run all Temboo examples. - If you don't already have one, you can register for a free Temboo account at + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at http://www.temboo.com - Since this sketch uses Gmail to send the email, you'll also need a valid - Google Gmail account. The sketch needs the username and password you use + Since this sketch uses Gmail to send the email, you'll also need a valid + Google Gmail account. The sketch needs the username and password you use to log into your Gmail account - substitute the placeholders below for these values. This example assumes basic familiarity with Arduino sketches, and that your Yun is connected to the Internet. - + Looking for another API to use with your Arduino Yun? We've got over 100 in our Library! This example code is in the public domain. @@ -24,7 +24,7 @@ #include #include #include "TembooAccount.h" // contains Temboo account information - // as described in the footer comment below +// as described in the footer comment below /*** SUBSTITUTE YOUR VALUES BELOW: ***/ @@ -41,14 +41,14 @@ const String GMAIL_PASSWORD = "xxxxxxxxxx"; const String TO_EMAIL_ADDRESS = "xxxxxxxxxx"; // a flag to indicate whether we've tried to send the email yet or not -boolean attempted = false; +boolean attempted = false; void setup() { Serial.begin(9600); // for debugging, wait until a serial console is connected delay(4000); - while(!Serial); + while (!Serial); Bridge.begin(); } @@ -59,14 +59,14 @@ void loop() if (!attempted) { Serial.println("Running SendAnEmail..."); - + TembooChoreo SendEmailChoreo; // invoke the Temboo client // NOTE that the client must be reinvoked, and repopulated with // appropriate arguments, each time its run() method is called. SendEmailChoreo.begin(); - + // set Temboo account credentials SendEmailChoreo.setAccountName(TEMBOO_ACCOUNT); SendEmailChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); @@ -74,13 +74,13 @@ void loop() // identify the Temboo Library choreo to run (Google > Gmail > SendEmail) SendEmailChoreo.setChoreo("/Library/Google/Gmail/SendEmail"); - + // set the required choreo inputs - // see https://www.temboo.com/library/Library/Google/Gmail/SendEmail/ + // see https://www.temboo.com/library/Library/Google/Gmail/SendEmail/ // for complete details about the inputs for this Choreo - // the first input is your Gmail email address. + // the first input is your Gmail email address. SendEmailChoreo.addInput("Username", GMAIL_USER_NAME); // next is your Gmail password. SendEmailChoreo.addInput("Password", GMAIL_PASSWORD); @@ -89,17 +89,17 @@ void loop() // then a subject line SendEmailChoreo.addInput("Subject", "ALERT: Greenhouse Temperature"); - // next comes the message body, the main content of the email + // next comes the message body, the main content of the email SendEmailChoreo.addInput("MessageBody", "Hey! The greenhouse is too cold!"); - // tell the Choreo to run and wait for the results. The - // return code (returnCode) will tell us whether the Temboo client + // tell the Choreo to run and wait for the results. The + // return code (returnCode) will tell us whether the Temboo client // was able to send our request to the Temboo servers unsigned int returnCode = SendEmailChoreo.run(); // a return code of zero (0) means everything worked if (returnCode == 0) { - Serial.println("Success! Email sent!"); + Serial.println("Success! Email sent!"); } else { // a non-zero return code means there was an error // read and print the error message @@ -107,9 +107,9 @@ void loop() char c = SendEmailChoreo.read(); Serial.print(c); } - } + } SendEmailChoreo.close(); - + // set the flag showing we've tried attempted = true; } @@ -123,15 +123,15 @@ void loop() by inserting your own Temboo account name and app key information. The contents of the file should look like: - #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key - You can find your Temboo App Key information on the Temboo website, + You can find your Temboo App Key information on the Temboo website, under My Account > Application Keys The same TembooAccount.h file settings can be used for all Temboo SDK sketches. - Keeping your account information in a separate file means you can share the main .ino file without worrying + Keeping your account information in a separate file means you can share the main .ino file without worrying that you forgot to delete your credentials. */ diff --git a/libraries/Bridge/examples/Temboo/SendAnSMS/SendAnSMS.ino b/libraries/Bridge/examples/Temboo/SendAnSMS/SendAnSMS.ino index 2b0cfb13f..6d6833cba 100644 --- a/libraries/Bridge/examples/Temboo/SendAnSMS/SendAnSMS.ino +++ b/libraries/Bridge/examples/Temboo/SendAnSMS/SendAnSMS.ino @@ -5,35 +5,35 @@ Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino - A Temboo account and application key are necessary to run all Temboo examples. - If you don't already have one, you can register for a free Temboo account at + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at http://www.temboo.com - Since this sketch uses Twilio to send the SMS, you'll also need a valid + Since this sketch uses Twilio to send the SMS, you'll also need a valid Twilio account. You can create one for free at https://www.twilio.com. - + The sketch needs your Twilio phone number, along with the Account SID and Auth Token you get when you register with Twilio. - Make sure to use the Account SID and Auth Token from your Twilio Dashboard + Make sure to use the Account SID and Auth Token from your Twilio Dashboard (not your test credentials from the Dev Tools panel). - Also note that if you're using a free Twilio account, you'll need to verify + Also note that if you're using a free Twilio account, you'll need to verify the phone number to which messages are being sent by going to twilio.com and following the instructions under the "Numbers > Verified Caller IDs" tab (this restriction doesn't apply if you have a paid Twilio account). - + This example assumes basic familiarity with Arduino sketches, and that your Yun is connected to the Internet. Looking for another API to use with your Arduino Yun? We've got over 100 in our Library! - + This example code is in the public domain. */ #include #include #include "TembooAccount.h" // contains Temboo account information - // as described in the footer comment below +// as described in the footer comment below @@ -55,14 +55,14 @@ const String TWILIO_NUMBER = "xxxxxxxxxx"; const String RECIPIENT_NUMBER = "xxxxxxxxxx"; // a flag to indicate whether we've attempted to send the SMS yet or not -boolean attempted = false; +boolean attempted = false; void setup() { Serial.begin(9600); // for debugging, wait until a serial console is connected delay(4000); - while(!Serial); + while (!Serial); Bridge.begin(); } @@ -73,7 +73,7 @@ void loop() if (!attempted) { Serial.println("Running SendAnSMS..."); - + // we need a Process object to send a Choreo request to Temboo TembooChoreo SendSMSChoreo; @@ -81,7 +81,7 @@ void loop() // NOTE that the client must be reinvoked and repopulated with // appropriate arguments each time its run() method is called. SendSMSChoreo.begin(); - + // set Temboo account credentials SendSMSChoreo.setAccountName(TEMBOO_ACCOUNT); SendSMSChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); @@ -91,32 +91,32 @@ void loop() SendSMSChoreo.setChoreo("/Library/Twilio/SMSMessages/SendSMS"); // set the required choreo inputs - // see https://www.temboo.com/library/Library/Twilio/SMSMessages/SendSMS/ + // see https://www.temboo.com/library/Library/Twilio/SMSMessages/SendSMS/ // for complete details about the inputs for this Choreo // the first input is a your AccountSID SendSMSChoreo.addInput("AccountSID", TWILIO_ACCOUNT_SID); - + // next is your Auth Token SendSMSChoreo.addInput("AuthToken", TWILIO_AUTH_TOKEN); - + // next is your Twilio phone number SendSMSChoreo.addInput("From", TWILIO_NUMBER); - + // next, what number to send the SMS to SendSMSChoreo.addInput("To", RECIPIENT_NUMBER); // finally, the text of the message to send SendSMSChoreo.addInput("Body", "Hey, there! This is a message from your Arduino Yun!"); - - // tell the Process to run and wait for the results. The - // return code (returnCode) will tell us whether the Temboo client + + // tell the Process to run and wait for the results. The + // return code (returnCode) will tell us whether the Temboo client // was able to send our request to the Temboo servers unsigned int returnCode = SendSMSChoreo.run(); // a return code of zero (0) means everything worked if (returnCode == 0) { - Serial.println("Success! SMS sent!"); + Serial.println("Success! SMS sent!"); } else { // a non-zero return code means there was an error // read and print the error message @@ -124,11 +124,11 @@ void loop() char c = SendSMSChoreo.read(); Serial.print(c); } - } + } SendSMSChoreo.close(); - + // set the flag indicatine we've tried once. - attempted=true; + attempted = true; } } @@ -140,15 +140,15 @@ void loop() by inserting your own Temboo account name and app key information. The contents of the file should look like: - #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key - You can find your Temboo App Key information on the Temboo website, + You can find your Temboo App Key information on the Temboo website, under My Account > Application Keys The same TembooAccount.h file settings can be used for all Temboo SDK sketches. - Keeping your account information in a separate file means you can share the main .ino file without worrying + Keeping your account information in a separate file means you can share the main .ino file without worrying that you forgot to delete your credentials. */ diff --git a/libraries/Bridge/examples/Temboo/SendDataToGoogleSpreadsheet/SendDataToGoogleSpreadsheet.ino b/libraries/Bridge/examples/Temboo/SendDataToGoogleSpreadsheet/SendDataToGoogleSpreadsheet.ino index 1f1b6b4b3..5949010ec 100644 --- a/libraries/Bridge/examples/Temboo/SendDataToGoogleSpreadsheet/SendDataToGoogleSpreadsheet.ino +++ b/libraries/Bridge/examples/Temboo/SendDataToGoogleSpreadsheet/SendDataToGoogleSpreadsheet.ino @@ -5,14 +5,14 @@ Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino - A Temboo account and application key are necessary to run all Temboo examples. - If you don't already have one, you can register for a free Temboo account at + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at http://www.temboo.com - Since this sketch uses a Google spreadsheet, you'll also need a + Since this sketch uses a Google spreadsheet, you'll also need a Google account: substitute the placeholders below for your Google account values. - This example assumes basic familiarity with Arduino sketches, and that your + This example assumes basic familiarity with Arduino sketches, and that your Yun is connected to the Internet. The columns in your spreadsheet must have labels for the Choreo to @@ -21,14 +21,14 @@ assumes there are two columns. The first column is the time (in milliseconds) that the row was appended, and the second column is a sensor value. In other words, your spreadsheet should look like: - - Time | Sensor Value | + + Time | Sensor Value | ------+----------------- | | - + NOTE that the first time you run this sketch, you may receive a warning from Google, prompting you to authorize access from a 3rd party system. - + Looking for another API to use with your Arduino Yun? We've got over 100 in our Library! This example code is in the public domain. @@ -38,7 +38,7 @@ #include #include #include "TembooAccount.h" // contains Temboo account information, - // as described in the footer comment below +// as described in the footer comment below /*** SUBSTITUTE YOUR VALUES BELOW: ***/ @@ -57,17 +57,17 @@ const String SPREADSHEET_TITLE = "your-spreadsheet-title"; const unsigned long RUN_INTERVAL_MILLIS = 60000; // how often to run the Choreo (in milliseconds) -// the last time we ran the Choreo +// the last time we ran the Choreo // (initialized to 60 seconds ago so the // Choreo is run immediately when we start up) -unsigned long lastRun = (unsigned long)-60000; +unsigned long lastRun = (unsigned long) - 60000; void setup() { - + // for debugging, wait until a serial console is connected Serial.begin(9600); delay(4000); - while(!Serial); + while (!Serial); Serial.print("Initializing the bridge..."); Bridge.begin(); @@ -84,7 +84,7 @@ void loop() // remember 'now' as the last time we ran the choreo lastRun = now; - + Serial.println("Getting sensor value..."); // get the value we want to append to our spreadsheet @@ -99,19 +99,19 @@ void loop() // NOTE that the client must be reinvoked and repopulated with // appropriate arguments each time its run() method is called. AppendRowChoreo.begin(); - + // set Temboo account credentials AppendRowChoreo.setAccountName(TEMBOO_ACCOUNT); AppendRowChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); AppendRowChoreo.setAppKey(TEMBOO_APP_KEY); - + // identify the Temboo Library choreo to run (Google > Spreadsheets > AppendRow) AppendRowChoreo.setChoreo("/Library/Google/Spreadsheets/AppendRow"); - + // set the required Choreo inputs - // see https://www.temboo.com/library/Library/Google/Spreadsheets/AppendRow/ + // see https://www.temboo.com/library/Library/Google/Spreadsheets/AppendRow/ // for complete details about the inputs for this Choreo - + // your Google username (usually your email address) AppendRowChoreo.addInput("Username", GOOGLE_USERNAME); @@ -131,7 +131,7 @@ void loop() AppendRowChoreo.addInput("RowData", rowData); // run the Choreo and wait for the results - // The return code (returnCode) will indicate success or failure + // The return code (returnCode) will indicate success or failure unsigned int returnCode = AppendRowChoreo.run(); // return code of zero (0) means success @@ -139,7 +139,7 @@ void loop() Serial.println("Success! Appended " + rowData); Serial.println(""); } else { - // return code of anything other than zero means failure + // return code of anything other than zero means failure // read and display any error messages while (AppendRowChoreo.available()) { char c = AppendRowChoreo.read(); @@ -151,7 +151,7 @@ void loop() } } -// this function simulates reading the value of a sensor +// this function simulates reading the value of a sensor unsigned long getSensorValue() { return analogRead(A0); } @@ -164,15 +164,15 @@ unsigned long getSensorValue() { by inserting your own Temboo account name and app key information. The contents of the file should look like: - #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key - You can find your Temboo App Key information on the Temboo website, + You can find your Temboo App Key information on the Temboo website, under My Account > Application Keys The same TembooAccount.h file settings can be used for all Temboo SDK sketches. - Keeping your account information in a separate file means you can share the main .ino file without worrying + Keeping your account information in a separate file means you can share the main .ino file without worrying that you forgot to delete your credentials. */ diff --git a/libraries/Bridge/examples/Temboo/ToxicFacilitiesSearch/ToxicFacilitiesSearch.ino b/libraries/Bridge/examples/Temboo/ToxicFacilitiesSearch/ToxicFacilitiesSearch.ino index 3b7f1d1aa..06c3db113 100644 --- a/libraries/Bridge/examples/Temboo/ToxicFacilitiesSearch/ToxicFacilitiesSearch.ino +++ b/libraries/Bridge/examples/Temboo/ToxicFacilitiesSearch/ToxicFacilitiesSearch.ino @@ -1,28 +1,28 @@ /* ToxicFacilitiesSearch - + Demonstrates making a request to the Envirofacts API using Temboo from an Arduino Yun. - This example retrieves the names and addresses of EPA-regulated facilities in the + This example retrieves the names and addresses of EPA-regulated facilities in the Toxins Release Inventory (TRI) database within a given zip code. - + Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino - A Temboo account and application key are necessary to run all Temboo examples. - If you don't already have one, you can register for a free Temboo account at + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at http://www.temboo.com - + This example assumes basic familiarity with Arduino sketches, and that your Yun is connected to the Internet. Looking for another API to use with your Arduino Yun? We've got over 100 in our Library! - + This example code is in the public domain. */ #include #include #include "TembooAccount.h" // contains Temboo account information - // as described in the footer comment below +// as described in the footer comment below // the zip code to search for toxin-emitting facilities String US_ZIP_CODE = "11215"; @@ -32,10 +32,10 @@ int maxRuns = 10; // max number of times the Envirofacts FacilitiesSearch Chore void setup() { Serial.begin(9600); - + // for debugging, wait until a serial console is connected delay(4000); - while(!Serial); + while (!Serial); Bridge.begin(); } @@ -43,7 +43,7 @@ void loop() { // while we haven't reached the max number of runs... if (numRuns <= maxRuns) { - + // print status Serial.println("Running ToxicFacilitiesSearch - Run #" + String(numRuns++) + "..."); @@ -54,26 +54,26 @@ void loop() // NOTE that the client must be reinvoked and repopulated with // appropriate arguments each time its run() method is called. FacilitiesSearchByZipChoreo.begin(); - + // set Temboo account credentials FacilitiesSearchByZipChoreo.setAccountName(TEMBOO_ACCOUNT); FacilitiesSearchByZipChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); FacilitiesSearchByZipChoreo.setAppKey(TEMBOO_APP_KEY); - + // identify the Temboo Library choreo to run (EnviroFacts > Toxins > FacilitiesSearchByZip) FacilitiesSearchByZipChoreo.setChoreo("/Library/EnviroFacts/Toxins/FacilitiesSearchByZip"); - + // set choreo inputs; in this case, the US zip code for which to retrieve toxin release data // the Temboo client provides standardized calls to 100+ cloud APIs FacilitiesSearchByZipChoreo.addInput("Zip", US_ZIP_CODE); - + // specify two output filters, to help simplify the Envirofacts API results. // see the tutorials on using Temboo SDK output filters at http://www.temboo.com/arduino FacilitiesSearchByZipChoreo.addOutputFilter("fac", "FACILITY_NAME", "Response"); FacilitiesSearchByZipChoreo.addOutputFilter("addr", "STREET_ADDRESS", "Response"); - // run the choreo + // run the choreo unsigned int returnCode = FacilitiesSearchByZipChoreo.run(); if (returnCode == 0) { String facilities; @@ -83,7 +83,7 @@ void loop() // the output filters we specified will return comma delimited // lists containing the name and street address of the facilities // located in the specified zip code. - while(FacilitiesSearchByZipChoreo.available()) { + while (FacilitiesSearchByZipChoreo.available()) { String name = FacilitiesSearchByZipChoreo.readStringUntil('\x1F'); name.trim(); @@ -97,8 +97,8 @@ void loop() } } FacilitiesSearchByZipChoreo.close(); - - // parse the comma delimited lists of facilities to join the + + // parse the comma delimited lists of facilities to join the // name with the address and print it to the serial monitor if (facilities.length() > 0) { int i = -1; @@ -118,12 +118,12 @@ void loop() address = addresses.substring(addressStart, i); addressStart = i + 1; } - + if (i >= 0) { printResult(facility, address); } - }while (i >= 0); + } while (i >= 0); facility = facilities.substring(facilityStart); address = addresses.substring(addressStart); printResult(facility, address); @@ -131,7 +131,7 @@ void loop() Serial.println("No facilities found in zip code " + US_ZIP_CODE); } } else { - while(FacilitiesSearchByZipChoreo.available()) { + while (FacilitiesSearchByZipChoreo.available()) { char c = FacilitiesSearchByZipChoreo.read(); Serial.print(c); } @@ -157,15 +157,15 @@ void printResult(String facility, String address) { by inserting your own Temboo account name and app key information. The contents of the file should look like: - #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key - You can find your Temboo App Key information on the Temboo website, + You can find your Temboo App Key information on the Temboo website, under My Account > Application Keys The same TembooAccount.h file settings can be used for all Temboo SDK sketches. - Keeping your account information in a separate file means you can share the main .ino file without worrying + Keeping your account information in a separate file means you can share the main .ino file without worrying that you forgot to delete your credentials. */ diff --git a/libraries/Bridge/examples/Temboo/UpdateFacebookStatus/UpdateFacebookStatus.ino b/libraries/Bridge/examples/Temboo/UpdateFacebookStatus/UpdateFacebookStatus.ino index dd8cabd73..124833d57 100644 --- a/libraries/Bridge/examples/Temboo/UpdateFacebookStatus/UpdateFacebookStatus.ino +++ b/libraries/Bridge/examples/Temboo/UpdateFacebookStatus/UpdateFacebookStatus.ino @@ -4,9 +4,9 @@ Demonstrates sending a Facebook status update using Temboo from an Arduino Yun. Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino - - A Temboo account and application key are necessary to run all Temboo examples. - If you don't already have one, you can register for a free Temboo account at + + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at http://www.temboo.com In order to run this sketch, you'll need to register an application using @@ -15,19 +15,19 @@ to use our OAuth Wizard (or OAuth Choreos) to obtain a Facebook access token. Substitute your access token for the placeholder value of FACEBOOK_ACCESS_TOKEN below. - This example assumes basic familiarity with Arduino sketches, and that your Yun + This example assumes basic familiarity with Arduino sketches, and that your Yun is connected to the Internet. - - Want to use another social API with your Arduino Yun? We've got Twitter, Google+, + + Want to use another social API with your Arduino Yun? We've got Twitter, Google+, Instagram, Tumblr and more in our Library! - This example code is in the public domain. + This example code is in the public domain. */ #include #include #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. */ diff --git a/libraries/Bridge/examples/Temboo/UploadToDropbox/UploadToDropbox.ino b/libraries/Bridge/examples/Temboo/UploadToDropbox/UploadToDropbox.ino index 744dcdb5e..b9f39fee6 100644 --- a/libraries/Bridge/examples/Temboo/UploadToDropbox/UploadToDropbox.ino +++ b/libraries/Bridge/examples/Temboo/UploadToDropbox/UploadToDropbox.ino @@ -1,23 +1,23 @@ /* UploadToDropbox - + Demonstrates uploading a file to a Dropbox account using Temboo from an Arduino Yun. - + Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino - A Temboo account and application key are necessary to run all Temboo examples. - If you don't already have one, you can register for a free Temboo account at + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at http://www.temboo.com - You'll also need a valid Dropbox app and accompanying OAuth credentials. - To create a Dropbox app, visit https://www.dropbox.com/developers/apps and + You'll also need a valid Dropbox app and accompanying OAuth credentials. + To create a Dropbox app, visit https://www.dropbox.com/developers/apps and do the following: - + 1. Create a "Dropbox API app" 2. Select "Files and datastores" 3. Select "Yes - my app only needs access to the files it creates." - - Once you've created your app, follow the instructions at + + Once you've created your app, follow the instructions at https://www.temboo.com/library/Library/Dropbox/OAuth/ to run the Initialize and Finalize OAuth Choreos. These Choreos complete the OAuth handshake and retrieve your Dropbox OAuth access tokens. @@ -25,14 +25,14 @@ to the Internet. Looking for another API to use with your Arduino Yun? We've got over 100 in our Library! - + This example code is in the public domain. */ #include #include #include "TembooAccount.h" // contains Temboo account information - // as described in the footer comment below +// as described in the footer comment below /*** SUBSTITUTE YOUR VALUES BELOW: ***/ @@ -43,7 +43,7 @@ // your Dropbox app key, available on the Dropbox developer console after registering an app const String DROPBOX_APP_KEY = "xxxxxxxxxx"; -// your Dropbox app secret, available on the Dropbox developer console after registering an app +// your Dropbox app secret, available on the Dropbox developer console after registering an app const String DROPBOX_APP_SECRET = "xxxxxxxxxx"; // your Dropbox access token, which is returned by the FinalizeOAuth Choreo @@ -57,10 +57,10 @@ boolean success = false; // a flag to indicate whether we've uploaded the file y void setup() { Serial.begin(9600); - + // For debugging, wait until a serial console is connected. delay(4000); - while(!Serial); + while (!Serial); Bridge.begin(); } @@ -68,23 +68,23 @@ void loop() { // only try to upload the file if we haven't already done so if (!success) { - + Serial.println("Base64 encoding data to upload..."); - + // base64 encode the data to upload String base64EncodedData = base64Encode("Hello, Arduino!"); Serial.println("Uploading data to Dropbox..."); - // we need a Process object to send a Choreo request to Temboo + // we need a Process object to send a Choreo request to Temboo TembooChoreo UploadFileChoreo; // invoke the Temboo client // NOTE that the client must be reinvoked and repopulated with // appropriate arguments each time its run() method is called. UploadFileChoreo.begin(); - + // set Temboo account credentials UploadFileChoreo.setAccountName(TEMBOO_ACCOUNT); UploadFileChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); @@ -92,7 +92,7 @@ void loop() // identify the Temboo Library choreo to run (Dropbox > FilesAndMetadata > UploadFile) UploadFileChoreo.setChoreo("/Library/Dropbox/FilesAndMetadata/UploadFile"); - + // set the required choreo inputs // see https://www.temboo.com/library/Library/Dropbox/FilesAndMetadata/UploadFile/ // for complete details about the inputs for this Choreo @@ -103,31 +103,31 @@ void loop() // next, the root folder on Dropbox relative to which the file path is specified. // to work with the Dropbox app you created earlier, this should be left as "sandbox" // if your Dropbox app has full access to your files, specify "dropbox" - UploadFileChoreo.addInput("Root","sandbox"); + UploadFileChoreo.addInput("Root", "sandbox"); // next, the Base64 encoded file data to upload UploadFileChoreo.addInput("FileContents", base64EncodedData); - + // finally, the Dropbox OAuth credentials defined above UploadFileChoreo.addInput("AppSecret", DROPBOX_APP_SECRET); UploadFileChoreo.addInput("AccessToken", DROPBOX_ACCESS_TOKEN); UploadFileChoreo.addInput("AccessTokenSecret", DROPBOX_ACCESS_TOKEN_SECRET); UploadFileChoreo.addInput("AppKey", DROPBOX_APP_KEY); - // tell the Process to run and wait for the results. The - // return code (returnCode) will tell us whether the Temboo client + // tell the Process to run and wait for the results. The + // return code (returnCode) will tell us whether the Temboo client // was able to send our request to the Temboo servers unsigned int returnCode = UploadFileChoreo.run(); // a return code of zero (0) means everything worked if (returnCode == 0) { - Serial.println("Success! File uploaded!"); - success = true; + Serial.println("Success! File uploaded!"); + success = true; } else { // a non-zero return code means there was an error Serial.println("Uh-oh! Something went wrong!"); } - + // print out the full response to the serial monitor in all // cases, just for debugging while (UploadFileChoreo.available()) { @@ -148,42 +148,42 @@ void loop() by calling a Temboo Utilities Choreo. */ String base64Encode(String toEncode) { - - // we need a Process object to send a Choreo request to Temboo - TembooChoreo Base64EncodeChoreo; - // invoke the Temboo client - Base64EncodeChoreo.begin(); - - // set Temboo account credentials - Base64EncodeChoreo.setAccountName(TEMBOO_ACCOUNT); - Base64EncodeChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); - Base64EncodeChoreo.setAppKey(TEMBOO_APP_KEY); + // we need a Process object to send a Choreo request to Temboo + TembooChoreo Base64EncodeChoreo; - // identify the Temboo Library choreo to run (Utilities > Encoding > Base64Encode) - Base64EncodeChoreo.setChoreo("/Library/Utilities/Encoding/Base64Encode"); - - // set choreo inputs - Base64EncodeChoreo.addInput("Text", toEncode); - - // run the choreo - Base64EncodeChoreo.run(); - - // read in the choreo results, and return the "Base64EncodedText" output value. - // see http://www.temboo.com/arduino for more details on using choreo outputs. - while(Base64EncodeChoreo.available()) { - // read the name of the output item - String name = Base64EncodeChoreo.readStringUntil('\x1F'); - name.trim(); + // invoke the Temboo client + Base64EncodeChoreo.begin(); - // read the value of the output item - String data = Base64EncodeChoreo.readStringUntil('\x1E'); - data.trim(); + // set Temboo account credentials + Base64EncodeChoreo.setAccountName(TEMBOO_ACCOUNT); + Base64EncodeChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); + Base64EncodeChoreo.setAppKey(TEMBOO_APP_KEY); - if(name == "Base64EncodedText") { - return data; - } + // identify the Temboo Library choreo to run (Utilities > Encoding > Base64Encode) + Base64EncodeChoreo.setChoreo("/Library/Utilities/Encoding/Base64Encode"); + + // set choreo inputs + Base64EncodeChoreo.addInput("Text", toEncode); + + // run the choreo + Base64EncodeChoreo.run(); + + // read in the choreo results, and return the "Base64EncodedText" output value. + // see http://www.temboo.com/arduino for more details on using choreo outputs. + while (Base64EncodeChoreo.available()) { + // read the name of the output item + String name = Base64EncodeChoreo.readStringUntil('\x1F'); + name.trim(); + + // read the value of the output item + String data = Base64EncodeChoreo.readStringUntil('\x1E'); + data.trim(); + + if (name == "Base64EncodedText") { + return data; } + } } /* @@ -194,15 +194,15 @@ String base64Encode(String toEncode) { by inserting your own Temboo account name and app key information. The contents of the file should look like: - #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key - You can find your Temboo App Key information on the Temboo website, + You can find your Temboo App Key information on the Temboo website, under My Account > Application Keys The same TembooAccount.h file settings can be used for all Temboo SDK sketches. - Keeping your account information in a separate file means you can share the main .ino file without worrying + Keeping your account information in a separate file means you can share the main .ino file without worrying that you forgot to delete your credentials. */ diff --git a/libraries/Bridge/examples/TemperatureWebPanel/TemperatureWebPanel.ino b/libraries/Bridge/examples/TemperatureWebPanel/TemperatureWebPanel.ino index 969c70e48..82b14ac2e 100644 --- a/libraries/Bridge/examples/TemperatureWebPanel/TemperatureWebPanel.ino +++ b/libraries/Bridge/examples/TemperatureWebPanel/TemperatureWebPanel.ino @@ -1,41 +1,41 @@ /* Temperature web interface - - This example shows how to serve data from an analog input + + This example shows how to serve data from an analog input via the Arduino Yún's built-in webserver using the Bridge library. - + The circuit: * TMP36 temperature sensor on analog pin A1 * SD card attached to SD card slot of the Arduino Yún - - Prepare your SD card with an empty folder in the SD root - named "arduino" and a subfolder of that named "www". - This will ensure that the Yún will create a link + + Prepare your SD card with an empty folder in the SD root + named "arduino" and a subfolder of that named "www". + This will ensure that the Yún will create a link to the SD to the "/mnt/sd" path. - - In this sketch folder is a basic webpage and a copy of zepto.js, a + + In this sketch folder is a basic webpage and a copy of zepto.js, a minimized version of jQuery. When you upload your sketch, these files will be placed in the /arduino/www/TemperatureWebPanel folder on your SD card. - + You can then go to http://arduino.local/sd/TemperatureWebPanel to see the output of this sketch. - - You can remove the SD card while the Linux and the + + You can remove the SD card while the Linux and the sketch are running but be careful not to remove it while the system is writing to it. - + created 6 July 2013 by Tom Igoe - + This example code is in the public domain. - + http://arduino.cc/en/Tutorial/TemperatureWebPanel - + */ #include #include -#include +#include // Listen on default port 5555, the webserver on the Yun // will forward there all the HTTP requests for us. @@ -47,7 +47,7 @@ void setup() { Serial.begin(9600); // Bridge startup - pinMode(13,OUTPUT); + pinMode(13, OUTPUT); digitalWrite(13, LOW); Bridge.begin(); digitalWrite(13, HIGH); @@ -66,7 +66,7 @@ void setup() { // get the time that this sketch started: Process startTime; startTime.runShellCommand("date"); - while(startTime.available()) { + while (startTime.available()) { char c = startTime.read(); startString += c; } @@ -89,16 +89,16 @@ void loop() { Process time; time.runShellCommand("date"); String timeString = ""; - while(time.available()) { + while (time.available()) { char c = time.read(); timeString += c; } Serial.println(timeString); int sensorValue = analogRead(A1); // convert the reading to millivolts: - float voltage = sensorValue * (5000/ 1024); + float voltage = sensorValue * (5000 / 1024); // convert the millivolts to temperature celsius: - float temperature = (voltage - 500)/10; + float temperature = (voltage - 500) / 10; // print the temperature: client.print("Current time on the Yún: "); client.println(timeString); diff --git a/libraries/Bridge/examples/TimeCheck/TimeCheck.ino b/libraries/Bridge/examples/TimeCheck/TimeCheck.ino index 540ffeb26..c658cb63a 100644 --- a/libraries/Bridge/examples/TimeCheck/TimeCheck.ino +++ b/libraries/Bridge/examples/TimeCheck/TimeCheck.ino @@ -1,16 +1,16 @@ /* - Time Check - + Time Check + Gets the time from the linino processor via Bridge then parses out hours, minutes and seconds for the Arduino - using an Arduino Yún. - + using an Arduino Yún. + created 27 May 2013 modified 21 June 2013 - By Tom Igoe + By Tom Igoe This example code is in the public domain. - + http://arduino.cc/en/Tutorial/TimeCheck */ @@ -24,14 +24,14 @@ int lastSecond = -1; // need an impossible value for comparison void setup() { Bridge.begin(); // initialize Bridge - Serial.begin(9600); // initialize serial - - while(!Serial); // wait for Serial Monitor to open + Serial.begin(9600); // initialize serial + + while (!Serial); // wait for Serial Monitor to open Serial.println("Time Check"); // Title of sketch // run an initial date process. Should return: // hh:mm:ss : - if (!date.running()) { + if (!date.running()) { date.begin("date"); date.addParameter("+%T"); date.run(); @@ -40,10 +40,10 @@ void setup() { void loop() { - if(lastSecond != seconds) { // if a second has passed + if (lastSecond != seconds) { // if a second has passed // print the time: if (hours <= 9) Serial.print("0"); // adjust for 0-9 - Serial.print(hours); + Serial.print(hours); Serial.print(":"); if (minutes <= 9) Serial.print("0"); // adjust for 0-9 Serial.print(minutes); @@ -52,7 +52,7 @@ void loop() { Serial.println(seconds); // restart the date process: - if (!date.running()) { + if (!date.running()) { date.begin("date"); date.addParameter("+%T"); date.run(); @@ -60,24 +60,24 @@ void loop() { } //if there's a result from the date process, parse it: - while (date.available()>0) { + while (date.available() > 0) { // get the result of the date process (should be hh:mm:ss): - String timeString = date.readString(); + String timeString = date.readString(); // find the colons: int firstColon = timeString.indexOf(":"); - int secondColon= timeString.lastIndexOf(":"); + int secondColon = timeString.lastIndexOf(":"); // get the substrings for hour, minute second: - String hourString = timeString.substring(0, firstColon); - String minString = timeString.substring(firstColon+1, secondColon); - String secString = timeString.substring(secondColon+1); + String hourString = timeString.substring(0, firstColon); + String minString = timeString.substring(firstColon + 1, secondColon); + String secString = timeString.substring(secondColon + 1); // convert to ints,saving the previous second: hours = hourString.toInt(); minutes = minString.toInt(); lastSecond = seconds; // save to do a time comparison seconds = secString.toInt(); - } + } } diff --git a/libraries/Bridge/examples/WiFiStatus/WiFiStatus.ino b/libraries/Bridge/examples/WiFiStatus/WiFiStatus.ino index be934a9e9..fe7c887b9 100644 --- a/libraries/Bridge/examples/WiFiStatus/WiFiStatus.ino +++ b/libraries/Bridge/examples/WiFiStatus/WiFiStatus.ino @@ -1,6 +1,6 @@ /* - WiFi Status - + WiFi Status + This sketch runs a script called "pretty-wifi-info.lua" installed on your Yún in folder /usr/bin. It prints information about the status of your wifi connection. @@ -11,22 +11,22 @@ created 18 June 2013 By Federico Fissore - + This example code is in the public domain. - + http://arduino.cc/en/Tutorial/YunWiFiStatus - + */ #include void setup() { Serial.begin(9600); // initialize serial communication - while(!Serial); // do nothing until the serial monitor is opened - + while (!Serial); // do nothing until the serial monitor is opened + Serial.println("Starting bridge...\n"); - pinMode(13,OUTPUT); - digitalWrite(13, LOW); + pinMode(13, OUTPUT); + digitalWrite(13, LOW); Bridge.begin(); // make contact with the linux processor digitalWrite(13, HIGH); // Led on pin 13 turns on when the bridge is ready @@ -38,15 +38,15 @@ void loop() { wifiCheck.runShellCommand("/usr/bin/pretty-wifi-info.lua"); // command you want to run - // while there's any characters coming back from the + // while there's any characters coming back from the // process, print them to the serial monitor: while (wifiCheck.available() > 0) { char c = wifiCheck.read(); Serial.print(c); } - + Serial.println(); - + delay(5000); } diff --git a/libraries/Bridge/examples/XivelyClient/XivelyClient.ino b/libraries/Bridge/examples/XivelyClient/XivelyClient.ino index c7741831d..b2b8dc163 100644 --- a/libraries/Bridge/examples/XivelyClient/XivelyClient.ino +++ b/libraries/Bridge/examples/XivelyClient/XivelyClient.ino @@ -1,15 +1,15 @@ /* - Xively sensor client with Strings - + Xively sensor client with Strings + This sketch connects an analog sensor to Xively, - using an Arduino Yún. - + using an Arduino Yún. + created 15 March 2010 updated 27 May 2013 by Tom Igoe - + http://arduino.cc/en/Tutorial/YunXivelyClient - + */ @@ -21,7 +21,7 @@ NOTE: passwords.h is not included with this repo because it contains my passwords. You need to create it for your own version of this application. To do so, make a new tab in Arduino, call it passwords.h, and include the following variables and constants: - + #define APIKEY "foo" // replace your pachube api key here #define FEEDID 0000 // replace your feed ID #define USERAGENT "my-project" // user agent is the project name @@ -38,7 +38,7 @@ void setup() { Bridge.begin(); Serial.begin(9600); - while(!Serial); // wait for Network Serial to open + while (!Serial); // wait for Network Serial to open Serial.println("Xively client"); // Do a first update immediately @@ -94,14 +94,14 @@ void sendData() { xively.addParameter("--data"); xively.addParameter(dataString); xively.addParameter("--header"); - xively.addParameter(apiString); + xively.addParameter(apiString); xively.addParameter(url); xively.run(); Serial.println("done!"); // If there's incoming data from the net connection, // send it out the Serial: - while (xively.available()>0) { + while (xively.available() > 0) { char c = xively.read(); Serial.write(c); } diff --git a/libraries/Bridge/examples/YunSerialTerminal/YunSerialTerminal.ino b/libraries/Bridge/examples/YunSerialTerminal/YunSerialTerminal.ino index d2704e80b..37fd31263 100644 --- a/libraries/Bridge/examples/YunSerialTerminal/YunSerialTerminal.ino +++ b/libraries/Bridge/examples/YunSerialTerminal/YunSerialTerminal.ino @@ -1,35 +1,35 @@ /* Arduino Yun USB-to-Serial - + Allows you to use the Yun's 32U4 processor as a serial terminal for the linino processor. - - Upload this to an Arduino Yun via serial (not WiFi) + + Upload this to an Arduino Yun via serial (not WiFi) then open the serial monitor at 115200 to see the boot process of the linino processor. You can also use the serial monitor - as a basic command line interface for the linino processor using + as a basic command line interface for the linino processor using this sketch. - + From the serial monitor the following commands can be issued: - + '~' followed by '0' -> Set the UART speed to 57600 baud '~' followed by '1' -> Set the UART speed to 115200 baud '~' followed by '2' -> Set the UART speed to 250000 baud '~' followed by '3' -> Set the UART speed to 500000 baud '~' followeb by '~' -> Sends the bridge's shutdown command to obtain the console. - + The circuit: * Arduino Yun - + created March 2013 by Massimo Banzi modified by Cristian Maglie - + This example code is in the public domain. - + http://arduino.cc/en/Tutorial/YunSerialTerminal - + */ @@ -75,8 +75,8 @@ void loop() { commandMode = false; // in all cases exit from command mode } } - if (Serial1.available()) { // got anything from Linino? - char c = (char)Serial1.read(); // read from Linino + if (Serial1.available()) { // got anything from Linino? + char c = (char)Serial1.read(); // read from Linino Serial.write(c); // write to USB-serial } } diff --git a/libraries/EEPROM/examples/eeprom_clear/eeprom_clear.ino b/libraries/EEPROM/examples/eeprom_clear/eeprom_clear.ino index d1e29bdbd..b18ff2ca3 100644 --- a/libraries/EEPROM/examples/eeprom_clear/eeprom_clear.ino +++ b/libraries/EEPROM/examples/eeprom_clear/eeprom_clear.ino @@ -13,7 +13,7 @@ void setup() // write a 0 to all 512 bytes of the EEPROM for (int i = 0; i < 512; i++) EEPROM.write(i, 0); - + // turn the LED on when we're done digitalWrite(13, HIGH); } diff --git a/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino b/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino index 0709b2d4c..ebf79d683 100644 --- a/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino +++ b/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino @@ -1,7 +1,7 @@ /* * EEPROM Read * - * Reads the value of each byte of the EEPROM and prints it + * Reads the value of each byte of the EEPROM and prints it * to the computer. * This example code is in the public domain. */ @@ -25,19 +25,19 @@ void loop() { // read a byte from the current address of the EEPROM value = EEPROM.read(address); - + Serial.print(address); Serial.print("\t"); Serial.print(value, DEC); Serial.println(); - + // advance to the next address of the EEPROM address = address + 1; - + // there are only 512 bytes of EEPROM, from 0 to 511, so if we're // on address 512, wrap around to address 0 if (address == 512) address = 0; - + delay(500); } diff --git a/libraries/EEPROM/examples/eeprom_write/eeprom_write.ino b/libraries/EEPROM/examples/eeprom_write/eeprom_write.ino index ae7c57ebd..c04788708 100644 --- a/libraries/EEPROM/examples/eeprom_write/eeprom_write.ino +++ b/libraries/EEPROM/examples/eeprom_write/eeprom_write.ino @@ -22,17 +22,17 @@ void loop() // 0 to 1023 and each byte of the EEPROM can only hold a // value from 0 to 255. int val = analogRead(0) / 4; - + // write the value to the appropriate byte of the EEPROM. // these values will remain there when the board is // turned off. EEPROM.write(addr, val); - - // advance to the next address. there are 512 bytes in + + // advance to the next address. there are 512 bytes in // the EEPROM, so go back to 0 when we hit 512. addr = addr + 1; if (addr == 512) addr = 0; - + delay(100); } diff --git a/libraries/Esplora/examples/Beginners/EsploraAccelerometer/EsploraAccelerometer.ino b/libraries/Esplora/examples/Beginners/EsploraAccelerometer/EsploraAccelerometer.ino index db5cc93ed..cb929af36 100644 --- a/libraries/Esplora/examples/Beginners/EsploraAccelerometer/EsploraAccelerometer.ino +++ b/libraries/Esplora/examples/Beginners/EsploraAccelerometer/EsploraAccelerometer.ino @@ -1,14 +1,14 @@ /* - Esplora Accelerometer - + Esplora Accelerometer + This sketch shows you how to read the values from the accelerometer. To see it in action, open the serial monitor and tilt the board. You'll see - the accelerometer values for each axis change when you tilt the board + the accelerometer values for each axis change when you tilt the board on that axis. - + Created on 22 Dec 2012 by Tom Igoe - + This example is in the public domain. */ @@ -17,7 +17,7 @@ void setup() { Serial.begin(9600); // initialize serial communications with your computer -} +} void loop() { @@ -25,9 +25,9 @@ void loop() int yAxis = Esplora.readAccelerometer(Y_AXIS); // read the Y axis int zAxis = Esplora.readAccelerometer(Z_AXIS); // read the Z axis - Serial.print("x: "); // print the label for X + Serial.print("x: "); // print the label for X Serial.print(xAxis); // print the value for the X axis - Serial.print("\ty: "); // print a tab character, then the label for Y + Serial.print("\ty: "); // print a tab character, then the label for Y Serial.print(yAxis); // print the value for the Y axis Serial.print("\tz: "); // print a tab character, then the label for Z Serial.println(zAxis); // print the value for the Z axis diff --git a/libraries/Esplora/examples/Beginners/EsploraBlink/EsploraBlink.ino b/libraries/Esplora/examples/Beginners/EsploraBlink/EsploraBlink.ino index e198551a0..0af16cc92 100644 --- a/libraries/Esplora/examples/Beginners/EsploraBlink/EsploraBlink.ino +++ b/libraries/Esplora/examples/Beginners/EsploraBlink/EsploraBlink.ino @@ -1,16 +1,16 @@ /* Esplora Blink - + This sketch blinks the Esplora's RGB LED. It goes through - all three primary colors (red, green, blue), then it + all three primary colors (red, green, blue), then it combines them for secondary colors(yellow, cyan, magenta), then - it turns on all the colors for white. + it turns on all the colors for white. For best results cover the LED with a piece of white paper to see the colors. - + Created on 22 Dec 2012 by Tom Igoe - + This example is in the public domain. */ @@ -22,19 +22,19 @@ void setup() { } void loop() { - Esplora.writeRGB(255,0,0); // make the LED red + Esplora.writeRGB(255, 0, 0); // make the LED red delay(1000); // wait 1 second - Esplora.writeRGB(0,255,0); // make the LED green + Esplora.writeRGB(0, 255, 0); // make the LED green delay(1000); // wait 1 second - Esplora.writeRGB(0,0,255); // make the LED blue + Esplora.writeRGB(0, 0, 255); // make the LED blue delay(1000); // wait 1 second - Esplora.writeRGB(255,255,0); // make the LED yellow + Esplora.writeRGB(255, 255, 0); // make the LED yellow delay(1000); // wait 1 second - Esplora.writeRGB(0,255,255); // make the LED cyan + Esplora.writeRGB(0, 255, 255); // make the LED cyan delay(1000); // wait 1 second - Esplora.writeRGB(255,0,255); // make the LED magenta + Esplora.writeRGB(255, 0, 255); // make the LED magenta delay(1000); // wait 1 second - Esplora.writeRGB(255,255,255);// make the LED white + Esplora.writeRGB(255, 255, 255); // make the LED white delay(1000); // wait 1 second } diff --git a/libraries/Esplora/examples/Beginners/EsploraJoystickMouse/EsploraJoystickMouse.ino b/libraries/Esplora/examples/Beginners/EsploraJoystickMouse/EsploraJoystickMouse.ino index 8d9260e3c..12faf5292 100644 --- a/libraries/Esplora/examples/Beginners/EsploraJoystickMouse/EsploraJoystickMouse.ino +++ b/libraries/Esplora/examples/Beginners/EsploraJoystickMouse/EsploraJoystickMouse.ino @@ -1,9 +1,9 @@ /* Esplora Joystick Mouse - + This sketch shows you how to read the joystick and use it to control the movement of the cursor on your computer. You're making your Esplora into a mouse! - + WARNING: this sketch will take over your mouse movement. If you lose control of your mouse do the following: 1) unplug the Esplora. @@ -11,13 +11,13 @@ 3) hold the reset button down while plugging your Esplora back in 4) while holding reset, click "Upload" 5) when you see the message "Done compiling", release the reset button. - + This will stop your Esplora from controlling your mouse while you upload a sketch that doesn't take control of the mouse. - + Created on 22 Dec 2012 by Tom Igoe - + This example is in the public domain. */ @@ -27,7 +27,7 @@ void setup() { Serial.begin(9600); // initialize serial communication with your computer Mouse.begin(); // take control of the mouse -} +} void loop() { @@ -41,10 +41,10 @@ void loop() Serial.print("\tButton: "); // print a tab character and a label for the button Serial.print(button); // print the button value - int mouseX = map( xValue,-512, 512, 10, -10); // map the X value to a range of movement for the mouse X - int mouseY = map( yValue,-512, 512, -10, 10); // map the Y value to a range of movement for the mouse Y + int mouseX = map( xValue, -512, 512, 10, -10); // map the X value to a range of movement for the mouse X + int mouseY = map( yValue, -512, 512, -10, 10); // map the Y value to a range of movement for the mouse Y Mouse.move(mouseX, mouseY, 0); // move the mouse - + delay(10); // a short delay before moving again } diff --git a/libraries/Esplora/examples/Beginners/EsploraLedShow/EsploraLedShow.ino b/libraries/Esplora/examples/Beginners/EsploraLedShow/EsploraLedShow.ino index 3c617dcce..5503628a6 100644 --- a/libraries/Esplora/examples/Beginners/EsploraLedShow/EsploraLedShow.ino +++ b/libraries/Esplora/examples/Beginners/EsploraLedShow/EsploraLedShow.ino @@ -3,7 +3,7 @@ Makes the RGB LED bright and glow as the joystick or the slider are moved. - + Created on 22 november 2012 By Enrico Gueli Modified 22 Dec 2012 @@ -21,12 +21,12 @@ void loop() { int xAxis = Esplora.readJoystickX(); int yAxis = Esplora.readJoystickY(); int slider = Esplora.readSlider(); - + // convert the sensor readings to light levels: byte red = map(xAxis, -512, 512, 0, 255); byte green = map(yAxis, -512, 512, 0, 255); - byte blue = slider/4; - + byte blue = slider / 4; + // print the light levels: Serial.print(red); Serial.print(' '); @@ -34,9 +34,9 @@ void loop() { Serial.print(' '); Serial.println(blue); - // write the light levels to the LED. + // write the light levels to the LED. Esplora.writeRGB(red, green, blue); - // add a delay to keep the LED from flickering: + // add a delay to keep the LED from flickering: delay(10); } diff --git a/libraries/Esplora/examples/Beginners/EsploraLedShow2/EsploraLedShow2.ino b/libraries/Esplora/examples/Beginners/EsploraLedShow2/EsploraLedShow2.ino index 8f9f8a2bf..6a383ae3d 100644 --- a/libraries/Esplora/examples/Beginners/EsploraLedShow2/EsploraLedShow2.ino +++ b/libraries/Esplora/examples/Beginners/EsploraLedShow2/EsploraLedShow2.ino @@ -22,7 +22,7 @@ void setup() { } int lowLight = 400; // the light sensor reading when it's covered -int highLight = 1023; // the maximum light sensor reading +int highLight = 1023; // the maximum light sensor reading int minGreen = 0; // minimum brightness of the green LED int maxGreen = 100; // maximum brightness of the green LED @@ -31,13 +31,13 @@ void loop() { int mic = Esplora.readMicrophone(); int light = Esplora.readLightSensor(); int slider = Esplora.readSlider(); - + // convert the sensor readings to light levels: byte red = constrain(mic, 0, 255); byte green = constrain( - map(light, lowLight, highLight, minGreen, maxGreen), - 0, 255); - byte blue = slider/4; + map(light, lowLight, highLight, minGreen, maxGreen), + 0, 255); + byte blue = slider / 4; // print the light levels (to see what's going on): Serial.print(red); @@ -46,10 +46,10 @@ void loop() { Serial.print(' '); Serial.println(blue); - // write the light levels to the LED. + // write the light levels to the LED. // note that the green value is always 0: Esplora.writeRGB(red, green, blue); - + // add a delay to keep the LED from flickering: - delay(10); + delay(10); } diff --git a/libraries/Esplora/examples/Beginners/EsploraLightCalibrator/EsploraLightCalibrator.ino b/libraries/Esplora/examples/Beginners/EsploraLightCalibrator/EsploraLightCalibrator.ino index c3eaff429..97412737d 100644 --- a/libraries/Esplora/examples/Beginners/EsploraLightCalibrator/EsploraLightCalibrator.ino +++ b/libraries/Esplora/examples/Beginners/EsploraLightCalibrator/EsploraLightCalibrator.ino @@ -1,17 +1,17 @@ /* Esplora Led calibration - + This sketch shows you how to read and calibrate the light sensor. - Because light levels vary from one location to another, you need to calibrate the + Because light levels vary from one location to another, you need to calibrate the sensor for each location. To do this, you read the sensor for a few seconds, - and save the highest and lowest readings as maximum and minimum. + and save the highest and lowest readings as maximum and minimum. Then, when you're using the sensor's reading (for example, to set the brightness of the LED), you map the sensor's reading to a range between the minimum and the maximum. - + Created on 22 Dec 2012 by Tom Igoe - + This example is in the public domain. */ @@ -43,9 +43,9 @@ void loop() { int brightness = map(light, lightMin, lightMax, 0, 255); // limit the brightness to a range from 0 to 255: brightness = constrain(brightness, 0, 255); - // write the brightness to the blue LED. + // write the brightness to the blue LED. Esplora.writeBlue(brightness); - + // if the calibration's been done, show the sensor and brightness // levels in the serial monitor: if (calibrated == true) { @@ -56,7 +56,7 @@ void loop() { Serial.println(brightness); } // add a delay to keep the LED from flickering: - delay(10); + delay(10); } void calibrate() { @@ -64,8 +64,8 @@ void calibrate() { Serial.println("While holding switch 1, shine a light on the light sensor, then cover it."); // calibrate while switch 1 is pressed: - while(Esplora.readButton(1) == LOW) { - // read the sensor value: + while (Esplora.readButton(1) == LOW) { + // read the sensor value: int light = Esplora.readLightSensor(); // record the maximum sensor value: diff --git a/libraries/Esplora/examples/Beginners/EsploraMusic/EsploraMusic.ino b/libraries/Esplora/examples/Beginners/EsploraMusic/EsploraMusic.ino index 7a950fb15..82d592a7d 100644 --- a/libraries/Esplora/examples/Beginners/EsploraMusic/EsploraMusic.ino +++ b/libraries/Esplora/examples/Beginners/EsploraMusic/EsploraMusic.ino @@ -16,19 +16,19 @@ // these are the frequencies for the notes from middle C // to one octave above middle C: const int note[] = { -262, // C -277, // C# -294, // D -311, // D# -330, // E -349, // F -370, // F# -392, // G -415, // G# -440, // A -466, // A# -494, // B -523 // C next octave + 262, // C + 277, // C# + 294, // D + 311, // D# + 330, // E + 349, // F + 370, // F# + 392, // G + 415, // G# + 440, // A + 466, // A# + 494, // B + 523 // C next octave }; void setup() { @@ -39,8 +39,8 @@ void loop() { // then play a note: if (Esplora.readButton(SWITCH_DOWN) == LOW) { int slider = Esplora.readSlider(); - - // use map() to map the slider's range to the + + // use map() to map the slider's range to the // range of notes you have: byte thisNote = map(slider, 0, 1023, 0, 13); // play the note corresponding to the slider's position: diff --git a/libraries/Esplora/examples/Beginners/EsploraSoundSensor/EsploraSoundSensor.ino b/libraries/Esplora/examples/Beginners/EsploraSoundSensor/EsploraSoundSensor.ino index 3bf454fed..6550dc7d3 100644 --- a/libraries/Esplora/examples/Beginners/EsploraSoundSensor/EsploraSoundSensor.ino +++ b/libraries/Esplora/examples/Beginners/EsploraSoundSensor/EsploraSoundSensor.ino @@ -1,15 +1,15 @@ /* Esplora Sound Sensor - + This sketch shows you how to read the microphone sensor. The microphone -will range from 0 (total silence) to 1023 (really loud). +will range from 0 (total silence) to 1023 (really loud). When you're using the sensor's reading (for example, to set the brightness of the LED), you map the sensor's reading to a range between the minimum and the maximum. - + Created on 22 Dec 2012 by Tom Igoe - + This example is in the public domain. */ @@ -26,16 +26,16 @@ void loop() { // map the sound level to a brightness level for the LED: int brightness = map(loudness, 0, 1023, 0, 255); - // write the brightness to the green LED: + // write the brightness to the green LED: Esplora.writeGreen(brightness); - - - // print the microphone levels and the LED levels (to see what's going on): - Serial.print("sound level: "); - Serial.print(loudness); - Serial.print(" Green brightness: "); - Serial.println(brightness); + + + // print the microphone levels and the LED levels (to see what's going on): + Serial.print("sound level: "); + Serial.print(loudness); + Serial.print(" Green brightness: "); + Serial.println(brightness); // add a delay to keep the LED from flickering: - delay(10); + delay(10); } diff --git a/libraries/Esplora/examples/Beginners/EsploraTemperatureSensor/EsploraTemperatureSensor.ino b/libraries/Esplora/examples/Beginners/EsploraTemperatureSensor/EsploraTemperatureSensor.ino index 72bbf04e0..68aef5173 100644 --- a/libraries/Esplora/examples/Beginners/EsploraTemperatureSensor/EsploraTemperatureSensor.ino +++ b/libraries/Esplora/examples/Beginners/EsploraTemperatureSensor/EsploraTemperatureSensor.ino @@ -1,12 +1,12 @@ /* Esplora Temperature Sensor - + This sketch shows you how to read the Esplora's temperature sensor You can read the temperature sensor in Farhenheit or Celsius. - + Created on 22 Dec 2012 by Tom Igoe - + This example is in the public domain. */ #include @@ -14,7 +14,7 @@ void setup() { Serial.begin(9600); // initialize serial communications with your computer -} +} void loop() { diff --git a/libraries/Esplora/examples/Experts/EsploraKart/EsploraKart.ino b/libraries/Esplora/examples/Experts/EsploraKart/EsploraKart.ino index 4c1621c19..38e99af26 100644 --- a/libraries/Esplora/examples/Experts/EsploraKart/EsploraKart.ino +++ b/libraries/Esplora/examples/Experts/EsploraKart/EsploraKart.ino @@ -7,7 +7,7 @@ By moving the joystick in a direction or by pressing a switch, the PC will "see" that a key is pressed. If the PC is running a game that has keyboard input, the Esplora can control it. - + The default configuration is suitable for SuperTuxKart, an open-source racing game. It can be downloaded from http://supertuxkart.sourceforge.net/ . @@ -20,11 +20,11 @@ #include /* - You're going to handle eight different buttons. You'll use arrays, - which are ordered lists of variables with a fixed size. Each array + You're going to handle eight different buttons. You'll use arrays, + which are ordered lists of variables with a fixed size. Each array has an index (counting from 0) to keep track of the position you're reading in the array, and each position can contain a number. - + This code uses three different arrays: one for the buttons you'll read; a second to hold the current states of those buttons; and a third to hold the keystrokes associated with each button. @@ -89,14 +89,14 @@ void setup() { Here we continuously check if something happened with the buttons. */ -void loop() { - +void loop() { + // Iterate through all the buttons: - for (byte thisButton=0; thisButton<8; thisButton++) { + for (byte thisButton = 0; thisButton < 8; thisButton++) { boolean lastState = buttonStates[thisButton]; boolean newState = Esplora.readButton(buttons[thisButton]); if (lastState != newState) { // Something changed! - /* + /* The Keyboard library allows you to "press" and "release" the keys as two distinct actions. These actions can be linked to the buttons we're handling. @@ -112,7 +112,7 @@ void loop() { // Store the new button state, so you can sense a difference later: buttonStates[thisButton] = newState; } - + /* Wait a little bit (50ms) between a check and another. When a mechanical switch is pressed or released, the diff --git a/libraries/Esplora/examples/Experts/EsploraPong/EsploraPong.ino b/libraries/Esplora/examples/Experts/EsploraPong/EsploraPong.ino index 725a109f3..945fdee26 100644 --- a/libraries/Esplora/examples/Experts/EsploraPong/EsploraPong.ino +++ b/libraries/Esplora/examples/Experts/EsploraPong/EsploraPong.ino @@ -1,21 +1,21 @@ /* Esplora Pong - + This sketch connects serially to a Processing sketch to control a Pong game. - It sends the position of the slider and the states of three pushbuttons to the - Processing sketch serially, separated by commas. The Processing sketch uses that + It sends the position of the slider and the states of three pushbuttons to the + Processing sketch serially, separated by commas. The Processing sketch uses that data to control the graphics in the sketch. - + The slider sets a paddle's height Switch 1 is resets the game Switch 2 resets the ball to the center Switch 3 reverses the players - + You can play this game with one or two Esploras. - + Created on 22 Dec 2012 by Tom Igoe - + This example is in the public domain. */ diff --git a/libraries/Esplora/examples/Experts/EsploraRemote/EsploraRemote.ino b/libraries/Esplora/examples/Experts/EsploraRemote/EsploraRemote.ino index 27010897b..f70aec49a 100644 --- a/libraries/Esplora/examples/Experts/EsploraRemote/EsploraRemote.ino +++ b/libraries/Esplora/examples/Experts/EsploraRemote/EsploraRemote.ino @@ -1,28 +1,28 @@ /* Esplora Remote - + This sketch allows to test all the Esplora's peripherals. It is also used with the ProcessingStart sketch (for Processing). - + When uploaded, you can open the Serial monitor and write one of the following commands (without quotes) to get an answer: - + "D": prints the current value of all sensors, separated by a comma. See the dumpInputs() function below to get the meaning of each value. - + "Rxxx" "Gxxx" "Bxxx": set the color of the RGB led. For example, write "R255" to turn on the red to full brightness, "G128" to turn the green to half brightness, or "G0" to turn off the green channel. - + "Txxxx": play a tone with the buzzer. The number is the frequency, e.g. "T440" plays the central A note. Write "T0" to turn off the buzzer. - - + + Created on 22 november 2012 By Enrico Gueli Modified 23 Dec 2012 @@ -32,7 +32,7 @@ #include void setup() { - while(!Serial); // needed for Leonardo-based board like Esplora + while (!Serial); // needed for Leonardo-based board like Esplora Serial.begin(9600); } @@ -48,53 +48,53 @@ void loop() { */ void parseCommand() { char cmd = Serial.read(); - switch(cmd) { - case 'D': - dumpInputs(); - break; - case 'R': - setRed(); - break; - case 'G': - setGreen(); - break; - case 'B': - setBlue(); - break; - case 'T': - setTone(); - break; + switch (cmd) { + case 'D': + dumpInputs(); + break; + case 'R': + setRed(); + break; + case 'G': + setGreen(); + break; + case 'B': + setBlue(); + break; + case 'T': + setTone(); + break; } } -void dumpInputs() { - Serial.print(Esplora.readButton(SWITCH_1)); +void dumpInputs() { + Serial.print(Esplora.readButton(SWITCH_1)); Serial.print(','); - Serial.print(Esplora.readButton(SWITCH_2)); + Serial.print(Esplora.readButton(SWITCH_2)); Serial.print(','); - Serial.print(Esplora.readButton(SWITCH_3)); + Serial.print(Esplora.readButton(SWITCH_3)); Serial.print(','); - Serial.print(Esplora.readButton(SWITCH_4)); + Serial.print(Esplora.readButton(SWITCH_4)); Serial.print(','); - Serial.print(Esplora.readSlider()); + Serial.print(Esplora.readSlider()); Serial.print(','); - Serial.print(Esplora.readLightSensor()); + Serial.print(Esplora.readLightSensor()); Serial.print(','); - Serial.print(Esplora.readTemperature(DEGREES_C)); + Serial.print(Esplora.readTemperature(DEGREES_C)); Serial.print(','); - Serial.print(Esplora.readMicrophone()); + Serial.print(Esplora.readMicrophone()); Serial.print(','); - Serial.print(Esplora.readJoystickSwitch()); + Serial.print(Esplora.readJoystickSwitch()); Serial.print(','); - Serial.print(Esplora.readJoystickX()); + Serial.print(Esplora.readJoystickX()); Serial.print(','); - Serial.print(Esplora.readJoystickY()); + Serial.print(Esplora.readJoystickY()); Serial.print(','); - Serial.print(Esplora.readAccelerometer(X_AXIS)); + Serial.print(Esplora.readAccelerometer(X_AXIS)); Serial.print(','); - Serial.print(Esplora.readAccelerometer(Y_AXIS)); + Serial.print(Esplora.readAccelerometer(Y_AXIS)); Serial.print(','); - Serial.print(Esplora.readAccelerometer(Z_AXIS)); + Serial.print(Esplora.readAccelerometer(Z_AXIS)); Serial.println(); } diff --git a/libraries/Esplora/examples/Experts/EsploraTable/EsploraTable.ino b/libraries/Esplora/examples/Experts/EsploraTable/EsploraTable.ino index 712dffa7a..e2983ff5d 100644 --- a/libraries/Esplora/examples/Experts/EsploraTable/EsploraTable.ino +++ b/libraries/Esplora/examples/Experts/EsploraTable/EsploraTable.ino @@ -3,18 +3,18 @@ Acts like a keyboard that prints sensor data in a table-like text, row by row. - + At startup, it does nothing. It waits for you to open a spreadsheet (e.g. Google Drive spreadsheet) so it can write data. By pressing Switch 1, it starts printing the table headers and the first row of data. It waits a bit, then it will print another row, and so on. - + The amount of time between each row is determined by the slider. If put to full left, the sketch will wait 10 seconds; at full right position, it will wait 5 minutes. An intermediate position will make the sketch wait for some time in-between. - + Clicking the Switch 1 at any time will stop the logging. The color LED shows what the sketch is doing: @@ -87,7 +87,7 @@ void loop() { * check for button presses often enough to not miss any event. */ activeDelay(50); - + /* * the justActivated variable may be set to true in the * checkSwitchPress() function. Here we check its status to @@ -99,7 +99,7 @@ void loop() { // do next sampling ASAP nextSampleAt = startedAt = millis(); } - + if (active == true) { if (nextSampleAt < millis()) { // it's time to sample! @@ -108,24 +108,24 @@ void loop() { // 10 and 290 seconds. int sampleInterval = map(slider, 0, 1023, 10, 290); nextSampleAt = millis() + sampleInterval * 1000; - + logAndPrint(); } - + // let the RGB led blink green once per second, for 200ms. unsigned int ms = millis() % 1000; if (ms < 200) Esplora.writeGreen(50); else Esplora.writeGreen(0); - + Esplora.writeBlue(0); - } + } else // while not active, keep a reassuring blue color coming // from the Esplora... Esplora.writeBlue(20); - + } /* @@ -135,7 +135,7 @@ void printHeaders() { Keyboard.print("Time"); Keyboard.write(KEY_TAB); activeDelay(300); // Some spreadsheets are slow, e.g. Google - // Drive that wants to save every edit. + // Drive that wants to save every edit. Keyboard.print("Accel X"); Keyboard.write(KEY_TAB); activeDelay(300); @@ -149,13 +149,13 @@ void printHeaders() { void logAndPrint() { // do all the samplings at once, because keystrokes have delays - unsigned long timeSecs = (millis() - startedAt) /1000; + unsigned long timeSecs = (millis() - startedAt) / 1000; int xAxis = Esplora.readAccelerometer(X_AXIS); int yAxis = Esplora.readAccelerometer(Y_AXIS); int zAxis = Esplora.readAccelerometer(Z_AXIS); - + Esplora.writeRed(100); - + Keyboard.print(timeSecs); Keyboard.write(KEY_TAB); activeDelay(300); @@ -169,7 +169,7 @@ void logAndPrint() { Keyboard.println(); activeDelay(300); Keyboard.write(KEY_HOME); - + Esplora.writeRed(0); } @@ -204,9 +204,9 @@ void checkSwitchPress() { if (startBtn == HIGH) { // button released active = !active; if (active) - justActivated = true; + justActivated = true; } - + lastStartBtn = startBtn; } } diff --git a/libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino b/libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino index bfbcb6d4a..2c85ddd78 100644 --- a/libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino +++ b/libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino @@ -1,14 +1,14 @@ /* SCP1000 Barometric Pressure Sensor Display - + Serves the output of a Barometric Pressure Sensor as a web page. Uses the SPI library. For details on the sensor, see: http://www.sparkfun.com/commerce/product_info.php?products_id=8161 http://www.vti.fi/en/support/obsolete_products/pressure_sensors/ - + This sketch adapted from Nathan Seidle's SCP1000 example for PIC: http://www.sparkfun.com/datasheets/Sensors/SCP1000-Testing.zip - + Circuit: SCP1000 sensor attached to pins 6,7, and 11 - 13: DRDY: pin 6 @@ -16,7 +16,7 @@ MOSI: pin 11 MISO: pin 12 SCK: pin 13 - + created 31 July 2010 by Tom Igoe */ @@ -28,16 +28,17 @@ // assign a MAC address for the ethernet controller. // fill in your address here: -byte mac[] = { - 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; // assign an IP address for the controller: -IPAddress ip(192,168,1,20); -IPAddress gateway(192,168,1,1); +IPAddress ip(192, 168, 1, 20); +IPAddress gateway(192, 168, 1, 1); IPAddress subnet(255, 255, 255, 0); // Initialize the Ethernet server library -// with the IP address and port you want to use +// with the IP address and port you want to use // (port 80 is default for HTTP): EthernetServer server(80); @@ -49,7 +50,7 @@ const int TEMPERATURE = 0x21; //16 bit temperature reading // pins used for the connection with the sensor // the others you need are controlled by the SPI library): -const int dataReadyPin = 6; +const int dataReadyPin = 6; const int chipSelectPin = 7; float temperature = 0.0; @@ -83,9 +84,9 @@ void setup() { } -void loop() { +void loop() { // check for a reading no more than once a second. - if (millis() - lastReadingTime > 1000){ + if (millis() - lastReadingTime > 1000) { // if there's a reading ready, read it: // don't do anything until the data ready pin is high: if (digitalRead(dataReadyPin) == HIGH) { @@ -109,13 +110,13 @@ void getData() { temperature = (float)tempData / 20.0; //Read the pressure data highest 3 bits: - byte pressureDataHigh = readRegister(0x1F, 1); + byte pressureDataHigh = readRegister(0x1F, 1); pressureDataHigh &= 0b00000111; //you only needs bits 2 to 0 //Read the pressure data lower 16 bits: - unsigned int pressureDataLow = readRegister(0x20, 2); + unsigned int pressureDataLow = readRegister(0x20, 2); //combine the two parts into one 19-bit number: - pressure = ((pressureDataHigh << 16) | pressureDataLow)/4; + pressure = ((pressureDataHigh << 16) | pressureDataLow) / 4; Serial.print("Temperature: "); Serial.print(temperature); @@ -149,13 +150,13 @@ void listenForEthernetClients() { client.println("
"); client.print("Pressure: " + String(pressure)); client.print(" Pa"); - client.println("
"); + client.println("
"); break; } if (c == '\n') { // you're starting a new line currentLineIsBlank = true; - } + } else if (c != '\r') { // you've gotten a character on the current line currentLineIsBlank = false; @@ -167,7 +168,7 @@ void listenForEthernetClients() { // close the connection: client.stop(); } -} +} //Send a write command to SCP1000 @@ -179,20 +180,20 @@ void writeRegister(byte registerName, byte registerValue) { registerName |= 0b00000010; //Write command // take the chip select low to select the device: - digitalWrite(chipSelectPin, LOW); + digitalWrite(chipSelectPin, LOW); SPI.transfer(registerName); //Send register location SPI.transfer(registerValue); //Send value to record into register // take the chip select high to de-select: - digitalWrite(chipSelectPin, HIGH); + digitalWrite(chipSelectPin, HIGH); } //Read register from the SCP1000: unsigned int readRegister(byte registerName, int numBytes) { byte inByte = 0; // incoming from the SPI read - unsigned int result = 0; // result to return + unsigned int result = 0; // result to return // SCP1000 expects the register name in the upper 6 bits // of the byte: @@ -201,22 +202,22 @@ unsigned int readRegister(byte registerName, int numBytes) { registerName &= 0b11111100; //Read command // take the chip select low to select the device: - digitalWrite(chipSelectPin, LOW); + digitalWrite(chipSelectPin, LOW); // send the device the register you want to read: - int command = SPI.transfer(registerName); + int command = SPI.transfer(registerName); // send a value of 0 to read the first byte returned: - inByte = SPI.transfer(0x00); - + inByte = SPI.transfer(0x00); + result = inByte; - // if there's more than one byte returned, + // if there's more than one byte returned, // shift the first byte then get the second byte: - if (numBytes > 1){ + if (numBytes > 1) { result = inByte << 8; - inByte = SPI.transfer(0x00); - result = result |inByte; + inByte = SPI.transfer(0x00); + result = result | inByte; } // take the chip select high to de-select: - digitalWrite(chipSelectPin, HIGH); + digitalWrite(chipSelectPin, HIGH); // return the result: return(result); } diff --git a/libraries/Ethernet/examples/ChatServer/ChatServer.ino b/libraries/Ethernet/examples/ChatServer/ChatServer.ino index d50e5a657..927a60e1b 100644 --- a/libraries/Ethernet/examples/ChatServer/ChatServer.ino +++ b/libraries/Ethernet/examples/ChatServer/ChatServer.ino @@ -1,20 +1,20 @@ /* Chat Server - + A simple server that distributes any incoming messages to all connected clients. To use telnet to your device's IP address and type. You can see the client's input in the serial monitor as well. - Using an Arduino Wiznet Ethernet shield. - + Using an Arduino Wiznet Ethernet shield. + Circuit: * Ethernet shield attached to pins 10, 11, 12, 13 * Analog inputs attached to pins A0 through A5 (optional) - + created 18 Dec 2009 by David A. Mellis modified 9 Apr 2012 by Tom Igoe - + */ #include @@ -23,10 +23,11 @@ // Enter a MAC address and IP address for your controller below. // The IP address will be dependent on your local network. // gateway and subnet are optional: -byte mac[] = { - 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; -IPAddress ip(192,168,1, 177); -IPAddress gateway(192,168,1, 1); +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; +IPAddress ip(192, 168, 1, 177); +IPAddress gateway(192, 168, 1, 1); IPAddress subnet(255, 255, 0, 0); @@ -39,9 +40,9 @@ void setup() { Ethernet.begin(mac, ip, gateway, subnet); // start listening for clients server.begin(); - // Open serial communications and wait for port to open: + // Open serial communications and wait for port to open: Serial.begin(9600); - while (!Serial) { + while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } @@ -58,11 +59,11 @@ void loop() { if (client) { if (!alreadyConnected) { // clead out the input buffer: - client.flush(); + client.flush(); Serial.println("We have a new client"); - client.println("Hello, client!"); + client.println("Hello, client!"); alreadyConnected = true; - } + } if (client.available() > 0) { // read the bytes incoming from the client: diff --git a/libraries/Ethernet/examples/CosmClient/CosmClient.ino b/libraries/Ethernet/examples/CosmClient/CosmClient.ino index ec742780f..11dac86f8 100644 --- a/libraries/Ethernet/examples/CosmClient/CosmClient.ino +++ b/libraries/Ethernet/examples/CosmClient/CosmClient.ino @@ -1,27 +1,27 @@ /* Cosm sensor client - + This sketch connects an analog sensor to Cosm (http://www.cosm.com) using a Wiznet Ethernet shield. You can use the Arduino Ethernet shield, or the Adafruit Ethernet shield, either one will work, as long as it's got a Wiznet Ethernet module on board. - - This example has been updated to use version 2.0 of the cosm.com API. + + This example has been updated to use version 2.0 of the cosm.com API. To make it work, create a feed with a datastream, and give it the ID sensor1. Or change the code below to match your feed. - - + + Circuit: * Analog sensor attached to analog in 0 * Ethernet shield attached to pins 10, 11, 12, 13 - + created 15 March 2010 updated 14 May 2012 by Tom Igoe with input from Usman Haque and Joe Saavedra - + http://arduino.cc/en/Tutorial/CosmClient This code is in the public domain. - + */ #include @@ -34,12 +34,13 @@ http://arduino.cc/en/Tutorial/CosmClient // assign a MAC address for the ethernet controller. // Newer Ethernet shields have a MAC address printed on a sticker on the shield // fill in your address here: -byte mac[] = { - 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; // fill in an available IP address on your network here, // for manual configuration: -IPAddress ip(10,0,1,20); +IPAddress ip(10, 0, 1, 20); // initialize the library instance: EthernetClient client; @@ -51,14 +52,14 @@ char server[] = "api.cosm.com"; // name address for cosm API unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds boolean lastConnected = false; // state of the connection last time through the main loop -const unsigned long postingInterval = 10L*1000L; // delay between updates to cosm.com - // the "L" is needed to use long type numbers +const unsigned long postingInterval = 10L * 1000L; // delay between updates to cosm.com +// the "L" is needed to use long type numbers void setup() { // start serial port: Serial.begin(9600); - // start the Ethernet connection: + // start the Ethernet connection: if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); // DHCP failed, so use a fixed IP address: @@ -68,7 +69,7 @@ void setup() { void loop() { // read the analog sensor: - int sensorReading = analogRead(A0); + int sensorReading = analogRead(A0); // if there's incoming data from the net connection. // send it out the serial port. This is for debugging @@ -88,7 +89,7 @@ void loop() { // if you're not connected, and ten seconds have passed since // your last connection, then connect again and send data: - if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) { + if (!client.connected() && (millis() - lastConnectionTime > postingInterval)) { sendData(sensorReading); } // store the state of the connection for next time through @@ -125,8 +126,8 @@ void sendData(int thisData) { // here's the actual content of the PUT request: client.print("sensor1,"); client.println(thisData); - - } + + } else { // if you couldn't make a connection: Serial.println("connection failed"); @@ -134,7 +135,7 @@ void sendData(int thisData) { Serial.println("disconnecting."); client.stop(); } - // note the time that the connection was made or attempted: + // note the time that the connection was made or attempted: lastConnectionTime = millis(); } @@ -147,12 +148,12 @@ void sendData(int thisData) { int getLength(int someValue) { // there's at least one byte: int digits = 1; - // continually divide the value by ten, + // continually divide the value by ten, // adding one to the digit count for each // time you divide, until you're at 0: - int dividend = someValue /10; + int dividend = someValue / 10; while (dividend > 0) { - dividend = dividend /10; + dividend = dividend / 10; digits++; } // return the number of digits: diff --git a/libraries/Ethernet/examples/CosmClientString/CosmClientString.ino b/libraries/Ethernet/examples/CosmClientString/CosmClientString.ino index e61992467..22a6b3ff4 100644 --- a/libraries/Ethernet/examples/CosmClientString/CosmClientString.ino +++ b/libraries/Ethernet/examples/CosmClientString/CosmClientString.ino @@ -1,29 +1,29 @@ /* Cosm sensor client with Strings - + This sketch connects an analog sensor to Cosm (http://www.cosm.com) using a Wiznet Ethernet shield. You can use the Arduino Ethernet shield, or the Adafruit Ethernet shield, either one will work, as long as it's got a Wiznet Ethernet module on board. - - This example has been updated to use version 2.0 of the Cosm.com API. + + This example has been updated to use version 2.0 of the Cosm.com API. To make it work, create a feed with two datastreams, and give them the IDs sensor1 and sensor2. Or change the code below to match your feed. - + This example uses the String library, which is part of the Arduino core from - version 0019. - + version 0019. + Circuit: * Analog sensor attached to analog in 0 * Ethernet shield attached to pins 10, 11, 12, 13 - + created 15 March 2010 updated 14 May 2012 by Tom Igoe with input from Usman Haque and Joe Saavedra - + http://arduino.cc/en/Tutorial/CosmClientString This code is in the public domain. - + */ #include @@ -36,12 +36,13 @@ // assign a MAC address for the ethernet controller. // fill in your address here: - byte mac[] = { - 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; - +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; + // fill in an available IP address on your network here, // for manual configuration: -IPAddress ip(10,0,1,20); +IPAddress ip(10, 0, 1, 20); // initialize the library instance: EthernetClient client; @@ -53,8 +54,8 @@ char server[] = "api.cosm.com"; // name address for Cosm API unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds boolean lastConnected = false; // state of the connection last time through the main loop -const unsigned long postingInterval = 10L*1000L; // delay between updates to Cosm.com - // the "L" is needed to use long type numbers +const unsigned long postingInterval = 10L * 1000L; // delay between updates to Cosm.com +// the "L" is needed to use long type numbers void setup() { // start serial port: Serial.begin(9600); @@ -70,7 +71,7 @@ void setup() { void loop() { // read the analog sensor: - int sensorReading = analogRead(A0); + int sensorReading = analogRead(A0); // convert the data to a String to send it: String dataString = "sensor1,"; @@ -99,8 +100,8 @@ void loop() { } // if you're not connected, and ten seconds have passed since - // your last connection, then connect again and send data: - if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) { + // your last connection, then connect again and send data: + if (!client.connected() && (millis() - lastConnectionTime > postingInterval)) { sendData(dataString); } // store the state of the connection for next time through @@ -132,7 +133,7 @@ void sendData(String thisData) { // here's the actual content of the PUT request: client.println(thisData); - } + } else { // if you couldn't make a connection: Serial.println("connection failed"); diff --git a/libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino b/libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino index 5eaaf24d1..a41b77403 100644 --- a/libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino +++ b/libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino @@ -1,17 +1,17 @@ /* DHCP-based IP printer - + This sketch uses the DHCP extensions to the Ethernet library to get an IP address via DHCP and print the address obtained. - using an Arduino Wiznet Ethernet shield. - + using an Arduino Wiznet Ethernet shield. + Circuit: * Ethernet shield attached to pins 10, 11, 12, 13 - + created 12 April 2011 modified 9 Apr 2012 by Tom Igoe - + */ #include @@ -19,19 +19,20 @@ // Enter a MAC address for your controller below. // Newer Ethernet shields have a MAC address printed on a sticker on the shield -byte mac[] = { - 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 }; +byte mac[] = { + 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 +}; // Initialize the Ethernet client library -// with the IP address and port of the server +// with the IP address and port of the server // that you want to connect to (port 80 is default for HTTP): EthernetClient client; void setup() { - // Open serial communications and wait for port to open: + // Open serial communications and wait for port to open: Serial.begin(9600); // this check is only needed on the Leonardo: - while (!Serial) { + while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } @@ -39,7 +40,7 @@ void setup() { if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); // no point in carrying on, so do nothing forevermore: - for(;;) + for (;;) ; } // print your local IP address: @@ -47,7 +48,7 @@ void setup() { for (byte thisByte = 0; thisByte < 4; thisByte++) { // print the value of each byte of the IP address: Serial.print(Ethernet.localIP()[thisByte], DEC); - Serial.print("."); + Serial.print("."); } Serial.println(); } diff --git a/libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino b/libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino index 09cbd4354..73cde4bbb 100644 --- a/libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino +++ b/libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino @@ -1,21 +1,21 @@ /* DHCP Chat Server - + A simple server that distributes any incoming messages to all connected clients. To use telnet to your device's IP address and type. You can see the client's input in the serial monitor as well. - Using an Arduino Wiznet Ethernet shield. - + Using an Arduino Wiznet Ethernet shield. + THis version attempts to get an IP address using DHCP - + Circuit: * Ethernet shield attached to pins 10, 11, 12, 13 - + created 21 May 2011 modified 9 Apr 2012 by Tom Igoe Based on ChatServer example by David A. Mellis - + */ #include @@ -24,10 +24,11 @@ // Enter a MAC address and IP address for your controller below. // The IP address will be dependent on your local network. // gateway and subnet are optional: -byte mac[] = { - 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 }; -IPAddress ip(192,168,1, 177); -IPAddress gateway(192,168,1, 1); +byte mac[] = { + 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 +}; +IPAddress ip(192, 168, 1, 177); +IPAddress gateway(192, 168, 1, 1); IPAddress subnet(255, 255, 0, 0); // telnet defaults to port 23 @@ -38,7 +39,7 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); // this check is only needed on the Leonardo: - while (!Serial) { + while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } @@ -56,12 +57,12 @@ void setup() { for (byte thisByte = 0; thisByte < 4; thisByte++) { // print the value of each byte of the IP address: Serial.print(ip[thisByte], DEC); - Serial.print("."); + Serial.print("."); } Serial.println(); // start listening for clients server.begin(); - + } void loop() { @@ -72,7 +73,7 @@ void loop() { if (client) { if (!gotAMessage) { Serial.println("We have a new client"); - client.println("Hello, client!"); + client.println("Hello, client!"); gotAMessage = true; } diff --git a/libraries/Ethernet/examples/PachubeClient/PachubeClient.ino b/libraries/Ethernet/examples/PachubeClient/PachubeClient.ino index dfd2d4010..989802523 100644 --- a/libraries/Ethernet/examples/PachubeClient/PachubeClient.ino +++ b/libraries/Ethernet/examples/PachubeClient/PachubeClient.ino @@ -1,27 +1,27 @@ /* Pachube sensor client - + This sketch connects an analog sensor to Pachube (http://www.pachube.com) using a Wiznet Ethernet shield. You can use the Arduino Ethernet shield, or the Adafruit Ethernet shield, either one will work, as long as it's got a Wiznet Ethernet module on board. - - This example has been updated to use version 2.0 of the Pachube.com API. + + This example has been updated to use version 2.0 of the Pachube.com API. To make it work, create a feed with a datastream, and give it the ID sensor1. Or change the code below to match your feed. - - + + Circuit: * Analog sensor attached to analog in 0 * Ethernet shield attached to pins 10, 11, 12, 13 - + created 15 March 2010 modified 9 Apr 2012 by Tom Igoe with input from Usman Haque and Joe Saavedra - + http://arduino.cc/en/Tutorial/PachubeClient This code is in the public domain. - + */ #include @@ -34,33 +34,34 @@ http://arduino.cc/en/Tutorial/PachubeClient // assign a MAC address for the ethernet controller. // Newer Ethernet shields have a MAC address printed on a sticker on the shield // fill in your address here: -byte mac[] = { - 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; // fill in an available IP address on your network here, // for manual configuration: -IPAddress ip(10,0,1,20); +IPAddress ip(10, 0, 1, 20); // initialize the library instance: EthernetClient client; // if you don't want to use DNS (and reduce your sketch size) // use the numeric IP instead of the name for the server: -IPAddress server(216,52,233,122); // numeric IP for api.pachube.com +IPAddress server(216, 52, 233, 122); // numeric IP for api.pachube.com //char server[] = "api.pachube.com"; // name address for pachube API unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds boolean lastConnected = false; // state of the connection last time through the main loop -const unsigned long postingInterval = 10*1000; //delay between updates to Pachube.com +const unsigned long postingInterval = 10 * 1000; //delay between updates to Pachube.com void setup() { - // Open serial communications and wait for port to open: + // Open serial communications and wait for port to open: Serial.begin(9600); - while (!Serial) { + while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } - // start the Ethernet connection: + // start the Ethernet connection: if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); // DHCP failed, so use a fixed IP address: @@ -70,7 +71,7 @@ void setup() { void loop() { // read the analog sensor: - int sensorReading = analogRead(A0); + int sensorReading = analogRead(A0); // if there's incoming data from the net connection. // send it out the serial port. This is for debugging @@ -90,7 +91,7 @@ void loop() { // if you're not connected, and ten seconds have passed since // your last connection, then connect again and send data: - if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) { + if (!client.connected() && (millis() - lastConnectionTime > postingInterval)) { sendData(sensorReading); } // store the state of the connection for next time through @@ -127,8 +128,8 @@ void sendData(int thisData) { // here's the actual content of the PUT request: client.print("sensor1,"); client.println(thisData); - - } + + } else { // if you couldn't make a connection: Serial.println("connection failed"); @@ -136,7 +137,7 @@ void sendData(int thisData) { Serial.println("disconnecting."); client.stop(); } - // note the time that the connection was made or attempted: + // note the time that the connection was made or attempted: lastConnectionTime = millis(); } @@ -149,12 +150,12 @@ void sendData(int thisData) { int getLength(int someValue) { // there's at least one byte: int digits = 1; - // continually divide the value by ten, + // continually divide the value by ten, // adding one to the digit count for each // time you divide, until you're at 0: - int dividend = someValue /10; + int dividend = someValue / 10; while (dividend > 0) { - dividend = dividend /10; + dividend = dividend / 10; digits++; } // return the number of digits: diff --git a/libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino b/libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino index e5c55edc3..bd961825d 100644 --- a/libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino +++ b/libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino @@ -1,29 +1,29 @@ /* Cosm sensor client with Strings - + This sketch connects an analog sensor to Cosm (http://www.cosm.com) using a Wiznet Ethernet shield. You can use the Arduino Ethernet shield, or the Adafruit Ethernet shield, either one will work, as long as it's got a Wiznet Ethernet module on board. - - This example has been updated to use version 2.0 of the Cosm.com API. + + This example has been updated to use version 2.0 of the Cosm.com API. To make it work, create a feed with two datastreams, and give them the IDs sensor1 and sensor2. Or change the code below to match your feed. - + This example uses the String library, which is part of the Arduino core from - version 0019. - + version 0019. + Circuit: * Analog sensor attached to analog in 0 * Ethernet shield attached to pins 10, 11, 12, 13 - + created 15 March 2010 modified 9 Apr 2012 by Tom Igoe with input from Usman Haque and Joe Saavedra - + http://arduino.cc/en/Tutorial/CosmClientString This code is in the public domain. - + */ #include @@ -37,27 +37,28 @@ // assign a MAC address for the ethernet controller. // fill in your address here: - byte mac[] = { - 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; // fill in an available IP address on your network here, // for manual configuration: -IPAddress ip(10,0,1,20); +IPAddress ip(10, 0, 1, 20); // initialize the library instance: EthernetClient client; // if you don't want to use DNS (and reduce your sketch size) // use the numeric IP instead of the name for the server: -IPAddress server(216,52,233,121); // numeric IP for api.cosm.com +IPAddress server(216, 52, 233, 121); // numeric IP for api.cosm.com //char server[] = "api.cosm.com"; // name address for Cosm API unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds boolean lastConnected = false; // state of the connection last time through the main loop -const unsigned long postingInterval = 10*1000; //delay between updates to Cosm.com +const unsigned long postingInterval = 10 * 1000; //delay between updates to Cosm.com void setup() { - // Open serial communications and wait for port to open: + // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only @@ -76,7 +77,7 @@ void setup() { void loop() { // read the analog sensor: - int sensorReading = analogRead(A0); + int sensorReading = analogRead(A0); // convert the data to a String to send it: String dataString = "sensor1,"; @@ -105,8 +106,8 @@ void loop() { } // if you're not connected, and ten seconds have passed since - // your last connection, then connect again and send data: - if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) { + // your last connection, then connect again and send data: + if (!client.connected() && (millis() - lastConnectionTime > postingInterval)) { sendData(dataString); } // store the state of the connection for next time through @@ -138,7 +139,7 @@ void sendData(String thisData) { // here's the actual content of the PUT request: client.println(thisData); - } + } else { // if you couldn't make a connection: Serial.println("connection failed"); diff --git a/libraries/Ethernet/examples/TelnetClient/TelnetClient.ino b/libraries/Ethernet/examples/TelnetClient/TelnetClient.ino index 345712564..dcf3e8aa9 100644 --- a/libraries/Ethernet/examples/TelnetClient/TelnetClient.ino +++ b/libraries/Ethernet/examples/TelnetClient/TelnetClient.ino @@ -1,21 +1,21 @@ /* Telnet client - + This sketch connects to a a telnet server (http://www.google.com) - using an Arduino Wiznet Ethernet shield. You'll need a telnet server + using an Arduino Wiznet Ethernet shield. You'll need a telnet server to test this with. - Processing's ChatServer example (part of the network library) works well, + Processing's ChatServer example (part of the network library) works well, running on port 10002. It can be found as part of the examples - in the Processing application, available at + in the Processing application, available at http://processing.org/ - + Circuit: * Ethernet shield attached to pins 10, 11, 12, 13 - + created 14 Sep 2010 modified 9 Apr 2012 by Tom Igoe - + */ #include @@ -23,15 +23,16 @@ // Enter a MAC address and IP address for your controller below. // The IP address will be dependent on your local network: -byte mac[] = { - 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; -IPAddress ip(192,168,1,177); +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; +IPAddress ip(192, 168, 1, 177); // Enter the IP address of the server you're connecting to: -IPAddress server(1,1,1,1); +IPAddress server(1, 1, 1, 1); // Initialize the Ethernet client library -// with the IP address and port of the server +// with the IP address and port of the server // that you want to connect to (port 23 is default for telnet; // if you're using Processing's ChatServer, use port 10002): EthernetClient client; @@ -39,9 +40,9 @@ EthernetClient client; void setup() { // start the Ethernet connection: Ethernet.begin(mac, ip); - // Open serial communications and wait for port to open: + // Open serial communications and wait for port to open: Serial.begin(9600); - while (!Serial) { + while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } @@ -53,7 +54,7 @@ void setup() { // if you get a connection, report back via serial: if (client.connect(server, 10002)) { Serial.println("connected"); - } + } else { // if you didn't get a connection to the server: Serial.println("connection failed"); @@ -62,7 +63,7 @@ void setup() { void loop() { - // if there are incoming bytes available + // if there are incoming bytes available // from the server, read them and print them: if (client.available()) { char c = client.read(); @@ -74,7 +75,7 @@ void loop() while (Serial.available() > 0) { char inChar = Serial.read(); if (client.connected()) { - client.print(inChar); + client.print(inChar); } } @@ -84,7 +85,7 @@ void loop() Serial.println("disconnecting."); client.stop(); // do nothing: - while(true); + while (true); } } diff --git a/libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino b/libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino index 4d4045cac..99de7650c 100644 --- a/libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino +++ b/libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino @@ -2,13 +2,13 @@ UDPSendReceive.pde: This sketch receives UDP message strings, prints them to the serial port and sends an "acknowledge" string back to the sender - - A Processing sketch is included at the end of file that can be used to send + + A Processing sketch is included at the end of file that can be used to send and received messages for testing with a computer. - + created 21 Aug 2010 by Michael Margolis - + This code is in the public domain. */ @@ -20,8 +20,9 @@ // Enter a MAC address and IP address for your controller below. // The IP address will be dependent on your local network: -byte mac[] = { - 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; IPAddress ip(192, 168, 1, 177); unsigned int localPort = 8888; // local port to listen on @@ -35,7 +36,7 @@ EthernetUDP Udp; void setup() { // start the Ethernet and UDP: - Ethernet.begin(mac,ip); + Ethernet.begin(mac, ip); Udp.begin(localPort); Serial.begin(9600); @@ -44,13 +45,13 @@ void setup() { void loop() { // if there's data available, read a packet int packetSize = Udp.parsePacket(); - if(packetSize) + if (packetSize) { Serial.print("Received packet of size "); Serial.println(packetSize); Serial.print("From "); IPAddress remote = Udp.remoteIP(); - for (int i =0; i < 4; i++) + for (int i = 0; i < 4; i++) { Serial.print(remote[i], DEC); if (i < 3) @@ -62,7 +63,7 @@ void loop() { Serial.println(Udp.remotePort()); // read the packet into packetBufffer - Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE); + Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE); Serial.println("Contents:"); Serial.println(packetBuffer); @@ -78,40 +79,40 @@ void loop() { /* Processing sketch to run with this example ===================================================== - - // Processing UDP example to send and receive string data from Arduino + + // Processing UDP example to send and receive string data from Arduino // press any key to send the "Hello Arduino" message - - + + import hypermedia.net.*; - + UDP udp; // define the UDP object - - + + void setup() { udp = new UDP( this, 6000 ); // create a new datagram connection on port 6000 //udp.log( true ); // <-- printout the connection activity - udp.listen( true ); // and wait for incoming message + udp.listen( true ); // and wait for incoming message } - + void draw() { } - + void keyPressed() { String ip = "192.168.1.177"; // the remote IP address int port = 8888; // the destination port - + udp.send("Hello World", ip, port ); // the message to send - + } - + void receive( byte[] data ) { // <-- default handler //void receive( byte[] data, String ip, int port ) { // <-- extended handler - - for(int i=0; i < data.length; i++) - print(char(data[i])); - println(); + + for(int i=0; i < data.length; i++) + print(char(data[i])); + println(); } */ diff --git a/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino b/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino index 93ffe3991..203bb8d5d 100644 --- a/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino +++ b/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino @@ -1,46 +1,47 @@ /* Udp NTP Client - + Get the time from a Network Time Protocol (NTP) time server - Demonstrates use of UDP sendPacket and ReceivePacket - For more on NTP time servers and the messages needed to communicate with them, + Demonstrates use of UDP sendPacket and ReceivePacket + For more on NTP time servers and the messages needed to communicate with them, see http://en.wikipedia.org/wiki/Network_Time_Protocol - - created 4 Sep 2010 + + created 4 Sep 2010 by Michael Margolis modified 9 Apr 2012 by Tom Igoe - + This code is in the public domain. */ -#include +#include #include #include // Enter a MAC address for your controller below. // Newer Ethernet shields have a MAC address printed on a sticker on the shield -byte mac[] = { - 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; unsigned int localPort = 8888; // local port to listen for UDP packets IPAddress timeServer(192, 43, 244, 18); // time.nist.gov NTP server -const int NTP_PACKET_SIZE= 48; // NTP time stamp is in the first 48 bytes of the message +const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message -byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets +byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets // A UDP instance to let us send and receive packets over UDP EthernetUDP Udp; -void setup() +void setup() { - // Open serial communications and wait for port to open: + // Open serial communications and wait for port to open: Serial.begin(9600); - while (!Serial) { + while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } @@ -49,7 +50,7 @@ void setup() if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); // no point in carrying on, so do nothing forevermore: - for(;;) + for (;;) ; } Udp.begin(localPort); @@ -59,58 +60,58 @@ void loop() { sendNTPpacket(timeServer); // send an NTP packet to a time server - // wait to see if a reply is available - delay(1000); - if ( Udp.parsePacket() ) { + // wait to see if a reply is available + delay(1000); + if ( Udp.parsePacket() ) { // We've received a packet, read the data from it - Udp.read(packetBuffer,NTP_PACKET_SIZE); // read the packet into the buffer + Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer //the timestamp starts at byte 40 of the received packet and is four bytes, // or two words, long. First, esxtract the two words: unsigned long highWord = word(packetBuffer[40], packetBuffer[41]); - unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); + unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); // combine the four bytes (two words) into a long integer // this is NTP time (seconds since Jan 1 1900): - unsigned long secsSince1900 = highWord << 16 | lowWord; + unsigned long secsSince1900 = highWord << 16 | lowWord; Serial.print("Seconds since Jan 1 1900 = " ); - Serial.println(secsSince1900); + Serial.println(secsSince1900); // now convert NTP time into everyday time: Serial.print("Unix time = "); // Unix time starts on Jan 1 1970. In seconds, that's 2208988800: - const unsigned long seventyYears = 2208988800UL; + const unsigned long seventyYears = 2208988800UL; // subtract seventy years: - unsigned long epoch = secsSince1900 - seventyYears; + unsigned long epoch = secsSince1900 - seventyYears; // print Unix time: - Serial.println(epoch); + Serial.println(epoch); // print the hour, minute and second: Serial.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT) Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day) - Serial.print(':'); + Serial.print(':'); if ( ((epoch % 3600) / 60) < 10 ) { // In the first 10 minutes of each hour, we'll want a leading '0' Serial.print('0'); } Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute) - Serial.print(':'); + Serial.print(':'); if ( (epoch % 60) < 10 ) { // In the first 10 seconds of each minute, we'll want a leading '0' Serial.print('0'); } - Serial.println(epoch %60); // print the second + Serial.println(epoch % 60); // print the second } // wait ten seconds before asking for the time again - delay(10000); + delay(10000); } -// send an NTP request to the time server at the given address +// send an NTP request to the time server at the given address unsigned long sendNTPpacket(IPAddress& address) { // set all bytes in the buffer to 0 - memset(packetBuffer, 0, NTP_PACKET_SIZE); + memset(packetBuffer, 0, NTP_PACKET_SIZE); // Initialize values needed to form NTP request // (see URL above for details on the packets) packetBuffer[0] = 0b11100011; // LI, Version, Mode @@ -118,16 +119,16 @@ unsigned long sendNTPpacket(IPAddress& address) packetBuffer[2] = 6; // Polling Interval packetBuffer[3] = 0xEC; // Peer Clock Precision // 8 bytes of zero for Root Delay & Root Dispersion - packetBuffer[12] = 49; + packetBuffer[12] = 49; packetBuffer[13] = 0x4E; packetBuffer[14] = 49; packetBuffer[15] = 52; // all NTP fields have been given values, now - // you can send a packet requesting a timestamp: + // you can send a packet requesting a timestamp: Udp.beginPacket(address, 123); //NTP requests are to port 123 - Udp.write(packetBuffer,NTP_PACKET_SIZE); - Udp.endPacket(); + Udp.write(packetBuffer, NTP_PACKET_SIZE); + Udp.endPacket(); } diff --git a/libraries/Ethernet/examples/WebClient/WebClient.ino b/libraries/Ethernet/examples/WebClient/WebClient.ino index 40523a4d9..9afd40eae 100644 --- a/libraries/Ethernet/examples/WebClient/WebClient.ino +++ b/libraries/Ethernet/examples/WebClient/WebClient.ino @@ -1,17 +1,17 @@ /* Web client - + This sketch connects to a website (http://www.google.com) - using an Arduino Wiznet Ethernet shield. - + using an Arduino Wiznet Ethernet shield. + Circuit: * Ethernet shield attached to pins 10, 11, 12, 13 - + created 18 Dec 2009 by David A. Mellis modified 9 Apr 2012 by Tom Igoe, based on work by Adrian McEwen - + */ #include @@ -26,17 +26,17 @@ byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; char server[] = "www.google.com"; // name address for Google (using DNS) // Set the static IP address to use if the DHCP fails to assign -IPAddress ip(192,168,0,177); +IPAddress ip(192, 168, 0, 177); // Initialize the Ethernet client library -// with the IP address and port of the server +// with the IP address and port of the server // that you want to connect to (port 80 is default for HTTP): EthernetClient client; void setup() { - // Open serial communications and wait for port to open: + // Open serial communications and wait for port to open: Serial.begin(9600); - while (!Serial) { + while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } @@ -59,7 +59,7 @@ void setup() { client.println("Host: www.google.com"); client.println("Connection: close"); client.println(); - } + } else { // kf you didn't get a connection to the server: Serial.println("connection failed"); @@ -68,7 +68,7 @@ void setup() { void loop() { - // if there are incoming bytes available + // if there are incoming bytes available // from the server, read them and print them: if (client.available()) { char c = client.read(); @@ -82,7 +82,7 @@ void loop() client.stop(); // do nothing forevermore: - while(true); + while (true); } } diff --git a/libraries/Ethernet/examples/WebClientRepeating/WebClientRepeating.ino b/libraries/Ethernet/examples/WebClientRepeating/WebClientRepeating.ino index 650f74efd..f21541bf7 100644 --- a/libraries/Ethernet/examples/WebClientRepeating/WebClientRepeating.ino +++ b/libraries/Ethernet/examples/WebClientRepeating/WebClientRepeating.ino @@ -1,23 +1,23 @@ /* Repeating Web client - + This sketch connects to a a web server and makes a request using a Wiznet Ethernet shield. You can use the Arduino Ethernet shield, or the Adafruit Ethernet shield, either one will work, as long as it's got a Wiznet Ethernet module on board. - + This example uses DNS, by assigning the Ethernet client with a MAC address, IP address, and DNS address. - + Circuit: * Ethernet shield attached to pins 10, 11, 12, 13 - + created 19 Apr 2012 by Tom Igoe - + http://arduino.cc/en/Tutorial/WebClientRepeating This code is in the public domain. - + */ #include @@ -25,14 +25,15 @@ // assign a MAC address for the ethernet controller. // fill in your address here: -byte mac[] = { - 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; // fill in an available IP address on your network here, // for manual configuration: -IPAddress ip(10,0,0,20); +IPAddress ip(10, 0, 0, 20); // fill in your Domain Name Server address here: -IPAddress myDns(1,1,1,1); +IPAddress myDns(1, 1, 1, 1); // initialize the library instance: EthernetClient client; @@ -41,8 +42,8 @@ char server[] = "www.arduino.cc"; unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds boolean lastConnected = false; // state of the connection last time through the main loop -const unsigned long postingInterval = 60L*1000L; // delay between updates, in milliseconds - // the "L" is needed to use long type numbers +const unsigned long postingInterval = 60L * 1000L; // delay between updates, in milliseconds +// the "L" is needed to use long type numbers void setup() { // start serial port: @@ -75,7 +76,7 @@ void loop() { // if you're not connected, and ten seconds have passed since // your last connection, then connect again and send data: - if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) { + if (!client.connected() && (millis() - lastConnectionTime > postingInterval)) { httpRequest(); } // store the state of the connection for next time through @@ -97,7 +98,7 @@ void httpRequest() { // note the time that the connection was made: lastConnectionTime = millis(); - } + } else { // if you couldn't make a connection: Serial.println("connection failed"); diff --git a/libraries/Ethernet/examples/WebServer/WebServer.ino b/libraries/Ethernet/examples/WebServer/WebServer.ino index 689eb7d39..d0c585d07 100644 --- a/libraries/Ethernet/examples/WebServer/WebServer.ino +++ b/libraries/Ethernet/examples/WebServer/WebServer.ino @@ -1,18 +1,18 @@ /* Web Server - + A simple web server that shows the value of the analog input pins. - using an Arduino Wiznet Ethernet shield. - + using an Arduino Wiznet Ethernet shield. + Circuit: * Ethernet shield attached to pins 10, 11, 12, 13 * Analog inputs attached to pins A0 through A5 (optional) - + created 18 Dec 2009 by David A. Mellis modified 9 Apr 2012 by Tom Igoe - + */ #include @@ -20,19 +20,20 @@ // Enter a MAC address and IP address for your controller below. // The IP address will be dependent on your local network: -byte mac[] = { - 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; -IPAddress ip(192,168,1,177); +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; +IPAddress ip(192, 168, 1, 177); // Initialize the Ethernet server library -// with the IP address and port you want to use +// with the IP address and port you want to use // (port 80 is default for HTTP): EthernetServer server(80); void setup() { - // Open serial communications and wait for port to open: + // Open serial communications and wait for port to open: Serial.begin(9600); - while (!Serial) { + while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } @@ -64,7 +65,7 @@ void loop() { client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("Connection: close"); // the connection will be closed after completion of the response - client.println("Refresh: 5"); // refresh the page automatically every 5 sec + client.println("Refresh: 5"); // refresh the page automatically every 5 sec client.println(); client.println(""); client.println(""); @@ -75,7 +76,7 @@ void loop() { client.print(analogChannel); client.print(" is "); client.print(sensorReading); - client.println("
"); + client.println("
"); } client.println(""); break; @@ -83,7 +84,7 @@ void loop() { if (c == '\n') { // you're starting a new line currentLineIsBlank = true; - } + } else if (c != '\r') { // you've gotten a character on the current line currentLineIsBlank = false; diff --git a/libraries/Firmata/examples/AllInputsFirmata/AllInputsFirmata.ino b/libraries/Firmata/examples/AllInputsFirmata/AllInputsFirmata.ino index bff736699..cfe44820a 100644 --- a/libraries/Firmata/examples/AllInputsFirmata/AllInputsFirmata.ino +++ b/libraries/Firmata/examples/AllInputsFirmata/AllInputsFirmata.ino @@ -9,7 +9,7 @@ * http://firmata.org/wiki/Download */ -/* +/* * This firmware reads all inputs and sends them as fast as it can. It was * inspired by the ease-of-use of the Arduino2Max program. * @@ -35,7 +35,7 @@ int samplingInterval = 19; // how often to run the main loop (in ms) void sendPort(byte portNumber, byte portValue) { portValue = portValue & portStatus[portNumber]; - if(previousPINs[portNumber] != portValue) { + if (previousPINs[portNumber] != portValue) { Firmata.sendDigitalPort(portNumber, portValue); previousPINs[portNumber] = portValue; } @@ -47,13 +47,13 @@ void setup() Firmata.setFirmwareVersion(0, 1); - for(pin = 0; pin < TOTAL_PINS; pin++) { + for (pin = 0; pin < TOTAL_PINS; pin++) { if IS_PIN_DIGITAL(pin) pinMode(PIN_TO_DIGITAL(pin), INPUT); } - for (port=0; port samplingInterval) { + if (currentMillis - previousMillis > samplingInterval) { previousMillis += samplingInterval; - while(Firmata.available()) { + while (Firmata.available()) { Firmata.processInput(); } - for(pin = 0; pin < TOTAL_ANALOG_PINS; pin++) { + for (pin = 0; pin < TOTAL_ANALOG_PINS; pin++) { analogValue = analogRead(pin); - if(analogValue != previousAnalogValues[pin]) { - Firmata.sendAnalog(pin, analogValue); + if (analogValue != previousAnalogValues[pin]) { + Firmata.sendAnalog(pin, analogValue); previousAnalogValues[pin] = analogValue; } } diff --git a/libraries/Firmata/examples/AnalogFirmata/AnalogFirmata.ino b/libraries/Firmata/examples/AnalogFirmata/AnalogFirmata.ino index ff1d664b8..8c4d9cd49 100644 --- a/libraries/Firmata/examples/AnalogFirmata/AnalogFirmata.ino +++ b/libraries/Firmata/examples/AnalogFirmata/AnalogFirmata.ino @@ -32,63 +32,63 @@ unsigned long previousMillis; // for comparison with currentMillis /*============================================================================== - * FUNCTIONS + * FUNCTIONS *============================================================================*/ void analogWriteCallback(byte pin, int value) { - switch(pin) { + switch (pin) { case 9: servo9.write(value); break; case 10: servo10.write(value); break; - case 3: - case 5: - case 6: + case 3: + case 5: + case 6: case 11: // PWM pins - analogWrite(pin, value); - break; - } + analogWrite(pin, value); + break; + } } // ----------------------------------------------------------------------------- // sets bits in a bit array (int) to toggle the reporting of the analogIns void reportAnalogCallback(byte pin, int value) { - if(value == 0) { - analogInputsToReport = analogInputsToReport &~ (1 << pin); - } - else { // everything but 0 enables reporting of that pin - analogInputsToReport = analogInputsToReport | (1 << pin); - } - // TODO: save status to EEPROM here, if changed + if (value == 0) { + analogInputsToReport = analogInputsToReport &~ (1 << pin); + } + else { // everything but 0 enables reporting of that pin + analogInputsToReport = analogInputsToReport | (1 << pin); + } + // TODO: save status to EEPROM here, if changed } /*============================================================================== * SETUP() *============================================================================*/ -void setup() +void setup() { - Firmata.setFirmwareVersion(0, 2); - Firmata.attach(ANALOG_MESSAGE, analogWriteCallback); - Firmata.attach(REPORT_ANALOG, reportAnalogCallback); + Firmata.setFirmwareVersion(0, 2); + Firmata.attach(ANALOG_MESSAGE, analogWriteCallback); + Firmata.attach(REPORT_ANALOG, reportAnalogCallback); - servo9.attach(9); - servo10.attach(10); - Firmata.begin(57600); + servo9.attach(9); + servo10.attach(10); + Firmata.begin(57600); } /*============================================================================== * LOOP() *============================================================================*/ -void loop() +void loop() { - while(Firmata.available()) - Firmata.processInput(); - currentMillis = millis(); - if(currentMillis - previousMillis > 20) { - previousMillis += 20; // run this every 20ms - for(analogPin=0;analogPin 20) { + previousMillis += 20; // run this every 20ms + for (analogPin = 0; analogPin < TOTAL_ANALOG_PINS; analogPin++) { + if ( analogInputsToReport & (1 << analogPin) ) + Firmata.sendAnalog(analogPin, analogRead(analogPin)); } + } } diff --git a/libraries/Firmata/examples/EchoString/EchoString.ino b/libraries/Firmata/examples/EchoString/EchoString.ino index f8b9aac5b..eea909587 100644 --- a/libraries/Firmata/examples/EchoString/EchoString.ino +++ b/libraries/Firmata/examples/EchoString/EchoString.ino @@ -17,28 +17,28 @@ void stringCallback(char *myString) { - Firmata.sendString(myString); + Firmata.sendString(myString); } void sysexCallback(byte command, byte argc, byte*argv) { - Firmata.sendSysex(command, argc, argv); + Firmata.sendSysex(command, argc, argv); } void setup() { - Firmata.setFirmwareVersion(0, 1); - Firmata.attach(STRING_DATA, stringCallback); - Firmata.attach(START_SYSEX, sysexCallback); - Firmata.begin(57600); + Firmata.setFirmwareVersion(0, 1); + Firmata.attach(STRING_DATA, stringCallback); + Firmata.attach(START_SYSEX, sysexCallback); + Firmata.begin(57600); } void loop() { - while(Firmata.available()) { - Firmata.processInput(); - } + while (Firmata.available()) { + Firmata.processInput(); + } } diff --git a/libraries/Firmata/examples/OldStandardFirmata/OldStandardFirmata.ino b/libraries/Firmata/examples/OldStandardFirmata/OldStandardFirmata.ino index d306c70d7..761f38880 100644 --- a/libraries/Firmata/examples/OldStandardFirmata/OldStandardFirmata.ino +++ b/libraries/Firmata/examples/OldStandardFirmata/OldStandardFirmata.ino @@ -11,16 +11,16 @@ /* Copyright (C) 2006-2008 Hans-Christoph Steiner. All rights reserved. - + This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + See file LICENSE.txt for further informations on licensing terms. */ -/* +/* * This is an old version of StandardFirmata (v2.0). It is kept here because * its the last version that works on an ATMEGA8 chip. Also, it can be used * for host software that has not been updated to a newer version of the @@ -50,34 +50,34 @@ unsigned long previousMillis; // for comparison with currentMillis /*============================================================================== - * FUNCTIONS + * FUNCTIONS *============================================================================*/ void outputPort(byte portNumber, byte portValue) { portValue = portValue &~ portStatus[portNumber]; - if(previousPINs[portNumber] != portValue) { - Firmata.sendDigitalPort(portNumber, portValue); - previousPINs[portNumber] = portValue; - Firmata.sendDigitalPort(portNumber, portValue); - } + if (previousPINs[portNumber] != portValue) { + Firmata.sendDigitalPort(portNumber, portValue); + previousPINs[portNumber] = portValue; + Firmata.sendDigitalPort(portNumber, portValue); + } } /* ----------------------------------------------------------------------------- * check all the active digital inputs for change of state, then add any events * to the Serial output queue using Serial.print() */ -void checkDigitalInputs(void) +void checkDigitalInputs(void) { - byte i, tmp; - for(i=0; i < TOTAL_PORTS; i++) { - if(reportPINs[i]) { - switch(i) { - case 0: outputPort(0, PIND &~ B00000011); break; // ignore Rx/Tx 0/1 - case 1: outputPort(1, PINB); break; - case 2: outputPort(2, PINC); break; - } - } + byte i, tmp; + for (i = 0; i < TOTAL_PORTS; i++) { + if (reportPINs[i]) { + switch (i) { + case 0: outputPort(0, PIND &~ B00000011); break; // ignore Rx/Tx 0/1 + case 1: outputPort(1, PINB); break; + case 2: outputPort(2, PINC); break; + } } + } } // ----------------------------------------------------------------------------- @@ -85,61 +85,61 @@ void checkDigitalInputs(void) * two bit-arrays that track Digital I/O and PWM status */ void setPinModeCallback(byte pin, int mode) { - byte port = 0; - byte offset = 0; + byte port = 0; + byte offset = 0; - if (pin < 8) { - port = 0; - offset = 0; - } else if (pin < 14) { - port = 1; - offset = 8; - } else if (pin < 22) { - port = 2; - offset = 14; - } + if (pin < 8) { + port = 0; + offset = 0; + } else if (pin < 14) { + port = 1; + offset = 8; + } else if (pin < 22) { + port = 2; + offset = 14; + } - if(pin > 1) { // ignore RxTx (pins 0 and 1) - pinStatus[pin] = mode; - switch(mode) { - case INPUT: - pinMode(pin, INPUT); - portStatus[port] = portStatus[port] &~ (1 << (pin - offset)); - break; - case OUTPUT: - digitalWrite(pin, LOW); // disable PWM - case PWM: - pinMode(pin, OUTPUT); - portStatus[port] = portStatus[port] | (1 << (pin - offset)); - break; + if (pin > 1) { // ignore RxTx (pins 0 and 1) + pinStatus[pin] = mode; + switch (mode) { + case INPUT: + pinMode(pin, INPUT); + portStatus[port] = portStatus[port] &~ (1 << (pin - offset)); + break; + case OUTPUT: + digitalWrite(pin, LOW); // disable PWM + case PWM: + pinMode(pin, OUTPUT); + portStatus[port] = portStatus[port] | (1 << (pin - offset)); + break; //case ANALOG: // TODO figure this out - default: - Firmata.sendString(""); - } - // TODO: save status to EEPROM here, if changed + default: + Firmata.sendString(""); } + // TODO: save status to EEPROM here, if changed + } } void analogWriteCallback(byte pin, int value) { - setPinModeCallback(pin,PWM); - analogWrite(pin, value); + setPinModeCallback(pin, PWM); + analogWrite(pin, value); } void digitalWriteCallback(byte port, int value) { - switch(port) { + switch (port) { case 0: // pins 2-7 (don't change Rx/Tx, pins 0 and 1) - // 0xFF03 == B1111111100000011 0x03 == B00000011 - PORTD = (value &~ 0xFF03) | (PORTD & 0x03); - break; - case 1: // pins 8-13 (14,15 are disabled for the crystal) - PORTB = (byte)value; - break; + // 0xFF03 == B1111111100000011 0x03 == B00000011 + PORTD = (value &~ 0xFF03) | (PORTD & 0x03); + break; + case 1: // pins 8-13 (14,15 are disabled for the crystal) + PORTB = (byte)value; + break; case 2: // analog pins used as digital - PORTC = (byte)value; - break; - } + PORTC = (byte)value; + break; + } } // ----------------------------------------------------------------------------- @@ -149,91 +149,91 @@ void digitalWriteCallback(byte port, int value) //} void reportAnalogCallback(byte pin, int value) { - if(value == 0) { - analogInputsToReport = analogInputsToReport &~ (1 << pin); - } - else { // everything but 0 enables reporting of that pin - analogInputsToReport = analogInputsToReport | (1 << pin); - } - // TODO: save status to EEPROM here, if changed + if (value == 0) { + analogInputsToReport = analogInputsToReport &~ (1 << pin); + } + else { // everything but 0 enables reporting of that pin + analogInputsToReport = analogInputsToReport | (1 << pin); + } + // TODO: save status to EEPROM here, if changed } void reportDigitalCallback(byte port, int value) { - reportPINs[port] = (byte)value; - if(port == 2) // turn off analog reporting when used as digital - analogInputsToReport = 0; + reportPINs[port] = (byte)value; + if (port == 2) // turn off analog reporting when used as digital + analogInputsToReport = 0; } /*============================================================================== * SETUP() *============================================================================*/ -void setup() +void setup() { - byte i; + byte i; - Firmata.setFirmwareVersion(2, 0); + Firmata.setFirmwareVersion(2, 0); - Firmata.attach(ANALOG_MESSAGE, analogWriteCallback); - Firmata.attach(DIGITAL_MESSAGE, digitalWriteCallback); - Firmata.attach(REPORT_ANALOG, reportAnalogCallback); - Firmata.attach(REPORT_DIGITAL, reportDigitalCallback); - Firmata.attach(SET_PIN_MODE, setPinModeCallback); + Firmata.attach(ANALOG_MESSAGE, analogWriteCallback); + Firmata.attach(DIGITAL_MESSAGE, digitalWriteCallback); + Firmata.attach(REPORT_ANALOG, reportAnalogCallback); + Firmata.attach(REPORT_DIGITAL, reportDigitalCallback); + Firmata.attach(SET_PIN_MODE, setPinModeCallback); - portStatus[0] = B00000011; // ignore Tx/RX pins - portStatus[1] = B11000000; // ignore 14/15 pins - portStatus[2] = B00000000; + portStatus[0] = B00000011; // ignore Tx/RX pins + portStatus[1] = B11000000; // ignore 14/15 pins + portStatus[2] = B00000000; -// for(i=0; i 20) { - previousMillis += 20; // run this every 20ms - /* SERIALREAD - Serial.read() uses a 128 byte circular buffer, so handle - * all serialReads at once, i.e. empty the buffer */ - while(Firmata.available()) - Firmata.processInput(); - /* SEND FTDI WRITE BUFFER - make sure that the FTDI buffer doesn't go over - * 60 bytes. use a timer to sending an event character every 4 ms to - * trigger the buffer to dump. */ - - /* ANALOGREAD - right after the event character, do all of the - * analogReads(). These only need to be done every 4ms. */ - for(analogPin=0;analogPin 20) { + previousMillis += 20; // run this every 20ms + /* SERIALREAD - Serial.read() uses a 128 byte circular buffer, so handle + * all serialReads at once, i.e. empty the buffer */ + while (Firmata.available()) + Firmata.processInput(); + /* SEND FTDI WRITE BUFFER - make sure that the FTDI buffer doesn't go over + * 60 bytes. use a timer to sending an event character every 4 ms to + * trigger the buffer to dump. */ + + /* ANALOGREAD - right after the event character, do all of the + * analogReads(). These only need to be done every 4ms. */ + for (analogPin = 0; analogPin < TOTAL_ANALOG_PINS; analogPin++) { + if ( analogInputsToReport & (1 << analogPin) ) { + Firmata.sendAnalog(analogPin, analogRead(analogPin)); + } } + } } diff --git a/libraries/Firmata/examples/ServoFirmata/ServoFirmata.ino b/libraries/Firmata/examples/ServoFirmata/ServoFirmata.ino index cdcfff04d..aab189bd7 100644 --- a/libraries/Firmata/examples/ServoFirmata/ServoFirmata.ino +++ b/libraries/Firmata/examples/ServoFirmata/ServoFirmata.ino @@ -9,14 +9,14 @@ * http://firmata.org/wiki/Download */ -/* This firmware supports as many servos as possible using the Servo library +/* This firmware supports as many servos as possible using the Servo library * included in Arduino 0017 * * TODO add message to configure minPulse/maxPulse/degrees * * This example code is in the public domain. */ - + #include #include @@ -24,30 +24,30 @@ Servo servos[MAX_SERVOS]; void analogWriteCallback(byte pin, int value) { + if (IS_PIN_SERVO(pin)) { + servos[PIN_TO_SERVO(pin)].write(value); + } +} + +void setup() +{ + byte pin; + + Firmata.setFirmwareVersion(0, 2); + Firmata.attach(ANALOG_MESSAGE, analogWriteCallback); + + for (pin = 0; pin < TOTAL_PINS; pin++) { if (IS_PIN_SERVO(pin)) { - servos[PIN_TO_SERVO(pin)].write(value); + servos[PIN_TO_SERVO(pin)].attach(PIN_TO_DIGITAL(pin)); } + } + + Firmata.begin(57600); } -void setup() +void loop() { - byte pin; - - Firmata.setFirmwareVersion(0, 2); - Firmata.attach(ANALOG_MESSAGE, analogWriteCallback); - - for (pin=0; pin < TOTAL_PINS; pin++) { - if (IS_PIN_SERVO(pin)) { - servos[PIN_TO_SERVO(pin)].attach(PIN_TO_DIGITAL(pin)); - } - } - - Firmata.begin(57600); -} - -void loop() -{ - while(Firmata.available()) - Firmata.processInput(); + while (Firmata.available()) + Firmata.processInput(); } diff --git a/libraries/Firmata/examples/SimpleAnalogFirmata/SimpleAnalogFirmata.ino b/libraries/Firmata/examples/SimpleAnalogFirmata/SimpleAnalogFirmata.ino index 44ea91eea..63ef465c6 100644 --- a/libraries/Firmata/examples/SimpleAnalogFirmata/SimpleAnalogFirmata.ino +++ b/libraries/Firmata/examples/SimpleAnalogFirmata/SimpleAnalogFirmata.ino @@ -19,28 +19,28 @@ byte analogPin = 0; void analogWriteCallback(byte pin, int value) { - if (IS_PIN_PWM(pin)) { - pinMode(PIN_TO_DIGITAL(pin), OUTPUT); - analogWrite(PIN_TO_PWM(pin), value); - } + if (IS_PIN_PWM(pin)) { + pinMode(PIN_TO_DIGITAL(pin), OUTPUT); + analogWrite(PIN_TO_PWM(pin), value); + } } void setup() { - Firmata.setFirmwareVersion(0, 1); - Firmata.attach(ANALOG_MESSAGE, analogWriteCallback); - Firmata.begin(57600); + Firmata.setFirmwareVersion(0, 1); + Firmata.attach(ANALOG_MESSAGE, analogWriteCallback); + Firmata.begin(57600); } void loop() { - while(Firmata.available()) { - Firmata.processInput(); - } - // do one analogRead per loop, so if PC is sending a lot of - // analog write messages, we will only delay 1 analogRead - Firmata.sendAnalog(analogPin, analogRead(analogPin)); - analogPin = analogPin + 1; - if (analogPin >= TOTAL_ANALOG_PINS) analogPin = 0; + while (Firmata.available()) { + Firmata.processInput(); + } + // do one analogRead per loop, so if PC is sending a lot of + // analog write messages, we will only delay 1 analogRead + Firmata.sendAnalog(analogPin, analogRead(analogPin)); + analogPin = analogPin + 1; + if (analogPin >= TOTAL_ANALOG_PINS) analogPin = 0; } diff --git a/libraries/Firmata/examples/SimpleDigitalFirmata/SimpleDigitalFirmata.ino b/libraries/Firmata/examples/SimpleDigitalFirmata/SimpleDigitalFirmata.ino index a0d764f72..016c22091 100644 --- a/libraries/Firmata/examples/SimpleDigitalFirmata/SimpleDigitalFirmata.ino +++ b/libraries/Firmata/examples/SimpleDigitalFirmata/SimpleDigitalFirmata.ino @@ -16,57 +16,57 @@ #include byte previousPIN[TOTAL_PORTS]; // PIN means PORT for input -byte previousPORT[TOTAL_PORTS]; +byte previousPORT[TOTAL_PORTS]; void outputPort(byte portNumber, byte portValue) { - // only send the data when it changes, otherwise you get too many messages! - if (previousPIN[portNumber] != portValue) { - Firmata.sendDigitalPort(portNumber, portValue); - previousPIN[portNumber] = portValue; - } + // only send the data when it changes, otherwise you get too many messages! + if (previousPIN[portNumber] != portValue) { + Firmata.sendDigitalPort(portNumber, portValue); + previousPIN[portNumber] = portValue; + } } void setPinModeCallback(byte pin, int mode) { - if (IS_PIN_DIGITAL(pin)) { - pinMode(PIN_TO_DIGITAL(pin), mode); - } + if (IS_PIN_DIGITAL(pin)) { + pinMode(PIN_TO_DIGITAL(pin), mode); + } } void digitalWriteCallback(byte port, int value) { - byte i; - byte currentPinValue, previousPinValue; + byte i; + byte currentPinValue, previousPinValue; - if (port < TOTAL_PORTS && value != previousPORT[port]) { - for(i=0; i<8; i++) { - currentPinValue = (byte) value & (1 << i); - previousPinValue = previousPORT[port] & (1 << i); - if(currentPinValue != previousPinValue) { - digitalWrite(i + (port*8), currentPinValue); - } - } - previousPORT[port] = value; + if (port < TOTAL_PORTS && value != previousPORT[port]) { + for (i = 0; i < 8; i++) { + currentPinValue = (byte) value & (1 << i); + previousPinValue = previousPORT[port] & (1 << i); + if (currentPinValue != previousPinValue) { + digitalWrite(i + (port * 8), currentPinValue); + } } + previousPORT[port] = value; + } } void setup() { - Firmata.setFirmwareVersion(0, 1); - Firmata.attach(DIGITAL_MESSAGE, digitalWriteCallback); - Firmata.attach(SET_PIN_MODE, setPinModeCallback); - Firmata.begin(57600); + Firmata.setFirmwareVersion(0, 1); + Firmata.attach(DIGITAL_MESSAGE, digitalWriteCallback); + Firmata.attach(SET_PIN_MODE, setPinModeCallback); + Firmata.begin(57600); } void loop() { - byte i; + byte i; - for (i=0; i= 100 +#if ARDUINO >= 100 Wire.write((byte)theRegister); - #else +#else Wire.send((byte)theRegister); - #endif +#endif Wire.endTransmission(); // do not set a value of 0 if (i2cReadDelayTime > 0) { @@ -111,22 +111,22 @@ void readAndReportData(byte address, int theRegister, byte numBytes) { Wire.requestFrom(address, numBytes); // all bytes are returned in requestFrom // check to be sure correct number of bytes were returned by slave - if(numBytes == Wire.available()) { + if (numBytes == Wire.available()) { i2cRxData[0] = address; i2cRxData[1] = theRegister; for (int i = 0; i < numBytes; i++) { - #if ARDUINO >= 100 +#if ARDUINO >= 100 i2cRxData[2 + i] = Wire.read(); - #else +#else i2cRxData[2 + i] = Wire.receive(); - #endif +#endif } } else { - if(numBytes > Wire.available()) { + if (numBytes > Wire.available()) { Firmata.sendString("I2C Read Error: Too many bytes received"); } else { - Firmata.sendString("I2C Read Error: Too few bytes received"); + Firmata.sendString("I2C Read Error: Too few bytes received"); } } @@ -139,7 +139,7 @@ void outputPort(byte portNumber, byte portValue, byte forceSend) // pins not configured as INPUT are cleared to zeros portValue = portValue & portConfigInputs[portNumber]; // only send if the value is different than previously sent - if(forceSend || previousPINs[portNumber] != portValue) { + if (forceSend || previousPINs[portNumber] != portValue) { Firmata.sendDigitalPort(portNumber, portValue); previousPINs[portNumber] = portValue; } @@ -190,60 +190,60 @@ void setPinModeCallback(byte pin, int mode) } if (IS_PIN_DIGITAL(pin)) { if (mode == INPUT) { - portConfigInputs[pin/8] |= (1 << (pin & 7)); + portConfigInputs[pin / 8] |= (1 << (pin & 7)); } else { - portConfigInputs[pin/8] &= ~(1 << (pin & 7)); + portConfigInputs[pin / 8] &= ~(1 << (pin & 7)); } } pinState[pin] = 0; - switch(mode) { - case ANALOG: - if (IS_PIN_ANALOG(pin)) { + switch (mode) { + case ANALOG: + if (IS_PIN_ANALOG(pin)) { + if (IS_PIN_DIGITAL(pin)) { + pinMode(PIN_TO_DIGITAL(pin), INPUT); // disable output driver + digitalWrite(PIN_TO_DIGITAL(pin), LOW); // disable internal pull-ups + } + pinConfig[pin] = ANALOG; + } + break; + case INPUT: if (IS_PIN_DIGITAL(pin)) { pinMode(PIN_TO_DIGITAL(pin), INPUT); // disable output driver digitalWrite(PIN_TO_DIGITAL(pin), LOW); // disable internal pull-ups + pinConfig[pin] = INPUT; } - pinConfig[pin] = ANALOG; - } - break; - case INPUT: - if (IS_PIN_DIGITAL(pin)) { - pinMode(PIN_TO_DIGITAL(pin), INPUT); // disable output driver - digitalWrite(PIN_TO_DIGITAL(pin), LOW); // disable internal pull-ups - pinConfig[pin] = INPUT; - } - break; - case OUTPUT: - if (IS_PIN_DIGITAL(pin)) { - digitalWrite(PIN_TO_DIGITAL(pin), LOW); // disable PWM - pinMode(PIN_TO_DIGITAL(pin), OUTPUT); - pinConfig[pin] = OUTPUT; - } - break; - case PWM: - if (IS_PIN_PWM(pin)) { - pinMode(PIN_TO_PWM(pin), OUTPUT); - analogWrite(PIN_TO_PWM(pin), 0); - pinConfig[pin] = PWM; - } - break; - case SERVO: - if (IS_PIN_SERVO(pin)) { - pinConfig[pin] = SERVO; - if (!servos[PIN_TO_SERVO(pin)].attached()) { + break; + case OUTPUT: + if (IS_PIN_DIGITAL(pin)) { + digitalWrite(PIN_TO_DIGITAL(pin), LOW); // disable PWM + pinMode(PIN_TO_DIGITAL(pin), OUTPUT); + pinConfig[pin] = OUTPUT; + } + break; + case PWM: + if (IS_PIN_PWM(pin)) { + pinMode(PIN_TO_PWM(pin), OUTPUT); + analogWrite(PIN_TO_PWM(pin), 0); + pinConfig[pin] = PWM; + } + break; + case SERVO: + if (IS_PIN_SERVO(pin)) { + pinConfig[pin] = SERVO; + if (!servos[PIN_TO_SERVO(pin)].attached()) { servos[PIN_TO_SERVO(pin)].attach(PIN_TO_DIGITAL(pin)); + } } - } - break; - case I2C: - if (IS_PIN_I2C(pin)) { - // mark the pin as i2c - // the user must call I2C_CONFIG to enable I2C for a device - pinConfig[pin] = I2C; - } - break; - default: - Firmata.sendString("Unknown pin mode"); // TODO: put error msgs in EEPROM + break; + case I2C: + if (IS_PIN_I2C(pin)) { + // mark the pin as i2c + // the user must call I2C_CONFIG to enable I2C for a device + pinConfig[pin] = I2C; + } + break; + default: + Firmata.sendString("Unknown pin mode"); // TODO: put error msgs in EEPROM } // TODO: save status to EEPROM here, if changed } @@ -251,30 +251,30 @@ void setPinModeCallback(byte pin, int mode) void analogWriteCallback(byte pin, int value) { if (pin < TOTAL_PINS) { - switch(pinConfig[pin]) { - case SERVO: - if (IS_PIN_SERVO(pin)) - servos[PIN_TO_SERVO(pin)].write(value); + switch (pinConfig[pin]) { + case SERVO: + if (IS_PIN_SERVO(pin)) + servos[PIN_TO_SERVO(pin)].write(value); pinState[pin] = value; - break; - case PWM: - if (IS_PIN_PWM(pin)) - analogWrite(PIN_TO_PWM(pin), value); + break; + case PWM: + if (IS_PIN_PWM(pin)) + analogWrite(PIN_TO_PWM(pin), value); pinState[pin] = value; - break; + break; } } } void digitalWriteCallback(byte port, int value) { - byte pin, lastPin, mask=1, pinWriteMask=0; + byte pin, lastPin, mask = 1, pinWriteMask = 0; if (port < TOTAL_PORTS) { // create a mask of the pins on this port that are writable. - lastPin = port*8+8; + lastPin = port * 8 + 8; if (lastPin > TOTAL_PINS) lastPin = TOTAL_PINS; - for (pin=port*8; pin < lastPin; pin++) { + for (pin = port * 8; pin < lastPin; pin++) { // do not disturb non-digital pins (eg, Rx & Tx) if (IS_PIN_DIGITAL(pin)) { // only write to OUTPUT and INPUT (enables pullup) @@ -299,7 +299,7 @@ void digitalWriteCallback(byte port, int value) void reportAnalogCallback(byte analogPin, int value) { if (analogPin < TOTAL_ANALOG_PINS) { - if(value == 0) { + if (value == 0) { analogInputsToReport = analogInputsToReport &~ (1 << analogPin); } else { analogInputsToReport = analogInputsToReport | (1 << analogPin); @@ -331,214 +331,214 @@ void sysexCallback(byte command, byte argc, byte *argv) byte slaveAddress; byte slaveRegister; byte data; - unsigned int delayTime; - - switch(command) { - case I2C_REQUEST: - mode = argv[1] & I2C_READ_WRITE_MODE_MASK; - if (argv[1] & I2C_10BIT_ADDRESS_MODE_MASK) { - Firmata.sendString("10-bit addressing mode is not yet supported"); - return; - } - else { - slaveAddress = argv[0]; - } + unsigned int delayTime; - switch(mode) { - case I2C_WRITE: - Wire.beginTransmission(slaveAddress); - for (byte i = 2; i < argc; i += 2) { - data = argv[i] + (argv[i + 1] << 7); - #if ARDUINO >= 100 - Wire.write(data); - #else - Wire.send(data); - #endif - } - Wire.endTransmission(); - delayMicroseconds(70); - break; - case I2C_READ: - if (argc == 6) { - // a slave register is specified - slaveRegister = argv[2] + (argv[3] << 7); - data = argv[4] + (argv[5] << 7); // bytes to read - readAndReportData(slaveAddress, (int)slaveRegister, data); + switch (command) { + case I2C_REQUEST: + mode = argv[1] & I2C_READ_WRITE_MODE_MASK; + if (argv[1] & I2C_10BIT_ADDRESS_MODE_MASK) { + Firmata.sendString("10-bit addressing mode is not yet supported"); + return; } else { - // a slave register is NOT specified - data = argv[2] + (argv[3] << 7); // bytes to read - readAndReportData(slaveAddress, (int)REGISTER_NOT_SPECIFIED, data); + slaveAddress = argv[0]; } - break; - case I2C_READ_CONTINUOUSLY: - if ((queryIndex + 1) >= MAX_QUERIES) { - // too many queries, just ignore - Firmata.sendString("too many queries"); - break; - } - queryIndex++; - query[queryIndex].addr = slaveAddress; - query[queryIndex].reg = argv[2] + (argv[3] << 7); - query[queryIndex].bytes = argv[4] + (argv[5] << 7); - break; - case I2C_STOP_READING: - byte queryIndexToSkip; - // if read continuous mode is enabled for only 1 i2c device, disable - // read continuous reporting for that device - if (queryIndex <= 0) { - queryIndex = -1; - } else { - // if read continuous mode is enabled for multiple devices, - // determine which device to stop reading and remove it's data from - // the array, shifiting other array data to fill the space - for (byte i = 0; i < queryIndex + 1; i++) { - if (query[i].addr = slaveAddress) { - queryIndexToSkip = i; + + switch (mode) { + case I2C_WRITE: + Wire.beginTransmission(slaveAddress); + for (byte i = 2; i < argc; i += 2) { + data = argv[i] + (argv[i + 1] << 7); +#if ARDUINO >= 100 + Wire.write(data); +#else + Wire.send(data); +#endif + } + Wire.endTransmission(); + delayMicroseconds(70); + break; + case I2C_READ: + if (argc == 6) { + // a slave register is specified + slaveRegister = argv[2] + (argv[3] << 7); + data = argv[4] + (argv[5] << 7); // bytes to read + readAndReportData(slaveAddress, (int)slaveRegister, data); + } + else { + // a slave register is NOT specified + data = argv[2] + (argv[3] << 7); // bytes to read + readAndReportData(slaveAddress, (int)REGISTER_NOT_SPECIFIED, data); + } + break; + case I2C_READ_CONTINUOUSLY: + if ((queryIndex + 1) >= MAX_QUERIES) { + // too many queries, just ignore + Firmata.sendString("too many queries"); break; } - } - - for (byte i = queryIndexToSkip; i 0) { + i2cReadDelayTime = delayTime; + } + + if (!isI2CEnabled) { + enableI2CPins(); + } + + break; + case SERVO_CONFIG: + if (argc > 4) { + // these vars are here for clarity, they'll optimized away by the compiler + byte pin = argv[0]; + int minPulse = argv[1] + (argv[2] << 7); + int maxPulse = argv[3] + (argv[4] << 7); + + if (IS_PIN_SERVO(pin)) { + if (servos[PIN_TO_SERVO(pin)].attached()) + servos[PIN_TO_SERVO(pin)].detach(); + servos[PIN_TO_SERVO(pin)].attach(PIN_TO_DIGITAL(pin), minPulse, maxPulse); + setPinModeCallback(pin, SERVO); } - queryIndex--; } break; - default: + case SAMPLING_INTERVAL: + if (argc > 1) { + samplingInterval = argv[0] + (argv[1] << 7); + if (samplingInterval < MINIMUM_SAMPLING_INTERVAL) { + samplingInterval = MINIMUM_SAMPLING_INTERVAL; + } + } else { + //Firmata.sendString("Not enough data"); + } break; - } - break; - case I2C_CONFIG: - delayTime = (argv[0] + (argv[1] << 7)); - - if(delayTime > 0) { - i2cReadDelayTime = delayTime; - } - - if (!isI2CEnabled) { - enableI2CPins(); - } - - break; - case SERVO_CONFIG: - if(argc > 4) { - // these vars are here for clarity, they'll optimized away by the compiler - byte pin = argv[0]; - int minPulse = argv[1] + (argv[2] << 7); - int maxPulse = argv[3] + (argv[4] << 7); - - if (IS_PIN_SERVO(pin)) { - if (servos[PIN_TO_SERVO(pin)].attached()) - servos[PIN_TO_SERVO(pin)].detach(); - servos[PIN_TO_SERVO(pin)].attach(PIN_TO_DIGITAL(pin), minPulse, maxPulse); - setPinModeCallback(pin, SERVO); + case EXTENDED_ANALOG: + if (argc > 1) { + int val = argv[1]; + if (argc > 2) val |= (argv[2] << 7); + if (argc > 3) val |= (argv[3] << 14); + analogWriteCallback(argv[0], val); } - } - break; - case SAMPLING_INTERVAL: - if (argc > 1) { - samplingInterval = argv[0] + (argv[1] << 7); - if (samplingInterval < MINIMUM_SAMPLING_INTERVAL) { - samplingInterval = MINIMUM_SAMPLING_INTERVAL; - } - } else { - //Firmata.sendString("Not enough data"); - } - break; - case EXTENDED_ANALOG: - if (argc > 1) { - int val = argv[1]; - if (argc > 2) val |= (argv[2] << 7); - if (argc > 3) val |= (argv[3] << 14); - analogWriteCallback(argv[0], val); - } - break; - case CAPABILITY_QUERY: - Firmata.write(START_SYSEX); - Firmata.write(CAPABILITY_RESPONSE); - for (byte pin=0; pin < TOTAL_PINS; pin++) { - if (IS_PIN_DIGITAL(pin)) { - Firmata.write((byte)INPUT); - Firmata.write(1); - Firmata.write((byte)OUTPUT); - Firmata.write(1); - } - if (IS_PIN_ANALOG(pin)) { - Firmata.write(ANALOG); - Firmata.write(10); - } - if (IS_PIN_PWM(pin)) { - Firmata.write(PWM); - Firmata.write(8); - } - if (IS_PIN_SERVO(pin)) { - Firmata.write(SERVO); - Firmata.write(14); - } - if (IS_PIN_I2C(pin)) { - Firmata.write(I2C); - Firmata.write(1); // to do: determine appropriate value - } - Firmata.write(127); - } - Firmata.write(END_SYSEX); - break; - case PIN_STATE_QUERY: - if (argc > 0) { - byte pin=argv[0]; + break; + case CAPABILITY_QUERY: Firmata.write(START_SYSEX); - Firmata.write(PIN_STATE_RESPONSE); - Firmata.write(pin); - if (pin < TOTAL_PINS) { - Firmata.write((byte)pinConfig[pin]); - Firmata.write((byte)pinState[pin] & 0x7F); - if (pinState[pin] & 0xFF80) Firmata.write((byte)(pinState[pin] >> 7) & 0x7F); - if (pinState[pin] & 0xC000) Firmata.write((byte)(pinState[pin] >> 14) & 0x7F); + Firmata.write(CAPABILITY_RESPONSE); + for (byte pin = 0; pin < TOTAL_PINS; pin++) { + if (IS_PIN_DIGITAL(pin)) { + Firmata.write((byte)INPUT); + Firmata.write(1); + Firmata.write((byte)OUTPUT); + Firmata.write(1); + } + if (IS_PIN_ANALOG(pin)) { + Firmata.write(ANALOG); + Firmata.write(10); + } + if (IS_PIN_PWM(pin)) { + Firmata.write(PWM); + Firmata.write(8); + } + if (IS_PIN_SERVO(pin)) { + Firmata.write(SERVO); + Firmata.write(14); + } + if (IS_PIN_I2C(pin)) { + Firmata.write(I2C); + Firmata.write(1); // to do: determine appropriate value + } + Firmata.write(127); } Firmata.write(END_SYSEX); - } - break; - case ANALOG_MAPPING_QUERY: - Firmata.write(START_SYSEX); - Firmata.write(ANALOG_MAPPING_RESPONSE); - for (byte pin=0; pin < TOTAL_PINS; pin++) { - Firmata.write(IS_PIN_ANALOG(pin) ? PIN_TO_ANALOG(pin) : 127); - } - Firmata.write(END_SYSEX); - break; + break; + case PIN_STATE_QUERY: + if (argc > 0) { + byte pin = argv[0]; + Firmata.write(START_SYSEX); + Firmata.write(PIN_STATE_RESPONSE); + Firmata.write(pin); + if (pin < TOTAL_PINS) { + Firmata.write((byte)pinConfig[pin]); + Firmata.write((byte)pinState[pin] & 0x7F); + if (pinState[pin] & 0xFF80) Firmata.write((byte)(pinState[pin] >> 7) & 0x7F); + if (pinState[pin] & 0xC000) Firmata.write((byte)(pinState[pin] >> 14) & 0x7F); + } + Firmata.write(END_SYSEX); + } + break; + case ANALOG_MAPPING_QUERY: + Firmata.write(START_SYSEX); + Firmata.write(ANALOG_MAPPING_RESPONSE); + for (byte pin = 0; pin < TOTAL_PINS; pin++) { + Firmata.write(IS_PIN_ANALOG(pin) ? PIN_TO_ANALOG(pin) : 127); + } + Firmata.write(END_SYSEX); + break; } } void enableI2CPins() { byte i; - // is there a faster way to do this? would probaby require importing + // is there a faster way to do this? would probaby require importing // Arduino.h to get SCL and SDA pins - for (i=0; i < TOTAL_PINS; i++) { - if(IS_PIN_I2C(i)) { + for (i = 0; i < TOTAL_PINS; i++) { + if (IS_PIN_I2C(i)) { // mark pins as i2c so they are ignore in non i2c data requests setPinModeCallback(i, I2C); - } + } } - - isI2CEnabled = true; - + + isI2CEnabled = true; + // is there enough time before the first I2C request to call this here? Wire.begin(); } /* disable the i2c pins so they can be used for other functions */ void disableI2CPins() { - isI2CEnabled = false; - // disable read continuous mode for all devices - queryIndex = -1; - // uncomment the following if or when the end() method is added to Wire library - // Wire.end(); + isI2CEnabled = false; + // disable read continuous mode for all devices + queryIndex = -1; + // uncomment the following if or when the end() method is added to Wire library + // Wire.end(); } /*============================================================================== @@ -550,16 +550,16 @@ void systemResetCallback() // initialize a defalt state // TODO: option to load config from EEPROM instead of default if (isI2CEnabled) { - disableI2CPins(); + disableI2CPins(); } - for (byte i=0; i < TOTAL_PORTS; i++) { + for (byte i = 0; i < TOTAL_PORTS; i++) { reportPINs[i] = false; // by default, reporting off portConfigInputs[i] = 0; // until activated previousPINs[i] = 0; } // pins with analog capability default to analog input // otherwise, pins default to digital output - for (byte i=0; i < TOTAL_PINS; i++) { + for (byte i = 0; i < TOTAL_PINS; i++) { if (IS_PIN_ANALOG(i)) { // turns off pullup, configures everything setPinModeCallback(i, ANALOG); @@ -582,7 +582,7 @@ void systemResetCallback() */ } -void setup() +void setup() { Firmata.setFirmwareVersion(FIRMATA_MAJOR_VERSION, FIRMATA_MINOR_VERSION); @@ -601,17 +601,17 @@ void setup() /*============================================================================== * LOOP() *============================================================================*/ -void loop() +void loop() { byte pin, analogPin; /* DIGITALREAD - as fast as possible, check for changes and output them to the * FTDI buffer using Serial.print() */ - checkDigitalInputs(); + checkDigitalInputs(); /* SERIALREAD - processing incoming messagse as soon as possible, while still * checking digital inputs. */ - while(Firmata.available()) + while (Firmata.available()) Firmata.processInput(); /* SEND FTDI WRITE BUFFER - make sure that the FTDI buffer doesn't go over @@ -622,7 +622,7 @@ void loop() if (currentMillis - previousMillis > samplingInterval) { previousMillis += samplingInterval; /* ANALOGREAD - do all analogReads() at the configured sampling interval */ - for(pin=0; pin postingInterval)) + if (!client.connected() && ((millis() - lastConnectionTime) > postingInterval)) { - sendData(sensorReading); + sendData(sensorReading); } - + // store the state of the connection for next time through // the loop: lastConnected = client.connected(); @@ -121,7 +121,7 @@ void sendData(int thisData) if (client.connect(server, 80)) { Serial.println("connecting..."); - + // send the HTTP PUT request: client.print("PUT /v2/feeds/"); client.print(FEEDID); @@ -142,11 +142,11 @@ void sendData(int thisData) client.println("Content-Type: text/csv"); client.println("Connection: close"); client.println(); - + // here's the actual content of the PUT request: client.print("sensor1,"); client.println(thisData); - } + } else { // if you couldn't make a connection: @@ -169,17 +169,17 @@ int getLength(int someValue) { // there's at least one byte: int digits = 1; - - // continually divide the value by ten, + + // continually divide the value by ten, // adding one to the digit count for each // time you divide, until you're at 0: - int dividend = someValue /10; + int dividend = someValue / 10; while (dividend > 0) { - dividend = dividend /10; + dividend = dividend / 10; digits++; } - + // return the number of digits: return digits; } diff --git a/libraries/GSM/examples/GSMPachubeClientString/GSMPachubeClientString.ino b/libraries/GSM/examples/GSMPachubeClientString/GSMPachubeClientString.ino index 9f6ea531d..b7f0a8cbe 100644 --- a/libraries/GSM/examples/GSMPachubeClientString/GSMPachubeClientString.ino +++ b/libraries/GSM/examples/GSMPachubeClientString/GSMPachubeClientString.ino @@ -1,27 +1,27 @@ /* Pachube client with Strings - + This sketch connects two analog sensors to Pachube (http://www.pachube.com) through a Telefonica GSM/GPRS shield. - - This example has been updated to use version 2.0 of the Pachube.com API. + + This example has been updated to use version 2.0 of the Pachube.com API. To make it work, create a feed with two datastreams, and give them the IDs sensor1 and sensor2. Or change the code below to match your feed. - + This example uses the String library, which is part of the Arduino core from - version 0019. - + version 0019. + Circuit: * Analog sensors attached to A0 and A1 * GSM shield attached to an Arduino * SIM card with a data plan - + created 8 March 2012 by Tom Igoe and adapted for GSM shield by David Del Peral - + This code is in the public domain. - + */ // Include the GSM library @@ -52,7 +52,7 @@ char server[] = "api.pachube.com"; // name address for Pachube API unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds boolean lastConnected = false; // state of the connection last time through the main loop -const unsigned long postingInterval = 10*1000; // delay between updates to Pachube.com +const unsigned long postingInterval = 10 * 1000; // delay between updates to Pachube.com void setup() { @@ -61,16 +61,16 @@ void setup() while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } - + // connection state boolean notConnected = true; - + // After starting the modem with GSM.begin() - // attach the shield to the GPRS network with the APN, login and password - while(notConnected) + // attach the shield to the GPRS network with the APN, login and password + while (notConnected) { - if((gsmAccess.begin(PINNUMBER)==GSM_READY) & - (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY)) + if ((gsmAccess.begin(PINNUMBER) == GSM_READY) & + (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) notConnected = false; else { @@ -85,13 +85,13 @@ void setup() void loop() { // read the sensor on A0 - int sensorReading = analogRead(A0); - + int sensorReading = analogRead(A0); + // convert the data to a String String dataString = "sensor1,"; dataString += sensorReading; - // you can append multiple readings to this String to + // you can append multiple readings to this String to // send the pachube feed multiple values int otherSensorReading = analogRead(A1); dataString += "\nsensor2,"; @@ -117,7 +117,7 @@ void loop() // if you're not connected, and ten seconds have passed since // your last connection, then connect again and send data - if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) + if (!client.connected() && (millis() - lastConnectionTime > postingInterval)) { sendData(dataString); } @@ -133,7 +133,7 @@ void sendData(String thisData) if (client.connect(server, 80)) { Serial.println("connecting..."); - + // send the HTTP PUT request: client.print("PUT /v2/feeds/"); client.print(FEEDID); @@ -150,10 +150,10 @@ void sendData(String thisData) client.println("Content-Type: text/csv"); client.println("Connection: close"); client.println(); - + // here's the actual content of the PUT request client.println(thisData); - } + } else { // if you couldn't make a connection diff --git a/libraries/GSM/examples/GsmWebClient/GsmWebClient.ino b/libraries/GSM/examples/GsmWebClient/GsmWebClient.ino index e7eb27587..4de67b150 100644 --- a/libraries/GSM/examples/GsmWebClient/GsmWebClient.ino +++ b/libraries/GSM/examples/GsmWebClient/GsmWebClient.ino @@ -1,19 +1,19 @@ /* Web client - + This sketch connects to a website through a GSM shield. Specifically, - this example downloads the URL "http://arduino.cc/asciilogo.txt" and + this example downloads the URL "http://arduino.cc/asciilogo.txt" and prints it to the Serial monitor. - + Circuit: * GSM shield attached to an Arduino * SIM card with a data plan - + created 8 Mar 2012 by Tom Igoe - + http://arduino.cc/en/Tutorial/GSMExamplesWebClient - + */ // libraries @@ -30,7 +30,7 @@ // initialize the library instance GSMClient client; GPRS gprs; -GSM gsmAccess; +GSM gsmAccess; // URL, path & port (for example: arduino.cc) char server[] = "arduino.cc"; @@ -51,10 +51,10 @@ void setup() // After starting the modem with GSM.begin() // attach the shield to the GPRS network with the APN, login and password - while(notConnected) + while (notConnected) { - if((gsmAccess.begin(PINNUMBER)==GSM_READY) & - (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY)) + if ((gsmAccess.begin(PINNUMBER) == GSM_READY) & + (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) notConnected = false; else { @@ -77,7 +77,7 @@ void setup() client.println(server); client.println("Connection: close"); client.println(); - } + } else { // if you didn't get a connection to the server: @@ -87,7 +87,7 @@ void setup() void loop() { - // if there are incoming bytes available + // if there are incoming bytes available // from the server, read them and print them: if (client.available()) { @@ -103,7 +103,7 @@ void loop() client.stop(); // do nothing forevermore: - for(;;) + for (;;) ; } } diff --git a/libraries/GSM/examples/GsmWebServer/GsmWebServer.ino b/libraries/GSM/examples/GsmWebServer/GsmWebServer.ino index e957b4cf8..326d55183 100644 --- a/libraries/GSM/examples/GsmWebServer/GsmWebServer.ino +++ b/libraries/GSM/examples/GsmWebServer/GsmWebServer.ino @@ -1,13 +1,13 @@ /* GSM Web Server - + A simple web server that shows the value of the analog input pins. using a GSM shield. Circuit: * GSM shield attached * Analog inputs attached to pins A0 through A5 (optional) - + created 8 Mar 2012 by Tom Igoe */ @@ -30,7 +30,7 @@ GSM gsmAccess; // include a 'true' parameter for debug enabled GSMServer server(80); // port 80 (http default) // timeout -const unsigned long __TIMEOUT__ = 10*1000; +const unsigned long __TIMEOUT__ = 10 * 1000; void setup() { @@ -39,16 +39,16 @@ void setup() while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } - + // connection state boolean notConnected = true; - + // Start GSM shield // If your SIM has PIN, pass it as a parameter of begin() in quotes - while(notConnected) + while (notConnected) { - if((gsmAccess.begin(PINNUMBER)==GSM_READY) & - (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY)) + if ((gsmAccess.begin(PINNUMBER) == GSM_READY) & + (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) notConnected = false; else { @@ -56,12 +56,12 @@ void setup() delay(1000); } } - + Serial.println("Connected to GPRS network"); - + // start server server.begin(); - + //Get IP. IPAddress LocalIP = gprs.getIPAddress(); Serial.println("Server IP address="); @@ -77,21 +77,21 @@ void loop() { if (client) - { + { while (client.connected()) { if (client.available()) { Serial.println("Receiving request!"); bool sendResponse = false; - while(char c=client.read()) { + while (char c = client.read()) { if (c == '\n') sendResponse = true; } - // if you've gotten to the end of the line (received a newline - // character) - if (sendResponse) - { + // if you've gotten to the end of the line (received a newline + // character) + if (sendResponse) + { // send a standard http response header client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); @@ -103,7 +103,7 @@ void loop() { client.print(analogChannel); client.print(" is "); client.print(analogRead(analogChannel)); - client.println("
"); + client.println("
"); } client.println(""); //necessary delay diff --git a/libraries/GSM/examples/MakeVoiceCall/MakeVoiceCall.ino b/libraries/GSM/examples/MakeVoiceCall/MakeVoiceCall.ino index 64df44afc..8cdb6d10b 100644 --- a/libraries/GSM/examples/MakeVoiceCall/MakeVoiceCall.ino +++ b/libraries/GSM/examples/MakeVoiceCall/MakeVoiceCall.ino @@ -1,21 +1,21 @@ /* Make Voice Call - + This sketch, for the Arduino GSM shield, puts a voice call to a remote phone number that you enter through the serial monitor. - To make it work, open the serial monitor, and when you see the - READY message, type a phone number. Make sure the serial monitor + To make it work, open the serial monitor, and when you see the + READY message, type a phone number. Make sure the serial monitor is set to send a just newline when you press return. - + Circuit: - * GSM shield - * Voice circuit. + * GSM shield + * Voice circuit. With no voice circuit the call will send nor receive any sound - - + + created Mar 2012 by Javier Zorzano - + This example is in the public domain. */ @@ -42,15 +42,15 @@ void setup() } Serial.println("Make Voice Call"); - + // connection state boolean notConnected = true; - + // Start GSM shield // If your SIM has PIN, pass it as a parameter of begin() in quotes - while(notConnected) + while (notConnected) { - if(gsmAccess.begin(PINNUMBER)==GSM_READY) + if (gsmAccess.begin(PINNUMBER) == GSM_READY) notConnected = false; else { @@ -58,7 +58,7 @@ void setup() delay(1000); } } - + Serial.println("GSM initialized."); Serial.println("Enter phone number to call."); @@ -84,33 +84,33 @@ void loop() // Call the remote number remoteNumber.toCharArray(charbuffer, 20); - - + + // Check if the receiving end has picked up the call - if(vcs.voiceCall(charbuffer)) + if (vcs.voiceCall(charbuffer)) { Serial.println("Call Established. Enter line to end"); // Wait for some input from the line - while(Serial.read()!='\n' && (vcs.getvoiceCallStatus()==TALKING)); + while (Serial.read() != '\n' && (vcs.getvoiceCallStatus() == TALKING)); // And hang up vcs.hangCall(); } Serial.println("Call Finished"); - remoteNumber=""; + remoteNumber = ""; Serial.println("Enter phone number to call."); - } + } else { - Serial.println("That's too long for a phone number. I'm forgetting it"); + Serial.println("That's too long for a phone number. I'm forgetting it"); remoteNumber = ""; } - } + } else { // add the latest character to the message to send: - if(inChar!='\r') + if (inChar != '\r') remoteNumber += inChar; } - } + } } diff --git a/libraries/GSM/examples/ReceiveSMS/ReceiveSMS.ino b/libraries/GSM/examples/ReceiveSMS/ReceiveSMS.ino index af800f46f..d40538e4d 100644 --- a/libraries/GSM/examples/ReceiveSMS/ReceiveSMS.ino +++ b/libraries/GSM/examples/ReceiveSMS/ReceiveSMS.ino @@ -1,20 +1,20 @@ /* SMS receiver - - This sketch, for the Arduino GSM shield, waits for a SMS message - and displays it through the Serial port. - + + This sketch, for the Arduino GSM shield, waits for a SMS message + and displays it through the Serial port. + Circuit: * GSM shield attached to and Arduino * SIM card that can receive SMS messages - + created 25 Feb 2012 by Javier Zorzano / TD - + This example is in the public domain. - + http://arduino.cc/en/Tutorial/GSMExamplesReceiveSMS - + */ // include the GSM library @@ -28,25 +28,25 @@ GSM gsmAccess; GSM_SMS sms; // Array to hold the number a SMS is retreived from -char senderNumber[20]; +char senderNumber[20]; -void setup() +void setup() { // initialize serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only - } + } Serial.println("SMS Messages Receiver"); - + // connection state boolean notConnected = true; - + // Start GSM connection - while(notConnected) + while (notConnected) { - if(gsmAccess.begin(PINNUMBER)==GSM_READY) + if (gsmAccess.begin(PINNUMBER) == GSM_READY) notConnected = false; else { @@ -54,38 +54,38 @@ void setup() delay(1000); } } - + Serial.println("GSM initialized"); Serial.println("Waiting for messages"); } -void loop() +void loop() { char c; - - // If there are any SMSs available() + + // If there are any SMSs available() if (sms.available()) { Serial.println("Message received from:"); - + // Get remote number sms.remoteNumber(senderNumber, 20); Serial.println(senderNumber); - // An example of message disposal + // An example of message disposal // Any messages starting with # should be discarded - if(sms.peek()=='#') + if (sms.peek() == '#') { Serial.println("Discarded SMS"); sms.flush(); } - + // Read message bytes and print them - while(c=sms.read()) + while (c = sms.read()) Serial.print(c); - + Serial.println("\nEND OF MESSAGE"); - + // Delete message from modem memory sms.flush(); Serial.println("MESSAGE DELETED"); diff --git a/libraries/GSM/examples/ReceiveVoiceCall/ReceiveVoiceCall.ino b/libraries/GSM/examples/ReceiveVoiceCall/ReceiveVoiceCall.ino index 14dbc5ee1..a4c76295f 100644 --- a/libraries/GSM/examples/ReceiveVoiceCall/ReceiveVoiceCall.ino +++ b/libraries/GSM/examples/ReceiveVoiceCall/ReceiveVoiceCall.ino @@ -1,24 +1,24 @@ /* Receive Voice Call - - This sketch, for the Arduino GSM shield, receives voice calls, + + This sketch, for the Arduino GSM shield, receives voice calls, displays the calling number, waits a few seconds then hangs up. - + Circuit: - * GSM shield + * GSM shield * Voice circuit. Refer to to the GSM shield getting started guide at http://arduino.cc/en/Guide/ArduinoGSMShield#toc11 * SIM card that can accept voice calls - + With no voice circuit the call will connect, but will not send or receive sound - + created Mar 2012 by Javier Zorzano - + This example is in the public domain. - + http://arduino.cc/en/Tutorial/GSMExamplesReceiveVoiceCall - + */ // Include the GSM library @@ -32,7 +32,7 @@ GSM gsmAccess; GSMVoiceCall vcs; // Array to hold the number for the incoming call -char numtel[20]; +char numtel[20]; void setup() { @@ -43,15 +43,15 @@ void setup() } Serial.println("Receive Voice Call"); - + // connection state boolean notConnected = true; - + // Start GSM shield // If your SIM has PIN, pass it as a parameter of begin() in quotes - while(notConnected) + while (notConnected) { - if(gsmAccess.begin(PINNUMBER)==GSM_READY) + if (gsmAccess.begin(PINNUMBER) == GSM_READY) notConnected = false; else { @@ -59,44 +59,44 @@ void setup() delay(1000); } } - + // This makes sure the modem correctly reports incoming events vcs.hangCall(); - + Serial.println("Waiting for a call"); } void loop() { // Check the status of the voice call - switch (vcs.getvoiceCallStatus()) + switch (vcs.getvoiceCallStatus()) { case IDLE_CALL: // Nothing is happening - + break; - + case RECEIVINGCALL: // Yes! Someone is calling us - + Serial.println("RECEIVING CALL"); - + // Retrieve the calling number vcs.retrieveCallingNumber(numtel, 20); - + // Print the calling number Serial.print("Number:"); Serial.println(numtel); - + // Answer the call, establish the call - vcs.answerCall(); + vcs.answerCall(); break; - + case TALKING: // In this case the call would be established - + Serial.println("TALKING. Press enter to hang up."); - while(Serial.read()!='\n') + while (Serial.read() != '\n') delay(100); vcs.hangCall(); - Serial.println("Hanging up and waiting for the next call."); + Serial.println("Hanging up and waiting for the next call."); break; } delay(1000); diff --git a/libraries/GSM/examples/SendSMS/SendSMS.ino b/libraries/GSM/examples/SendSMS/SendSMS.ino index 677442a93..beaf96dfc 100644 --- a/libraries/GSM/examples/SendSMS/SendSMS.ino +++ b/libraries/GSM/examples/SendSMS/SendSMS.ino @@ -1,24 +1,24 @@ /* SMS sender - - This sketch, for the Arduino GSM shield,sends an SMS message - you enter in the serial monitor. Connect your Arduino with the - GSM shield and SIM card, open the serial monitor, and wait for - the "READY" message to appear in the monitor. Next, type a - message to send and press "return". Make sure the serial + + This sketch, for the Arduino GSM shield,sends an SMS message + you enter in the serial monitor. Connect your Arduino with the + GSM shield and SIM card, open the serial monitor, and wait for + the "READY" message to appear in the monitor. Next, type a + message to send and press "return". Make sure the serial monitor is set to send a newline when you press return. - + Circuit: - * GSM shield + * GSM shield * SIM card that can send SMS - + created 25 Feb 2012 by Tom Igoe - + This example is in the public domain. - + http://arduino.cc/en/Tutorial/GSMExamplesSendSMS - + */ // Include the GSM library @@ -37,7 +37,7 @@ void setup() while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } - + Serial.println("SMS Messages Sender"); // connection state @@ -45,9 +45,9 @@ void setup() // Start GSM shield // If your SIM has PIN, pass it as a parameter of begin() in quotes - while(notConnected) + while (notConnected) { - if(gsmAccess.begin(PINNUMBER)==GSM_READY) + if (gsmAccess.begin(PINNUMBER) == GSM_READY) notConnected = false; else { @@ -55,7 +55,7 @@ void setup() delay(1000); } } - + Serial.println("GSM initialized"); } @@ -66,7 +66,7 @@ void loop() char remoteNum[20]; // telephone number to send sms readSerial(remoteNum); Serial.println(remoteNum); - + // sms text Serial.print("Now, enter SMS content: "); char txtMsg[200]; @@ -75,11 +75,11 @@ void loop() Serial.println(); Serial.println("Message:"); Serial.println(txtMsg); - + // send the message sms.beginSMS(remoteNum); sms.print(txtMsg); - sms.endSMS(); + sms.endSMS(); Serial.println("\nCOMPLETE!\n"); } @@ -89,7 +89,7 @@ void loop() int readSerial(char result[]) { int i = 0; - while(1) + while (1) { while (Serial.available() > 0) { @@ -100,7 +100,7 @@ int readSerial(char result[]) Serial.flush(); return 0; } - if(inChar!='\r') + if (inChar != '\r') { result[i] = inChar; i++; diff --git a/libraries/GSM/examples/Tools/BandManagement/BandManagement.ino b/libraries/GSM/examples/Tools/BandManagement/BandManagement.ino index 84d8c71c1..a30b236d9 100644 --- a/libraries/GSM/examples/Tools/BandManagement/BandManagement.ino +++ b/libraries/GSM/examples/Tools/BandManagement/BandManagement.ino @@ -1,24 +1,24 @@ /* Band Management - + This sketch, for the Arduino GSM shield, checks the band - currently configured in the modem and allows you to change + currently configured in the modem and allows you to change it. - + Please check http://www.worldtimezone.com/gsm.html Usual configurations: Europe, Africa, Middle East: E-GSM(900)+DCS(1800) USA, Canada, South America: GSM(850)+PCS(1900) Mexico: PCS(1900) Brazil: GSM(850)+E-GSM(900)+DCS(1800)+PCS(1900) - - + + Circuit: - * GSM shield - + * GSM shield + created 12 June 2012 by Javier Zorzano, Scott Fitzgerald - + This example is in the public domain. */ @@ -35,18 +35,18 @@ void setup() while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } - + // Beginning the band manager restarts the modem Serial.println("Restarting modem..."); band.begin(); Serial.println("Modem restarted."); - + }; void loop() { - // Get current band + // Get current band String bandName = band.getBand(); // Get and print band name Serial.print("Current band:"); Serial.println(bandName); @@ -54,25 +54,25 @@ void loop() String newBandName; newBandName = askUser(); // Tell the user what we are about to do… - Serial.print("\nConfiguring band "); - Serial.println(newBandName); - // Change the band - boolean operationSuccess; - operationSuccess = band.setBand(newBandName); - // Tell the user if the operation was OK - if(operationSuccess) - { + Serial.print("\nConfiguring band "); + Serial.println(newBandName); + // Change the band + boolean operationSuccess; + operationSuccess = band.setBand(newBandName); + // Tell the user if the operation was OK + if (operationSuccess) + { Serial.println("Success"); - } + } else - { + { Serial.println("Error while changing band"); - } - - if(operationSuccess) - { - while(true); - } + } + + if (operationSuccess) + { + while (true); + } } // This function offers the user different options @@ -80,41 +80,41 @@ void loop() // The user selects one String askUser() { - String newBand; - Serial.println("Select band:"); - // Print the different options - Serial.println("1 : E-GSM(900)"); - Serial.println("2 : DCS(1800)"); - Serial.println("3 : PCS(1900)"); - Serial.println("4 : E-GSM(900)+DCS(1800) ex: Europe"); - Serial.println("5 : GSM(850)+PCS(1900) Ex: USA, South Am."); - Serial.println("6 : GSM(850)+E-GSM(900)+DCS(1800)+PCS(1900)"); - - // Empty the incoming buffer - while(Serial.available()) - Serial.read(); - - // Wait for an answer, just look at the first character - while(!Serial.available()); - char c= Serial.read(); - if(c=='1') - newBand=GSM_MODE_EGSM; - else if(c=='2') - newBand=GSM_MODE_DCS; - else if(c=='3') - newBand=GSM_MODE_PCS; - else if(c=='4') - newBand=GSM_MODE_EGSM_DCS; - else if(c=='5') - newBand=GSM_MODE_GSM850_PCS; - else if(c=='6') - newBand=GSM_MODE_GSM850_EGSM_DCS_PCS; + String newBand; + Serial.println("Select band:"); + // Print the different options + Serial.println("1 : E-GSM(900)"); + Serial.println("2 : DCS(1800)"); + Serial.println("3 : PCS(1900)"); + Serial.println("4 : E-GSM(900)+DCS(1800) ex: Europe"); + Serial.println("5 : GSM(850)+PCS(1900) Ex: USA, South Am."); + Serial.println("6 : GSM(850)+E-GSM(900)+DCS(1800)+PCS(1900)"); + + // Empty the incoming buffer + while (Serial.available()) + Serial.read(); + + // Wait for an answer, just look at the first character + while (!Serial.available()); + char c = Serial.read(); + if (c == '1') + newBand = GSM_MODE_EGSM; + else if (c == '2') + newBand = GSM_MODE_DCS; + else if (c == '3') + newBand = GSM_MODE_PCS; + else if (c == '4') + newBand = GSM_MODE_EGSM_DCS; + else if (c == '5') + newBand = GSM_MODE_GSM850_PCS; + else if (c == '6') + newBand = GSM_MODE_GSM850_EGSM_DCS_PCS; else - newBand="GSM_MODE_UNDEFINED"; + newBand = "GSM_MODE_UNDEFINED"; return newBand; } - + diff --git a/libraries/GSM/examples/Tools/GsmScanNetworks/GsmScanNetworks.ino b/libraries/GSM/examples/Tools/GsmScanNetworks/GsmScanNetworks.ino index 0e442eb7b..097241586 100644 --- a/libraries/GSM/examples/Tools/GsmScanNetworks/GsmScanNetworks.ino +++ b/libraries/GSM/examples/Tools/GsmScanNetworks/GsmScanNetworks.ino @@ -1,23 +1,23 @@ /* - + GSM Scan Networks - + This example prints out the IMEI number of the modem, - then checks to see if it's connected to a carrier. If so, + then checks to see if it's connected to a carrier. If so, it prints the phone number associated with the card. Then it scans for nearby networks and prints out their signal strengths. - + Circuit: - * GSM shield + * GSM shield * SIM card - + Created 8 Mar 2012 by Tom Igoe, implemented by Javier Carazo Modified 4 Feb 2013 by Scott Fitzgerald - + http://arduino.cc/en/Tutorial/GSMToolsGsmScanNetworks - + This example code is part of the public domain */ @@ -48,15 +48,15 @@ void setup() Serial.println("GSM networks scanner"); scannerNetworks.begin(); - + // connection state boolean notConnected = true; - + // Start GSM shield // If your SIM has PIN, pass it as a parameter of begin() in quotes - while(notConnected) + while (notConnected) { - if(gsmAccess.begin(PINNUMBER)==GSM_READY) + if (gsmAccess.begin(PINNUMBER) == GSM_READY) notConnected = false; else { @@ -64,13 +64,13 @@ void setup() delay(1000); } } - + // get modem parameters // IMEI, modem unique identifier Serial.print("Modem IMEI: "); IMEI = modemTest.getIMEI(); - IMEI.replace("\n",""); - if(IMEI != NULL) + IMEI.replace("\n", ""); + if (IMEI != NULL) Serial.println(IMEI); } @@ -79,11 +79,11 @@ void loop() // scan for existing networks, displays a list of networks Serial.println("Scanning available networks. May take some seconds."); Serial.println(scannerNetworks.readNetworks()); - - // currently connected carrier + + // currently connected carrier Serial.print("Current carrier: "); Serial.println(scannerNetworks.getCurrentCarrier()); - + // returns strength and ber // signal strength in 0-31 scale. 31 means power > 51dBm // BER is the Bit Error Rate. 0-7 scale. 99=not detectable diff --git a/libraries/GSM/examples/Tools/PinManagement/PinManagement.ino b/libraries/GSM/examples/Tools/PinManagement/PinManagement.ino index 654d1b839..011c3be8b 100644 --- a/libraries/GSM/examples/Tools/PinManagement/PinManagement.ino +++ b/libraries/GSM/examples/Tools/PinManagement/PinManagement.ino @@ -1,19 +1,19 @@ /* - - This example enables you to change or remove the PIN number of + + This example enables you to change or remove the PIN number of a SIM card inserted into a GSM shield. - + Circuit: * GSM shield * SIM card - + Created 12 Jun 2012 by David del Peral - - This example code is part of the public domain - + + This example code is part of the public domain + http://arduino.cc/en/Tutorial/GSMToolsPinManagement - + */ // libraries @@ -39,32 +39,32 @@ void setup() while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } - + Serial.println("Change PIN example\n"); PINManager.begin(); - + // check if the SIM have pin lock - while(!auth){ + while (!auth) { int pin_query = PINManager.isPIN(); - if(pin_query == 1) + if (pin_query == 1) { // if SIM is locked, enter PIN code Serial.print("Enter PIN code: "); user_input = readSerial(); // check PIN code - if(PINManager.checkPIN(user_input) == 0) + if (PINManager.checkPIN(user_input) == 0) { auth = true; PINManager.setPINUsed(true); Serial.println(oktext); } else - { + { // if PIN code was incorrected Serial.println("Incorrect PIN. Remember that you have 3 opportunities."); } } - else if(pin_query == -1) + else if (pin_query == -1) { // PIN code is locked, user must enter PUK code Serial.println("PIN locked. Enter PUK code: "); @@ -72,7 +72,7 @@ void setup() Serial.print("Now, enter a new PIN code: "); user_input = readSerial(); // check PUK code - if(PINManager.checkPUK(puk, user_input) == 0) + if (PINManager.checkPUK(puk, user_input) == 0) { auth = true; PINManager.setPINUsed(true); @@ -84,32 +84,32 @@ void setup() Serial.println("Incorrect PUK or invalid new PIN. Try again!."); } } - else if(pin_query == -2) + else if (pin_query == -2) { // the worst case, PIN and PUK are locked Serial.println("PIN & PUK locked. Use PIN2/PUK2 in a mobile phone."); - while(true); + while (true); } else { - // SIM does not requires authetication + // SIM does not requires authetication Serial.println("No pin necessary."); auth = true; } } - + // start GSM shield Serial.print("Checking register in GSM network..."); - if(PINManager.checkReg() == 0) + if (PINManager.checkReg() == 0) Serial.println(oktext); // if you are connect by roaming - else if(PINManager.checkReg() == 1) - Serial.println("ROAMING " + oktext); + else if (PINManager.checkReg() == 1) + Serial.println("ROAMING " + oktext); else { // error connection Serial.println(errortext); - while(true); + while (true); } } @@ -118,19 +118,19 @@ void loop() // Function loop implements pin management user menu // Only if you SIM use pin lock, you can change PIN code // user_op variables save user option - + Serial.println("Choose an option:\n1 - On/Off PIN."); - if(PINManager.getPINUsed()) + if (PINManager.getPINUsed()) Serial.println("2 - Change PIN."); String user_op = readSerial(); - if(user_op == "1") + if (user_op == "1") { Serial.println("Enter your PIN code:"); user_input = readSerial(); // activate/deactivate PIN lock PINManager.switchPIN(user_input); } - else if(user_op == "2" & PINManager.getPINUsed()) + else if (user_op == "2" & PINManager.getPINUsed()) { Serial.println("Enter your actual PIN code:"); String oldPIN = readSerial(); @@ -152,7 +152,7 @@ void loop() String readSerial() { String text = ""; - while(1) + while (1) { while (Serial.available() > 0) { @@ -161,7 +161,7 @@ String readSerial() { return text; } - if(inChar!='\r') + if (inChar != '\r') text += inChar; } } diff --git a/libraries/GSM/examples/Tools/TestGPRS/TestGPRS.ino b/libraries/GSM/examples/Tools/TestGPRS/TestGPRS.ino index ab4a2bed1..14f82a5d6 100644 --- a/libraries/GSM/examples/Tools/TestGPRS/TestGPRS.ino +++ b/libraries/GSM/examples/Tools/TestGPRS/TestGPRS.ino @@ -1,20 +1,20 @@ /* - + This sketch test the GSM shield's ability to connect to a - GPERS network. It asks for APN information through the + GPERS network. It asks for APN information through the serial monitor and tries to connect to arduino.cc. - + Circuit: * GSM shield attached * SIM card with data plan - + Created 18 Jun 2012 by David del Peral - + This example code is part of the public domain - + http://arduino.cc/en/Tutorial/GSMToolsTestGPRS - + */ // libraries @@ -55,53 +55,53 @@ void setup() void loop() { use_proxy = false; - + // start GSM shield // if your SIM has PIN, pass it as a parameter of begin() in quotes Serial.print("Connecting GSM network..."); - if(gsmAccess.begin(PINNUMBER)!=GSM_READY) + if (gsmAccess.begin(PINNUMBER) != GSM_READY) { Serial.println(errortext); - while(true); + while (true); } Serial.println(oktext); - + // read APN introduced by user char apn[50]; Serial.print("Enter your APN: "); readSerial(apn); Serial.println(apn); - + // Read APN login introduced by user char login[50]; Serial.print("Now, enter your login: "); readSerial(login); Serial.println(login); - + // read APN password introduced by user char password[20]; Serial.print("Finally, enter your password: "); readSerial(password); - + // attach GPRS Serial.println("Attaching to GPRS with your APN..."); - if(gprsAccess.attachGPRS(apn, login, password)!=GPRS_READY) + if (gprsAccess.attachGPRS(apn, login, password) != GPRS_READY) { Serial.println(errortext); } - else{ - + else { + Serial.println(oktext); - + // read proxy introduced by user char proxy[100]; Serial.print("If your carrier uses a proxy, enter it, if not press enter: "); readSerial(proxy); Serial.println(proxy); - + // if user introduced a proxy, asks him for proxy port int pport; - if(proxy[0] != '\0'){ + if (proxy[0] != '\0') { // read proxy port introduced by user char proxyport[10]; Serial.print("Enter the proxy port: "); @@ -111,61 +111,61 @@ void loop() use_proxy = true; Serial.println(proxyport); } - + // connection with arduino.cc and realize HTTP request Serial.print("Connecting and sending GET request to arduino.cc..."); int res_connect; - + // if use a proxy, connect with it - if(use_proxy) + if (use_proxy) res_connect = client.connect(proxy, pport); else res_connect = client.connect(url, 80); - + if (res_connect) { // make a HTTP 1.0 GET request (client sends the request) client.print("GET "); - + // if use a proxy, the path is arduino.cc URL - if(use_proxy) + if (use_proxy) client.print(urlproxy); else client.print(path); - + client.println(" HTTP/1.0"); client.println(); Serial.println(oktext); - } + } else { // if you didn't get a connection to the server Serial.println(errortext); } Serial.print("Receiving response..."); - + boolean test = true; - while(test) + while (test) { - // if there are incoming bytes available + // if there are incoming bytes available // from the server, read and check them if (client.available()) { char c = client.read(); response += c; - + // cast response obtained from string to char array - char responsechar[response.length()+1]; - response.toCharArray(responsechar, response.length()+1); - + char responsechar[response.length() + 1]; + response.toCharArray(responsechar, response.length() + 1); + // if response includes a "200 OK" substring - if(strstr(responsechar, "200 OK") != NULL){ + if (strstr(responsechar, "200 OK") != NULL) { Serial.println(oktext); Serial.println("TEST COMPLETE!"); test = false; } } - + // if the server's disconnected, stop the client: if (!client.connected()) { @@ -184,7 +184,7 @@ void loop() int readSerial(char result[]) { int i = 0; - while(1) + while (1) { while (Serial.available() > 0) { @@ -194,7 +194,7 @@ int readSerial(char result[]) result[i] = '\0'; return 0; } - if(inChar!='\r') + if (inChar != '\r') { result[i] = inChar; i++; diff --git a/libraries/GSM/examples/Tools/TestModem/TestModem.ino b/libraries/GSM/examples/Tools/TestModem/TestModem.ino index de61fffaa..271d349ff 100644 --- a/libraries/GSM/examples/Tools/TestModem/TestModem.ino +++ b/libraries/GSM/examples/Tools/TestModem/TestModem.ino @@ -1,21 +1,21 @@ /* - - This example tests to see if the modem of the - GSM shield is working correctly. You do not need + + This example tests to see if the modem of the + GSM shield is working correctly. You do not need a SIM card for this example. - + Circuit: - * GSM shield attached - + * GSM shield attached + Created 12 Jun 2012 by David del Peral modified 21 Nov 2012 by Tom Igoe - + http://arduino.cc/en/Tutorial/GSMToolsTestModem - + This sample code is part of the public domain - + */ // libraries @@ -34,10 +34,10 @@ void setup() while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } - + // start modem test (reset and check response) Serial.print("Starting modem test..."); - if(modem.begin()) + if (modem.begin()) Serial.println("modem.begin() succeeded"); else Serial.println("ERROR, no modem answer."); @@ -48,9 +48,9 @@ void loop() // get modem IMEI Serial.print("Checking IMEI..."); IMEI = modem.getIMEI(); - + // check IMEI response - if(IMEI != NULL) + if (IMEI != NULL) { // show IMEI in serial monitor Serial.println("Modem's IMEI: " + IMEI); @@ -58,7 +58,7 @@ void loop() Serial.print("Resetting modem..."); modem.begin(); // get and check IMEI one more time - if(modem.getIMEI() != NULL) + if (modem.getIMEI() != NULL) { Serial.println("Modem is functoning properly"); } @@ -72,6 +72,6 @@ void loop() Serial.println("Error: Could not get IMEI"); } // do nothing: - while(true); + while (true); } diff --git a/libraries/GSM/examples/Tools/TestWebServer/TestWebServer.ino b/libraries/GSM/examples/Tools/TestWebServer/TestWebServer.ino index 5cc3f8af4..1225ad0b4 100644 --- a/libraries/GSM/examples/Tools/TestWebServer/TestWebServer.ino +++ b/libraries/GSM/examples/Tools/TestWebServer/TestWebServer.ino @@ -1,22 +1,22 @@ /* Basic Web Server - + A simple web server that replies with nothing, but prints the client's request and the server IP address. Circuit: * GSM shield attached - - created + + created by David Cuartielles modified 21 Nov 2012 by Tom Igoe - + http://arduino.cc/en/Tutorial/GSMToolsTestWebServer - + This example code is part of the public domain */ - #include +#include // PIN Number #define PINNUMBER "" @@ -33,7 +33,7 @@ GSM gsmAccess; // include a 'true' parameter for debug enabled GSMServer server(80); // port 80 (http default) // timeout -const unsigned long __TIMEOUT__ = 10*1000; +const unsigned long __TIMEOUT__ = 10 * 1000; void setup() { @@ -49,10 +49,10 @@ void setup() // Start GSM shield // If your SIM has PIN, pass it as a parameter of begin() in quotes - while(!connected) + while (!connected) { - if((gsmAccess.begin(PINNUMBER)==GSM_READY) & - (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY)) + if ((gsmAccess.begin(PINNUMBER) == GSM_READY) & + (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) connected = true; else { @@ -72,14 +72,14 @@ void setup() Serial.println(LocalIP); } -void loop(){ +void loop() { GSMClient client = server.available(); - - if (client) { - if (client.available()) { - Serial.write(client.read()); - } -} + + if (client) { + if (client.available()) { + Serial.write(client.read()); + } + } } diff --git a/libraries/LiquidCrystal/examples/Autoscroll/Autoscroll.ino b/libraries/LiquidCrystal/examples/Autoscroll/Autoscroll.ino index 1127d8f15..0acb3affc 100644 --- a/libraries/LiquidCrystal/examples/Autoscroll/Autoscroll.ino +++ b/libraries/LiquidCrystal/examples/Autoscroll/Autoscroll.ino @@ -1,14 +1,14 @@ /* LiquidCrystal Library - Autoscroll - + Demonstrates the use a 16x2 LCD display. The LiquidCrystal - library works with all LCD displays that are compatible with the + library works with all LCD displays that are compatible with the Hitachi HD44780 driver. There are many of them out there, and you can usually tell them by the 16-pin interface. - + This sketch demonstrates the use of the autoscroll() and noAutoscroll() functions to make new text scroll or not. - + The circuit: * LCD RS pin to digital pin 12 * LCD Enable pin to digital pin 11 @@ -20,16 +20,16 @@ * 10K resistor: * ends to +5V and ground * wiper to LCD VO pin (pin 3) - + Library originally added 18 Apr 2008 by David A. Mellis library modified 5 Jul 2009 by Limor Fried (http://www.ladyada.net) example added 9 Jul 2009 - by Tom Igoe + by Tom Igoe modified 22 Nov 2010 by Tom Igoe - + This example code is in the public domain. http://arduino.cc/en/Tutorial/LiquidCrystalAutoscroll @@ -43,8 +43,8 @@ LiquidCrystal lcd(12, 11, 5, 4, 3, 2); void setup() { - // set up the LCD's number of columns and rows: - lcd.begin(16,2); + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); } void loop() { @@ -52,12 +52,12 @@ void loop() { lcd.setCursor(0, 0); // print from 0 to 9: for (int thisChar = 0; thisChar < 10; thisChar++) { - lcd.print(thisChar); - delay(500); + lcd.print(thisChar); + delay(500); } // set the cursor to (16,1): - lcd.setCursor(16,1); + lcd.setCursor(16, 1); // set the display to automatically scroll: lcd.autoscroll(); // print from 0 to 9: @@ -67,7 +67,7 @@ void loop() { } // turn off automatic scrolling lcd.noAutoscroll(); - + // clear screen for the next loop: lcd.clear(); } diff --git a/libraries/LiquidCrystal/examples/Blink/Blink.ino b/libraries/LiquidCrystal/examples/Blink/Blink.ino index 9667b5d6f..856d522c5 100644 --- a/libraries/LiquidCrystal/examples/Blink/Blink.ino +++ b/libraries/LiquidCrystal/examples/Blink/Blink.ino @@ -1,14 +1,14 @@ /* LiquidCrystal Library - Blink - + Demonstrates the use a 16x2 LCD display. The LiquidCrystal - library works with all LCD displays that are compatible with the + library works with all LCD displays that are compatible with the Hitachi HD44780 driver. There are many of them out there, and you can usually tell them by the 16-pin interface. - - This sketch prints "Hello World!" to the LCD and makes the + + This sketch prints "Hello World!" to the LCD and makes the cursor block blink. - + The circuit: * LCD RS pin to digital pin 12 * LCD Enable pin to digital pin 11 @@ -20,20 +20,20 @@ * 10K resistor: * ends to +5V and ground * wiper to LCD VO pin (pin 3) - + Library originally added 18 Apr 2008 by David A. Mellis library modified 5 Jul 2009 by Limor Fried (http://www.ladyada.net) example added 9 Jul 2009 - by Tom Igoe + by Tom Igoe modified 22 Nov 2010 by Tom Igoe - + This example code is in the public domain. http://arduino.cc/en/Tutorial/LiquidCrystalBlink - + */ // include the library code: @@ -43,7 +43,7 @@ LiquidCrystal lcd(12, 11, 5, 4, 3, 2); void setup() { - // set up the LCD's number of columns and rows: + // set up the LCD's number of columns and rows: lcd.begin(16, 2); // Print a message to the LCD. lcd.print("hello, world!"); @@ -53,7 +53,7 @@ void loop() { // Turn off the blinking cursor: lcd.noBlink(); delay(3000); - // Turn on the blinking cursor: + // Turn on the blinking cursor: lcd.blink(); delay(3000); } diff --git a/libraries/LiquidCrystal/examples/Cursor/Cursor.ino b/libraries/LiquidCrystal/examples/Cursor/Cursor.ino index 05862a49f..5f68d917d 100644 --- a/libraries/LiquidCrystal/examples/Cursor/Cursor.ino +++ b/libraries/LiquidCrystal/examples/Cursor/Cursor.ino @@ -1,15 +1,15 @@ /* LiquidCrystal Library - Cursor - + Demonstrates the use a 16x2 LCD display. The LiquidCrystal - library works with all LCD displays that are compatible with the + library works with all LCD displays that are compatible with the Hitachi HD44780 driver. There are many of them out there, and you can usually tell them by the 16-pin interface. - + This sketch prints "Hello World!" to the LCD and uses the cursor() and noCursor() methods to turn on and off the cursor. - + The circuit: * LCD RS pin to digital pin 12 * LCD Enable pin to digital pin 11 @@ -21,13 +21,13 @@ * 10K resistor: * ends to +5V and ground * wiper to LCD VO pin (pin 3) - + Library originally added 18 Apr 2008 by David A. Mellis library modified 5 Jul 2009 by Limor Fried (http://www.ladyada.net) example added 9 Jul 2009 - by Tom Igoe + by Tom Igoe modified 22 Nov 2010 by Tom Igoe @@ -44,7 +44,7 @@ LiquidCrystal lcd(12, 11, 5, 4, 3, 2); void setup() { - // set up the LCD's number of columns and rows: + // set up the LCD's number of columns and rows: lcd.begin(16, 2); // Print a message to the LCD. lcd.print("hello, world!"); @@ -54,7 +54,7 @@ void loop() { // Turn off the cursor: lcd.noCursor(); delay(500); - // Turn on the cursor: + // Turn on the cursor: lcd.cursor(); delay(500); } diff --git a/libraries/LiquidCrystal/examples/CustomCharacter/CustomCharacter.ino b/libraries/LiquidCrystal/examples/CustomCharacter/CustomCharacter.ino index d3ce47924..3a96488b2 100644 --- a/libraries/LiquidCrystal/examples/CustomCharacter/CustomCharacter.ino +++ b/libraries/LiquidCrystal/examples/CustomCharacter/CustomCharacter.ino @@ -1,14 +1,14 @@ /* LiquidCrystal Library - Custom Characters - - Demonstrates how to add custom characters on an LCD display. - The LiquidCrystal library works with all LCD displays that are - compatible with the Hitachi HD44780 driver. There are many of + + Demonstrates how to add custom characters on an LCD display. + The LiquidCrystal library works with all LCD displays that are + compatible with the Hitachi HD44780 driver. There are many of them out there, and you can usually tell them by the 16-pin interface. - + This sketch prints "I Arduino!" and a little dancing man to the LCD. - + The circuit: * LCD RS pin to digital pin 12 * LCD Enable pin to digital pin 11 @@ -21,18 +21,18 @@ * ends to +5V and ground * wiper to LCD VO pin (pin 3) * 10K poterntiometer on pin A0 - + created21 Mar 2011 by Tom Igoe Based on Adafruit's example at https://github.com/adafruit/SPI_VFD/blob/master/examples/createChar/createChar.pde - + This example code is in the public domain. http://www.arduino.cc/en/Tutorial/LiquidCrystal - + Also useful: http://icontexto.com/charactercreator/ - + */ // include the library code: @@ -104,14 +104,14 @@ void setup() { // create a new character lcd.createChar(2, frownie); // create a new character - lcd.createChar(3, armsDown); + lcd.createChar(3, armsDown); // create a new character - lcd.createChar(4, armsUp); + lcd.createChar(4, armsUp); - // set up the lcd's number of columns and rows: + // set up the lcd's number of columns and rows: lcd.begin(16, 2); // Print a message to the lcd. - lcd.print("I "); + lcd.print("I "); lcd.write(0); lcd.print(" Arduino! "); lcd.write(1); @@ -131,7 +131,7 @@ void loop() { lcd.setCursor(4, 1); // draw him arms up: lcd.write(4); - delay(delayTime); + delay(delayTime); } diff --git a/libraries/LiquidCrystal/examples/Display/Display.ino b/libraries/LiquidCrystal/examples/Display/Display.ino index a85effb44..5c9e67cb3 100644 --- a/libraries/LiquidCrystal/examples/Display/Display.ino +++ b/libraries/LiquidCrystal/examples/Display/Display.ino @@ -1,15 +1,15 @@ /* LiquidCrystal Library - display() and noDisplay() - + Demonstrates the use a 16x2 LCD display. The LiquidCrystal - library works with all LCD displays that are compatible with the + library works with all LCD displays that are compatible with the Hitachi HD44780 driver. There are many of them out there, and you can usually tell them by the 16-pin interface. - - This sketch prints "Hello World!" to the LCD and uses the + + This sketch prints "Hello World!" to the LCD and uses the display() and noDisplay() functions to turn on and off the display. - + The circuit: * LCD RS pin to digital pin 12 * LCD Enable pin to digital pin 11 @@ -21,13 +21,13 @@ * 10K resistor: * ends to +5V and ground * wiper to LCD VO pin (pin 3) - + Library originally added 18 Apr 2008 by David A. Mellis library modified 5 Jul 2009 by Limor Fried (http://www.ladyada.net) example added 9 Jul 2009 - by Tom Igoe + by Tom Igoe modified 22 Nov 2010 by Tom Igoe @@ -44,7 +44,7 @@ LiquidCrystal lcd(12, 11, 5, 4, 3, 2); void setup() { - // set up the LCD's number of columns and rows: + // set up the LCD's number of columns and rows: lcd.begin(16, 2); // Print a message to the LCD. lcd.print("hello, world!"); @@ -54,7 +54,7 @@ void loop() { // Turn off the display: lcd.noDisplay(); delay(500); - // Turn on the display: + // Turn on the display: lcd.display(); delay(500); } diff --git a/libraries/LiquidCrystal/examples/HelloWorld/HelloWorld.ino b/libraries/LiquidCrystal/examples/HelloWorld/HelloWorld.ino index e99957d9a..ec495b306 100644 --- a/libraries/LiquidCrystal/examples/HelloWorld/HelloWorld.ino +++ b/libraries/LiquidCrystal/examples/HelloWorld/HelloWorld.ino @@ -1,14 +1,14 @@ /* LiquidCrystal Library - Hello World - + Demonstrates the use a 16x2 LCD display. The LiquidCrystal - library works with all LCD displays that are compatible with the + library works with all LCD displays that are compatible with the Hitachi HD44780 driver. There are many of them out there, and you can usually tell them by the 16-pin interface. - + This sketch prints "Hello World!" to the LCD and shows the time. - + The circuit: * LCD RS pin to digital pin 12 * LCD Enable pin to digital pin 11 @@ -20,7 +20,7 @@ * 10K resistor: * ends to +5V and ground * wiper to LCD VO pin (pin 3) - + Library originally added 18 Apr 2008 by David A. Mellis library modified 5 Jul 2009 @@ -29,7 +29,7 @@ by Tom Igoe modified 22 Nov 2010 by Tom Igoe - + This example code is in the public domain. http://www.arduino.cc/en/Tutorial/LiquidCrystal @@ -42,7 +42,7 @@ LiquidCrystal lcd(12, 11, 5, 4, 3, 2); void setup() { - // set up the LCD's number of columns and rows: + // set up the LCD's number of columns and rows: lcd.begin(16, 2); // Print a message to the LCD. lcd.print("hello, world!"); @@ -53,6 +53,6 @@ void loop() { // (note: line 1 is the second row, since counting begins with 0): lcd.setCursor(0, 1); // print the number of seconds since reset: - lcd.print(millis()/1000); + lcd.print(millis() / 1000); } diff --git a/libraries/LiquidCrystal/examples/Scroll/Scroll.ino b/libraries/LiquidCrystal/examples/Scroll/Scroll.ino index 0d6d8dcf8..3e4479177 100644 --- a/libraries/LiquidCrystal/examples/Scroll/Scroll.ino +++ b/libraries/LiquidCrystal/examples/Scroll/Scroll.ino @@ -1,15 +1,15 @@ /* LiquidCrystal Library - scrollDisplayLeft() and scrollDisplayRight() - + Demonstrates the use a 16x2 LCD display. The LiquidCrystal - library works with all LCD displays that are compatible with the + library works with all LCD displays that are compatible with the Hitachi HD44780 driver. There are many of them out there, and you can usually tell them by the 16-pin interface. - + This sketch prints "Hello World!" to the LCD and uses the scrollDisplayLeft() and scrollDisplayRight() methods to scroll the text. - + The circuit: * LCD RS pin to digital pin 12 * LCD Enable pin to digital pin 11 @@ -21,18 +21,18 @@ * 10K resistor: * ends to +5V and ground * wiper to LCD VO pin (pin 3) - + Library originally added 18 Apr 2008 by David A. Mellis library modified 5 Jul 2009 by Limor Fried (http://www.ladyada.net) example added 9 Jul 2009 - by Tom Igoe + by Tom Igoe modified 22 Nov 2010 by Tom Igoe - + This example code is in the public domain. - + http://arduino.cc/en/Tutorial/LiquidCrystalScroll */ @@ -44,7 +44,7 @@ LiquidCrystal lcd(12, 11, 5, 4, 3, 2); void setup() { - // set up the LCD's number of columns and rows: + // set up the LCD's number of columns and rows: lcd.begin(16, 2); // Print a message to the LCD. lcd.print("hello, world!"); @@ -52,11 +52,11 @@ void setup() { } void loop() { - // scroll 13 positions (string length) to the left + // scroll 13 positions (string length) to the left // to move it offscreen left: for (int positionCounter = 0; positionCounter < 13; positionCounter++) { // scroll one position left: - lcd.scrollDisplayLeft(); + lcd.scrollDisplayLeft(); // wait a bit: delay(150); } @@ -65,20 +65,20 @@ void loop() { // to move it offscreen right: for (int positionCounter = 0; positionCounter < 29; positionCounter++) { // scroll one position right: - lcd.scrollDisplayRight(); + lcd.scrollDisplayRight(); // wait a bit: delay(150); } - - // scroll 16 positions (display length + string length) to the left - // to move it back to center: + + // scroll 16 positions (display length + string length) to the left + // to move it back to center: for (int positionCounter = 0; positionCounter < 16; positionCounter++) { // scroll one position left: - lcd.scrollDisplayLeft(); + lcd.scrollDisplayLeft(); // wait a bit: delay(150); } - + // delay at the end of the full loop: delay(1000); diff --git a/libraries/LiquidCrystal/examples/SerialDisplay/SerialDisplay.ino b/libraries/LiquidCrystal/examples/SerialDisplay/SerialDisplay.ino index a6f8f40bc..5838dc5a0 100644 --- a/libraries/LiquidCrystal/examples/SerialDisplay/SerialDisplay.ino +++ b/libraries/LiquidCrystal/examples/SerialDisplay/SerialDisplay.ino @@ -1,14 +1,14 @@ /* LiquidCrystal Library - Serial Input - + Demonstrates the use a 16x2 LCD display. The LiquidCrystal - library works with all LCD displays that are compatible with the + library works with all LCD displays that are compatible with the Hitachi HD44780 driver. There are many of them out there, and you can usually tell them by the 16-pin interface. - - This sketch displays text sent over the serial port + + This sketch displays text sent over the serial port (e.g. from the Serial Monitor) on an attached LCD. - + The circuit: * LCD RS pin to digital pin 12 * LCD Enable pin to digital pin 11 @@ -20,18 +20,18 @@ * 10K resistor: * ends to +5V and ground * wiper to LCD VO pin (pin 3) - + Library originally added 18 Apr 2008 by David A. Mellis library modified 5 Jul 2009 by Limor Fried (http://www.ladyada.net) example added 9 Jul 2009 - by Tom Igoe + by Tom Igoe modified 22 Nov 2010 by Tom Igoe - + This example code is in the public domain. - + http://arduino.cc/en/Tutorial/LiquidCrystalSerial */ @@ -41,8 +41,8 @@ // initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 5, 4, 3, 2); -void setup(){ - // set up the LCD's number of columns and rows: +void setup() { + // set up the LCD's number of columns and rows: lcd.begin(16, 2); // initialize the serial communications: Serial.begin(9600); diff --git a/libraries/LiquidCrystal/examples/TextDirection/TextDirection.ino b/libraries/LiquidCrystal/examples/TextDirection/TextDirection.ino index cabd8ea8f..3bb8695b3 100644 --- a/libraries/LiquidCrystal/examples/TextDirection/TextDirection.ino +++ b/libraries/LiquidCrystal/examples/TextDirection/TextDirection.ino @@ -1,40 +1,40 @@ - /* - LiquidCrystal Library - TextDirection - - Demonstrates the use a 16x2 LCD display. The LiquidCrystal - library works with all LCD displays that are compatible with the - Hitachi HD44780 driver. There are many of them out there, and you - can usually tell them by the 16-pin interface. - - This sketch demonstrates how to use leftToRight() and rightToLeft() - to move the cursor. - - The circuit: - * LCD RS pin to digital pin 12 - * LCD Enable pin to digital pin 11 - * LCD D4 pin to digital pin 5 - * LCD D5 pin to digital pin 4 - * LCD D6 pin to digital pin 3 - * LCD D7 pin to digital pin 2 - * LCD R/W pin to ground - * 10K resistor: - * ends to +5V and ground - * wiper to LCD VO pin (pin 3) - - Library originally added 18 Apr 2008 - by David A. Mellis - library modified 5 Jul 2009 - by Limor Fried (http://www.ladyada.net) - example added 9 Jul 2009 - by Tom Igoe - modified 22 Nov 2010 - by Tom Igoe - - This example code is in the public domain. - - http://arduino.cc/en/Tutorial/LiquidCrystalTextDirection - - */ +/* +LiquidCrystal Library - TextDirection + +Demonstrates the use a 16x2 LCD display. The LiquidCrystal +library works with all LCD displays that are compatible with the +Hitachi HD44780 driver. There are many of them out there, and you +can usually tell them by the 16-pin interface. + +This sketch demonstrates how to use leftToRight() and rightToLeft() +to move the cursor. + +The circuit: +* LCD RS pin to digital pin 12 +* LCD Enable pin to digital pin 11 +* LCD D4 pin to digital pin 5 +* LCD D5 pin to digital pin 4 +* LCD D6 pin to digital pin 3 +* LCD D7 pin to digital pin 2 +* LCD R/W pin to ground +* 10K resistor: +* ends to +5V and ground +* wiper to LCD VO pin (pin 3) + +Library originally added 18 Apr 2008 +by David A. Mellis +library modified 5 Jul 2009 +by Limor Fried (http://www.ladyada.net) +example added 9 Jul 2009 +by Tom Igoe +modified 22 Nov 2010 +by Tom Igoe + +This example code is in the public domain. + +http://arduino.cc/en/Tutorial/LiquidCrystalTextDirection + +*/ // include the library code: #include @@ -45,7 +45,7 @@ LiquidCrystal lcd(12, 11, 5, 4, 3, 2); int thisChar = 'a'; void setup() { - // set up the LCD's number of columns and rows: + // set up the LCD's number of columns and rows: lcd.begin(16, 2); // turn on the cursor: lcd.cursor(); @@ -55,17 +55,17 @@ void loop() { // reverse directions at 'm': if (thisChar == 'm') { // go right for the next letter - lcd.rightToLeft(); + lcd.rightToLeft(); } // reverse again at 's': if (thisChar == 's') { // go left for the next letter - lcd.leftToRight(); + lcd.leftToRight(); } // reset at 'z': if (thisChar > 'z') { // go to (0,0): - lcd.home(); + lcd.home(); // start again at 0 thisChar = 'a'; } diff --git a/libraries/LiquidCrystal/examples/setCursor/setCursor.ino b/libraries/LiquidCrystal/examples/setCursor/setCursor.ino index e45c49181..689f3297e 100644 --- a/libraries/LiquidCrystal/examples/setCursor/setCursor.ino +++ b/libraries/LiquidCrystal/examples/setCursor/setCursor.ino @@ -1,14 +1,14 @@ /* LiquidCrystal Library - setCursor - + Demonstrates the use a 16x2 LCD display. The LiquidCrystal - library works with all LCD displays that are compatible with the + library works with all LCD displays that are compatible with the Hitachi HD44780 driver. There are many of them out there, and you can usually tell them by the 16-pin interface. - + This sketch prints to all the positions of the LCD using the setCursor(0 method: - + The circuit: * LCD RS pin to digital pin 12 * LCD Enable pin to digital pin 11 @@ -20,18 +20,18 @@ * 10K resistor: * ends to +5V and ground * wiper to LCD VO pin (pin 3) - + Library originally added 18 Apr 2008 by David A. Mellis library modified 5 Jul 2009 by Limor Fried (http://www.ladyada.net) example added 9 Jul 2009 - by Tom Igoe + by Tom Igoe modified 22 Nov 2010 by Tom Igoe - + This example code is in the public domain. - + http://arduino.cc/en/Tutorial/LiquidCrystalSetCursor */ @@ -48,8 +48,8 @@ const int numCols = 16; LiquidCrystal lcd(12, 11, 5, 4, 3, 2); void setup() { - // set up the LCD's number of columns and rows: - lcd.begin(numCols,numRows); + // set up the LCD's number of columns and rows: + lcd.begin(numCols, numRows); } void loop() { @@ -60,7 +60,7 @@ void loop() { // loop over the rows: for (int thisRow = 0; thisRow < numCols; thisRow++) { // set the cursor position: - lcd.setCursor(thisRow,thisCol); + lcd.setCursor(thisRow, thisCol); // print the letter: lcd.write(thisLetter); delay(200); diff --git a/libraries/RobotIRremote/examples/IRrecord/IRrecord.ino b/libraries/RobotIRremote/examples/IRrecord/IRrecord.ino index caf86de3d..ee5621562 100644 --- a/libraries/RobotIRremote/examples/IRrecord/IRrecord.ino +++ b/libraries/RobotIRremote/examples/IRrecord/IRrecord.ino @@ -1,5 +1,5 @@ /* - * IRrecord: record and play back IR signals as a minimal + * IRrecord: record and play back IR signals as a minimal * An IR detector/demodulator must be connected to the input RECV_PIN. * An IR LED must be connected to the output PWM pin 3. * A button must be connected to the input BUTTON_PIN; this is the @@ -56,12 +56,12 @@ void storeCode(decode_results *results) { for (int i = 1; i <= codeLen; i++) { if (i % 2) { // Mark - rawCodes[i - 1] = results->rawbuf[i]*USECPERTICK - MARK_EXCESS; + rawCodes[i - 1] = results->rawbuf[i] * USECPERTICK - MARK_EXCESS; Serial.print(" m"); - } + } else { // Space - rawCodes[i - 1] = results->rawbuf[i]*USECPERTICK + MARK_EXCESS; + rawCodes[i - 1] = results->rawbuf[i] * USECPERTICK + MARK_EXCESS; Serial.print(" s"); } Serial.print(rawCodes[i - 1], DEC); @@ -76,16 +76,16 @@ void storeCode(decode_results *results) { Serial.println("repeat; ignoring."); return; } - } + } else if (codeType == SONY) { Serial.print("Received SONY: "); - } + } else if (codeType == RC5) { Serial.print("Received RC5: "); - } + } else if (codeType == RC6) { Serial.print("Received RC6: "); - } + } else { Serial.print("Unexpected codeType "); Serial.print(codeType, DEC); @@ -102,18 +102,18 @@ void sendCode(int repeat) { if (repeat) { irsend.sendNEC(REPEAT, codeLen); Serial.println("Sent NEC repeat"); - } + } else { irsend.sendNEC(codeValue, codeLen); Serial.print("Sent NEC "); Serial.println(codeValue, HEX); } - } + } else if (codeType == SONY) { irsend.sendSony(codeValue, codeLen); Serial.print("Sent Sony "); Serial.println(codeValue, HEX); - } + } else if (codeType == RC5 || codeType == RC6) { if (!repeat) { // Flip the toggle bit for a new button press @@ -126,13 +126,13 @@ void sendCode(int repeat) { Serial.print("Sent RC5 "); Serial.println(codeValue, HEX); irsend.sendRC5(codeValue, codeLen); - } + } else { irsend.sendRC6(codeValue, codeLen); Serial.print("Sent RC6 "); Serial.println(codeValue, HEX); } - } + } else if (codeType == UNKNOWN /* i.e. raw */) { // Assume 38 KHz irsend.sendRaw(rawCodes, codeLen, 38); @@ -156,7 +156,7 @@ void loop() { sendCode(lastButtonState == buttonState); digitalWrite(STATUS_PIN, LOW); delay(50); // Wait a bit between retransmissions - } + } else if (irrecv.decode(&results)) { digitalWrite(STATUS_PIN, HIGH); storeCode(&results); diff --git a/libraries/RobotIRremote/examples/IRrecvDump/IRrecvDump.ino b/libraries/RobotIRremote/examples/IRrecvDump/IRrecvDump.ino index 6afcb0fbb..e2fa0e9ec 100644 --- a/libraries/RobotIRremote/examples/IRrecvDump/IRrecvDump.ino +++ b/libraries/RobotIRremote/examples/IRrecvDump/IRrecvDump.ino @@ -30,26 +30,26 @@ void dump(decode_results *results) { int count = results->rawlen; if (results->decode_type == UNKNOWN) { Serial.print("Unknown encoding: "); - } + } else if (results->decode_type == NEC) { Serial.print("Decoded NEC: "); - } + } else if (results->decode_type == SONY) { Serial.print("Decoded SONY: "); - } + } else if (results->decode_type == RC5) { Serial.print("Decoded RC5: "); - } + } else if (results->decode_type == RC6) { Serial.print("Decoded RC6: "); } - else if (results->decode_type == PANASONIC) { + else if (results->decode_type == PANASONIC) { Serial.print("Decoded PANASONIC - Address: "); - Serial.print(results->panasonicAddress,HEX); + Serial.print(results->panasonicAddress, HEX); Serial.print(" Value: "); } else if (results->decode_type == JVC) { - Serial.print("Decoded JVC: "); + Serial.print("Decoded JVC: "); } Serial.print(results->value, HEX); Serial.print(" ("); @@ -62,7 +62,7 @@ void dump(decode_results *results) { for (int i = 0; i < count; i++) { if ((i % 2) == 1) { Serial.print(results->rawbuf[i]*USECPERTICK, DEC); - } + } else { Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC); } diff --git a/libraries/RobotIRremote/examples/IRrelay/IRrelay.ino b/libraries/RobotIRremote/examples/IRrelay/IRrelay.ino index 046fb5fa6..1de058f26 100644 --- a/libraries/RobotIRremote/examples/IRrelay/IRrelay.ino +++ b/libraries/RobotIRremote/examples/IRrelay/IRrelay.ino @@ -23,17 +23,17 @@ void dump(decode_results *results) { int count = results->rawlen; if (results->decode_type == UNKNOWN) { Serial.println("Could not decode message"); - } + } else { if (results->decode_type == NEC) { Serial.print("Decoded NEC: "); - } + } else if (results->decode_type == SONY) { Serial.print("Decoded SONY: "); - } + } else if (results->decode_type == RC5) { Serial.print("Decoded RC5: "); - } + } else if (results->decode_type == RC6) { Serial.print("Decoded RC6: "); } @@ -49,7 +49,7 @@ void dump(decode_results *results) { for (int i = 0; i < count; i++) { if ((i % 2) == 1) { Serial.print(results->rawbuf[i]*USECPERTICK, DEC); - } + } else { Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC); } @@ -62,7 +62,7 @@ void setup() { pinMode(RELAY_PIN, OUTPUT); pinMode(13, OUTPUT); - Serial.begin(9600); + Serial.begin(9600); irrecv.enableIRIn(); // Start the receiver } @@ -79,7 +79,7 @@ void loop() { digitalWrite(13, on ? HIGH : LOW); dump(&results); } - last = millis(); + last = millis(); irrecv.resume(); // Receive the next value } } diff --git a/libraries/RobotIRremote/examples/IRtest/IRtest.ino b/libraries/RobotIRremote/examples/IRtest/IRtest.ino index 4845a4a4d..f8369d6cf 100644 --- a/libraries/RobotIRremote/examples/IRtest/IRtest.ino +++ b/libraries/RobotIRremote/examples/IRtest/IRtest.ino @@ -21,17 +21,17 @@ void dump(decode_results *results) { int count = results->rawlen; if (results->decode_type == UNKNOWN) { Serial.println("Could not decode message"); - } + } else { if (results->decode_type == NEC) { Serial.print("Decoded NEC: "); - } + } else if (results->decode_type == SONY) { Serial.print("Decoded SONY: "); - } + } else if (results->decode_type == RC5) { Serial.print("Decoded RC5: "); - } + } else if (results->decode_type == RC6) { Serial.print("Decoded RC6: "); } @@ -47,7 +47,7 @@ void dump(decode_results *results) { for (int i = 0; i < count; i++) { if ((i % 2) == 1) { Serial.print(results->rawbuf[i]*USECPERTICK, DEC); - } + } else { Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC); } @@ -59,61 +59,61 @@ void dump(decode_results *results) { IRrecv irrecv(0); decode_results results; -class IRsendDummy : -public IRsend +class IRsendDummy : + public IRsend { -public: - // For testing, just log the marks/spaces + public: + // For testing, just log the marks/spaces #define SENDLOG_LEN 128 - int sendlog[SENDLOG_LEN]; - int sendlogcnt; - IRsendDummy() : - IRsend() { - } - void reset() { - sendlogcnt = 0; - } - void mark(int time) { - sendlog[sendlogcnt] = time; - if (sendlogcnt < SENDLOG_LEN) sendlogcnt++; - } - void space(int time) { - sendlog[sendlogcnt] = -time; - if (sendlogcnt < SENDLOG_LEN) sendlogcnt++; - } - // Copies the dummy buf into the interrupt buf - void useDummyBuf() { - int last = SPACE; - irparams.rcvstate = STATE_STOP; - irparams.rawlen = 1; // Skip the gap - for (int i = 0 ; i < sendlogcnt; i++) { - if (sendlog[i] < 0) { - if (last == MARK) { - // New space - irparams.rawbuf[irparams.rawlen++] = (-sendlog[i] - MARK_EXCESS) / USECPERTICK; - last = SPACE; - } - else { - // More space - irparams.rawbuf[irparams.rawlen - 1] += -sendlog[i] / USECPERTICK; + int sendlog[SENDLOG_LEN]; + int sendlogcnt; + IRsendDummy() : + IRsend() { + } + void reset() { + sendlogcnt = 0; + } + void mark(int time) { + sendlog[sendlogcnt] = time; + if (sendlogcnt < SENDLOG_LEN) sendlogcnt++; + } + void space(int time) { + sendlog[sendlogcnt] = -time; + if (sendlogcnt < SENDLOG_LEN) sendlogcnt++; + } + // Copies the dummy buf into the interrupt buf + void useDummyBuf() { + int last = SPACE; + irparams.rcvstate = STATE_STOP; + irparams.rawlen = 1; // Skip the gap + for (int i = 0 ; i < sendlogcnt; i++) { + if (sendlog[i] < 0) { + if (last == MARK) { + // New space + irparams.rawbuf[irparams.rawlen++] = (-sendlog[i] - MARK_EXCESS) / USECPERTICK; + last = SPACE; + } + else { + // More space + irparams.rawbuf[irparams.rawlen - 1] += -sendlog[i] / USECPERTICK; + } } - } - else if (sendlog[i] > 0) { - if (last == SPACE) { - // New mark - irparams.rawbuf[irparams.rawlen++] = (sendlog[i] + MARK_EXCESS) / USECPERTICK; - last = MARK; - } - else { - // More mark - irparams.rawbuf[irparams.rawlen - 1] += sendlog[i] / USECPERTICK; + else if (sendlog[i] > 0) { + if (last == SPACE) { + // New mark + irparams.rawbuf[irparams.rawlen++] = (sendlog[i] + MARK_EXCESS) / USECPERTICK; + last = MARK; + } + else { + // More mark + irparams.rawbuf[irparams.rawlen - 1] += sendlog[i] / USECPERTICK; + } } } + if (irparams.rawlen % 2) { + irparams.rawlen--; // Remove trailing space + } } - if (irparams.rawlen % 2) { - irparams.rawlen--; // Remove trailing space - } - } }; IRsendDummy irsenddummy; @@ -125,12 +125,12 @@ void verify(unsigned long val, int bits, int type) { Serial.print(val, HEX); if (results.value == val && results.bits == bits && results.decode_type == type) { Serial.println(": OK"); - } + } else { Serial.println(": Error"); dump(&results); } -} +} void testNEC(unsigned long val, int bits) { irsenddummy.reset(); diff --git a/libraries/RobotIRremote/examples/IRtest2/IRtest2.ino b/libraries/RobotIRremote/examples/IRtest2/IRtest2.ino index 56b8a4d2a..13bc901b7 100644 --- a/libraries/RobotIRremote/examples/IRtest2/IRtest2.ino +++ b/libraries/RobotIRremote/examples/IRtest2/IRtest2.ino @@ -20,7 +20,7 @@ * The test software automatically decides which board is the sender and which is * the receiver by looking for an input on the send pin, which will indicate * the sender. You should hook the serial port to the receiver for debugging. - * + * * Copyright 2010 Ken Shirriff * http://arcfn.com */ @@ -51,7 +51,7 @@ void setup() pinMode(LED_PIN, OUTPUT); digitalWrite(LED_PIN, LOW); Serial.println("Receiver mode"); - } + } else { mode = SENDER; Serial.println("Sender mode"); @@ -64,7 +64,7 @@ void setup() void waitForGap(int gap) { Serial.println("Waiting for gap"); while (1) { - while (digitalRead(RECV_PIN) == LOW) { + while (digitalRead(RECV_PIN) == LOW) { } unsigned long time = millis(); while (digitalRead(RECV_PIN) == HIGH) { @@ -81,17 +81,17 @@ void dump(decode_results *results) { int count = results->rawlen; if (results->decode_type == UNKNOWN) { Serial.println("Could not decode message"); - } + } else { if (results->decode_type == NEC) { Serial.print("Decoded NEC: "); - } + } else if (results->decode_type == SONY) { Serial.print("Decoded SONY: "); - } + } else if (results->decode_type == RC5) { Serial.print("Decoded RC5: "); - } + } else if (results->decode_type == RC6) { Serial.print("Decoded RC6: "); } @@ -107,7 +107,7 @@ void dump(decode_results *results) { for (int i = 0; i < count; i++) { if ((i % 2) == 1) { Serial.print(results->rawbuf[i]*USECPERTICK, DEC); - } + } else { Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC); } @@ -130,22 +130,22 @@ void test(char *label, int type, unsigned long value, int bits) { Serial.println(label); if (type == NEC) { irsend.sendNEC(value, bits); - } + } else if (type == SONY) { irsend.sendSony(value, bits); - } + } else if (type == RC5) { irsend.sendRC5(value, bits); - } + } else if (type == RC6) { irsend.sendRC6(value, bits); - } + } else { Serial.print(label); Serial.println("Bad type!"); } delay(200); - } + } else if (mode == RECEIVER) { irrecv.resume(); // Receive the next value unsigned long max_time = millis() + 30000; @@ -164,7 +164,7 @@ void test(char *label, int type, unsigned long value, int bits) { digitalWrite(LED_PIN, HIGH); delay(20); digitalWrite(LED_PIN, LOW); - } + } else { Serial.println(": BAD"); dump(&results); @@ -180,7 +180,7 @@ void testRaw(char *label, unsigned int *rawbuf, int rawlen) { Serial.println(label); irsend.sendRaw(rawbuf, rawlen, 38 /* kHz */); delay(200); - } + } else if (mode == RECEIVER ) { irrecv.resume(); // Receive the next value unsigned long max_time = millis() + 30000; @@ -203,11 +203,11 @@ void testRaw(char *label, unsigned int *rawbuf, int rawlen) { return; } for (int i = 0; i < rawlen; i++) { - long got = results.rawbuf[i+1] * USECPERTICK; + long got = results.rawbuf[i + 1] * USECPERTICK; // Adjust for extra duration of marks - if (i % 2 == 0) { + if (i % 2 == 0) { got -= MARK_EXCESS; - } + } else { got += MARK_EXCESS; } @@ -225,7 +225,7 @@ void testRaw(char *label, unsigned int *rawbuf, int rawlen) { delay(20); digitalWrite(LED_PIN, LOW); } -} +} // This is the raw data corresponding to NEC 0x12345678 unsigned int sendbuf[] = { /* NEC format */ @@ -238,15 +238,16 @@ unsigned int sendbuf[] = { /* NEC format */ 560, 560, 560, 1690, 560, 1690, 560, 560, /* 6 */ 560, 560, 560, 1690, 560, 1690, 560, 1690, /* 7 */ 560, 1690, 560, 560, 560, 560, 560, 560, /* 8 */ - 560}; + 560 +}; void loop() { if (mode == SENDER) { delay(2000); // Delay for more than gap to give receiver a better chance to sync. - } + } else if (mode == RECEIVER) { waitForGap(1000); - } + } else if (mode == ERROR) { // Light up for 5 seconds for error digitalWrite(LED_PIN, HIGH); @@ -282,7 +283,7 @@ void loop() { if (mode == SENDER) { testRaw("RAW2", sendbuf, 67); test("RAW3", NEC, 0x12345678, 32); - } + } else { test("RAW2", NEC, 0x12345678, 32); testRaw("RAW3", sendbuf, 67); diff --git a/libraries/RobotIRremote/examples/JVCPanasonicSendDemo/JVCPanasonicSendDemo.ino b/libraries/RobotIRremote/examples/JVCPanasonicSendDemo/JVCPanasonicSendDemo.ino index 33c167c58..1b58e4d97 100644 --- a/libraries/RobotIRremote/examples/JVCPanasonicSendDemo/JVCPanasonicSendDemo.ino +++ b/libraries/RobotIRremote/examples/JVCPanasonicSendDemo/JVCPanasonicSendDemo.ino @@ -7,7 +7,7 @@ * JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post) */ #include - + #define PanasonicAddress 0x4004 // Panasonic address (Pre data) #define PanasonicPower 0x100BCBD // Panasonic Power button @@ -20,10 +20,10 @@ void setup() } void loop() { - irsend.sendPanasonic(PanasonicAddress,PanasonicPower); // This should turn your TV on and off - - irsend.sendJVC(JVCPower, 16,0); // hex value, 16 bits, no repeat + irsend.sendPanasonic(PanasonicAddress, PanasonicPower); // This should turn your TV on and off + + irsend.sendJVC(JVCPower, 16, 0); // hex value, 16 bits, no repeat delayMicroseconds(50); // see http://www.sbprojects.com/knowledge/ir/jvc.php for information - irsend.sendJVC(JVCPower, 16,1); // hex value, 16 bits, repeat + irsend.sendJVC(JVCPower, 16, 1); // hex value, 16 bits, repeat delayMicroseconds(50); } diff --git a/libraries/Robot_Control/examples/explore/R01_Logo/R01_Logo.ino b/libraries/Robot_Control/examples/explore/R01_Logo/R01_Logo.ino index 794479ee5..f43a27267 100644 --- a/libraries/Robot_Control/examples/explore/R01_Logo/R01_Logo.ino +++ b/libraries/Robot_Control/examples/explore/R01_Logo/R01_Logo.ino @@ -1,24 +1,24 @@ /* Robot Logo - This sketch demonstrates basic movement of the Robot. - When the sketch starts, press the on-board buttons to tell - the robot how to move. Pressing the middle button will - save the pattern, and the robot will follow accordingly. - You can record up to 20 commands. The robot will move for + This sketch demonstrates basic movement of the Robot. + When the sketch starts, press the on-board buttons to tell + the robot how to move. Pressing the middle button will + save the pattern, and the robot will follow accordingly. + You can record up to 20 commands. The robot will move for one second per command. - + This example uses images on an SD card. It looks for files named "lg0.bmp" and "lg1.bmp" and draws them on the screen. Circuit: * Arduino Robot - + created 1 May 2013 by X. Yang modified 12 May 2013 by D. Cuartielles - + This example is in the public domain */ @@ -27,7 +27,7 @@ int commands[20]; // array for storing commands void setup() { - // initialize the Robot, SD card, and display + // initialize the Robot, SD card, and display Robot.begin(); Robot.beginTFT(); Robot.beginSD(); @@ -37,39 +37,39 @@ void setup() { } void loop() { - + Robot.drawBMP("intro.bmp", 0, 0); //display background image - + iniCommands(); // remove commands from the array addCommands(); // add commands to the array - + delay(1000); // wait for a second - + executeCommands(); // follow orders - - Robot.stroke(0,0,0); + + Robot.stroke(0, 0, 0); Robot.text("Done!", 5, 103); // write some text to the display delay(1500); // wait for a moment } // empty the commands array void iniCommands() { - for(int i=0; i<20; i++) - commands[i]=-1; + for (int i = 0; i < 20; i++) + commands[i] = -1; } // add commands to the array void addCommands() { - Robot.stroke(0,0,0); + Robot.stroke(0, 0, 0); // display text on the screen Robot.text("1. Press buttons to\n add commands.\n\n 2. Middle to finish.", 5, 5); - + // read the buttons' state - for(int i=0; i<20;) { //max 20 commands + for (int i = 0; i < 20;) { //max 20 commands int key = Robot.keyboardRead(); - if(key == BUTTON_MIDDLE) { //finish input + if (key == BUTTON_MIDDLE) { //finish input break; - }else if(key == BUTTON_NONE) { //if no button is pressed + } else if (key == BUTTON_NONE) { //if no button is pressed continue; } commands[i] = key; // save the button to the array @@ -82,11 +82,11 @@ void addCommands() { // run through the array and move the robot void executeCommands() { // print status to the screen - Robot.text("Excuting...",5,70); - + Robot.text("Excuting...", 5, 70); + // read through the array and move accordingly - for(int i=0; i<20; i++) { - switch(commands[i]) { + for (int i = 0; i < 20; i++) { + switch (commands[i]) { case BUTTON_LEFT: Robot.turn(-90); break; @@ -103,10 +103,10 @@ void executeCommands() { return; } // print the current command to the screen - Robot.stroke(255,0,0); + Robot.stroke(255, 0, 0); PrintCommandI(i, 86); delay(1000); - + // stop moving for a second Robot.motorsStop(); delay(1000); @@ -115,7 +115,7 @@ void executeCommands() { // convert the button press to a single character char keyToChar(int key) { - switch(key) { + switch (key) { case BUTTON_LEFT: return '<'; case BUTTON_RIGHT: @@ -129,6 +129,6 @@ char keyToChar(int key) { // display a command void PrintCommandI(int i, int originY) { - Robot.text(keyToChar(commands[i]), i%14*8+5, i/14*10+originY); + Robot.text(keyToChar(commands[i]), i % 14 * 8 + 5, i / 14 * 10 + originY); } diff --git a/libraries/Robot_Control/examples/explore/R02_Line_Follow/R02_Line_Follow.ino b/libraries/Robot_Control/examples/explore/R02_Line_Follow/R02_Line_Follow.ino index 2e37e95d7..b5b4fd4eb 100644 --- a/libraries/Robot_Control/examples/explore/R02_Line_Follow/R02_Line_Follow.ino +++ b/libraries/Robot_Control/examples/explore/R02_Line_Follow/R02_Line_Follow.ino @@ -1,19 +1,19 @@ /* Robot Line Follow This sketch demonstrates the line following capabilities - of the Arduino Robot. On the floor, place some black + of the Arduino Robot. On the floor, place some black electrical tape along the path you wish the robot to follow. To indicate a stopping point, place another piece of tape perpendicular to the path. Circuit: * Arduino Robot - + created 1 May 2013 by X. Yang modified 12 May 2013 by D. Cuartielles - + This example is in the public domain */ @@ -22,7 +22,7 @@ long timerOrigin; // used for counting elapsed time void setup() { - // initialize the Robot, SD card, display, and speaker + // initialize the Robot, SD card, display, and speaker Robot.begin(); Robot.beginTFT(); Robot.beginSD(); @@ -30,45 +30,45 @@ void setup() { // show the logots on the TFT screen Robot.displayLogos(); - + Robot.drawBMP("lf.bmp", 0, 0); // display background image Robot.playFile("chase.sqm"); // play a song from the SD card - + // add the instructions Robot.text("Line Following\n\n place the robot on\n the track and \n see it run", 5, 5); Robot.text("Press the middle\n button to start...", 5, 61); Robot.waitContinue(); - // These are some general values that work for line following + // These are some general values that work for line following // uncomment one or the other to see the different behaviors of the robot //Robot.lineFollowConfig(14, 9, 50, 10); Robot.lineFollowConfig(11, 7, 60, 5); - - + + //set the motor board into line-follow mode - Robot.setMode(MODE_LINE_FOLLOW); - + Robot.setMode(MODE_LINE_FOLLOW); + // start Robot.fill(255, 255, 255); Robot.stroke(255, 255, 255); Robot.rect(0, 0, 128, 80); // erase the previous text Robot.stroke(0, 0, 0); Robot.text("Start", 5, 5); - + Robot.stroke(0, 0, 0); // choose color for the text Robot.text("Time passed:", 5, 21); // write some text to the screen - - timerOrigin=millis(); // keep track of the elapsed time - - while(!Robot.isActionDone()) { //wait for the finish signal - Robot.debugPrint(millis()-timerOrigin, 5, 29); // show how much time has passed + + timerOrigin = millis(); // keep track of the elapsed time + + while (!Robot.isActionDone()) { //wait for the finish signal + Robot.debugPrint(millis() - timerOrigin, 5, 29); // show how much time has passed } - - Robot.stroke(0, 0, 0); + + Robot.stroke(0, 0, 0); Robot.text("Done!", 5, 45); } void loop() { - //nothing here, the program only runs once. Reset the robot + //nothing here, the program only runs once. Reset the robot //to do it again! } diff --git a/libraries/Robot_Control/examples/explore/R03_Disco_Bot/R03_Disco_Bot.ino b/libraries/Robot_Control/examples/explore/R03_Disco_Bot/R03_Disco_Bot.ino index 3574b013a..685345720 100644 --- a/libraries/Robot_Control/examples/explore/R03_Disco_Bot/R03_Disco_Bot.ino +++ b/libraries/Robot_Control/examples/explore/R03_Disco_Bot/R03_Disco_Bot.ino @@ -1,18 +1,18 @@ /* Disco Bot - This sketch shows you how to use the melody playing - feature of the robot, with some really cool 8-bit music. - Music will play when the robot is turned on, and it + This sketch shows you how to use the melody playing + feature of the robot, with some really cool 8-bit music. + Music will play when the robot is turned on, and it will show you some dance moves. Circuit: * Arduino Robot - + created 1 May 2013 by X. Yang modified 12 May 2013 by D. Cuartielles - + This example is in the public domain */ @@ -25,12 +25,12 @@ F: go forward B: go backwards - The number after each command determines how long + The number after each command determines how long each step lasts. Each number is 1/2 second long. The "\0" indicates end of string */ -char danceScript[] = "S4L1R1S2F1B1S1\0"; +char danceScript[] = "S4L1R1S2F1B1S1\0"; int currentScript = 0; // what step are we at @@ -49,34 +49,34 @@ long waitFrom; long waitTime = 0; void setup() { - // initialize the Robot, SD card, display, and speaker + // initialize the Robot, SD card, display, and speaker Robot.begin(); Robot.beginSpeaker(); Robot.beginSD(); Robot.beginTFT(); - + // draw "lg0.bmp" and "lg1.bmp" on the screen Robot.displayLogos(); - + // Print instructions to the screen Robot.text("1. Use left and\n right key to switch\n song", 5, 5); Robot.text("2. Put robot on the\n ground to dance", 5, 33); // wait for a few soconds delay(3000); - + setInterface(); // display the current song play(0); //play the first song in the array - + resetWait(); //Initialize non-blocking delay } void loop() { // read the butttons on the robot int key = Robot.keyboardRead(); - + // Right/left buttons play next/previous song - switch(key) { + switch (key) { case BUTTON_UP: case BUTTON_LEFT: play(-1); //play previous song @@ -86,25 +86,25 @@ void loop() { play(1); //play next song break; } - + // dance! runScript(); } // Dancing function -void runScript() { - if(!waiting()) { // if the previous instructions have finished - // get the next 2 commands (direction and duration) - parseCommand(danceScript[currentScript], danceScript[currentScript+1]); +void runScript() { + if (!waiting()) { // if the previous instructions have finished + // get the next 2 commands (direction and duration) + parseCommand(danceScript[currentScript], danceScript[currentScript + 1]); currentScript += 2; - if(danceScript[currentScript] == '\0') // at the end of the array + if (danceScript[currentScript] == '\0') // at the end of the array currentScript = 0; // start again at the beginning - } + } } // instead of delay, use this timer boolean waiting() { - if(millis()-waitFrom >= waitTime) + if (millis() - waitFrom >= waitTime) return false; else return true; @@ -122,9 +122,9 @@ void resetWait() { } // read the direction and dirstion of the steps -void parseCommand(char dir, char duration) { +void parseCommand(char dir, char duration) { //convert the scripts to action - switch(dir) { + switch (dir) { case 'L': Robot.motorsWrite(-255, 255); break; @@ -142,7 +142,7 @@ void parseCommand(char dir, char duration) { break; } //You can change "500" to change the pace of dancing - wait(500*(duration-'0')); + wait(500 * (duration - '0')); } // display the song @@ -154,10 +154,10 @@ void setInterface() { // display the next song void select(int seq, boolean onOff) { - if(onOff){//select + if (onOff) { //select Robot.stroke(0, 0, 0); Robot.text(musics[seq], 0, 0); - }else{//deselect + } else { //deselect Robot.stroke(255, 255, 255); Robot.text(musics[seq], 0, 0); } @@ -166,9 +166,9 @@ void select(int seq, boolean onOff) { // play the slected song void play(int seq) { select(currentSong, false); - if(currentSong <= 0 && seq == -1) { //previous of 1st song? - currentSong = SONGS_COUNT-1; //go to last song - } else if(currentSong >= SONGS_COUNT-1 && seq == 1) { //next of last? + if (currentSong <= 0 && seq == -1) { //previous of 1st song? + currentSong = SONGS_COUNT - 1; //go to last song + } else if (currentSong >= SONGS_COUNT - 1 && seq == 1) { //next of last? currentSong = 0; //go to 1st song } else { currentSong += seq; //next song diff --git a/libraries/Robot_Control/examples/explore/R04_Compass/R04_Compass.ino b/libraries/Robot_Control/examples/explore/R04_Compass/R04_Compass.ino index a7a7315f5..1ccd114e1 100644 --- a/libraries/Robot_Control/examples/explore/R04_Compass/R04_Compass.ino +++ b/libraries/Robot_Control/examples/explore/R04_Compass/R04_Compass.ino @@ -1,21 +1,21 @@ /* Robot Compass The robot has an on-board compass module, with - which it can tell the direction the robot is - facing. This sketch will make sure the robot - goes towards a certain direction. - + which it can tell the direction the robot is + facing. This sketch will make sure the robot + goes towards a certain direction. + Beware, magnets will interfere with the compass readings. Circuit: * Arduino Robot - + created 1 May 2013 by X. Yang modified 12 May 2013 by D. Cuartielles - + This example is in the public domain */ @@ -35,32 +35,32 @@ void setup() { Robot.displayLogos(); } -void loop() { +void loop() { // read the compass orientation compassValue = Robot.compassRead(); - + // how many degrees are we off - int diff = compassValue-direc; - - // modify degress - if(diff > 180) - diff = -360+diff; - else if(diff < -180) - diff = 360+diff; - + int diff = compassValue - direc; + + // modify degress + if (diff > 180) + diff = -360 + diff; + else if (diff < -180) + diff = 360 + diff; + // Make the robot turn to its proper orientation diff = map(diff, -180, 180, -255, 255); - - if(diff > 0) { - // keep the right wheel spinning, - // change the speed of the left wheel - speedLeft = 255-diff; + + if (diff > 0) { + // keep the right wheel spinning, + // change the speed of the left wheel + speedLeft = 255 - diff; speedRight = 255; } else { // keep the right left spinning, - // change the speed of the left wheel + // change the speed of the left wheel speedLeft = 255; - speedRight = 255+diff; + speedRight = 255 + diff; } // write out to the motors Robot.motorsWrite(speedLeft, speedRight); diff --git a/libraries/Robot_Control/examples/explore/R05_Inputs/R05_Inputs.ino b/libraries/Robot_Control/examples/explore/R05_Inputs/R05_Inputs.ino index ee6c31fb3..36f4b53f7 100644 --- a/libraries/Robot_Control/examples/explore/R05_Inputs/R05_Inputs.ino +++ b/libraries/Robot_Control/examples/explore/R05_Inputs/R05_Inputs.ino @@ -1,21 +1,21 @@ /* Robot Inputs - This sketch shows you how to use the on-board - potentiometer and buttons as inputs. + This sketch shows you how to use the on-board + potentiometer and buttons as inputs. - Turning the potentiometer draws a clock-shaped - circle. The up and down buttons change the pitch, - while the left and right buttons change the tempo. + Turning the potentiometer draws a clock-shaped + circle. The up and down buttons change the pitch, + while the left and right buttons change the tempo. The middle button resets tempo and pitch. Circuit: * Arduino Robot - + created 1 May 2013 by X. Yang modified 12 May 2013 by D. Cuartielles - + This example is in the public domain */ @@ -26,16 +26,16 @@ int tempo = 60; int pitch = 1000; void setup() { - // initialize the Robot, SD card, speaker, and display + // initialize the Robot, SD card, speaker, and display Robot.begin(); Robot.beginTFT(); Robot.beginSpeaker(); Robot.beginSD(); - // draw "lg0.bmp" and "lg1.bmp" on the screen + // draw "lg0.bmp" and "lg1.bmp" on the screen Robot.displayLogos(); - // play a sound file + // play a sound file Robot.playFile("Melody.sqm"); } @@ -50,55 +50,55 @@ void loop() { // Draw the basic interface void renderUI() { //fill the buttons blank - Robot.fill(255, 255, 255); + Robot.fill(255, 255, 255); Robot.rect(53, 58, 13, 13); // left Robot.rect(93, 58, 13, 13); // right Robot.rect(73, 38, 13, 13); // up Robot.circle(79, 64, 6); // middle Robot.rect(73, 78, 13, 13); // down - + //draw the knob Robot.noFill(); Robot.circle(26, 116, 17); // knob //draw the vertical bargraph - int fullPart=map(pitch, 200, 2000, 0, 58); //length of filled bargraph - Robot.fill(255, 255, 255); - Robot.rect(21, 30, 13, 58-fullPart); - Robot.fill(0, 0, 255); - Robot.rect(21, 88-fullPart, 13, fullPart); //58-fullPart+30 + int fullPart = map(pitch, 200, 2000, 0, 58); //length of filled bargraph + Robot.fill(255, 255, 255); + Robot.rect(21, 30, 13, 58 - fullPart); + Robot.fill(0, 0, 255); + Robot.rect(21, 88 - fullPart, 13, fullPart); //58-fullPart+30 //draw the horizontal bargraph fullPart = map(tempo, 20, 100, 0, 58); // length of filled bargraph - Robot.fill(255, 190, 0); + Robot.fill(255, 190, 0); Robot.rect(53, 110, fullPart, 13); - Robot.fill(255, 255, 255); - Robot.rect(53+fullPart, 110, 58-fullPart, 13); + Robot.fill(255, 255, 255); + Robot.rect(53 + fullPart, 110, 58 - fullPart, 13); } void keyDown(int keyCode) { // use a static int so it is persistent over time static int oldKey; - switch(keyCode) { + switch (keyCode) { case BUTTON_LEFT: //left button pressed, reduces tempo tempo -= 5; - if(tempo < 20) tempo = 20; //lowest tempo 20 - Robot.fill(255,190,0); + if (tempo < 20) tempo = 20; //lowest tempo 20 + Robot.fill(255, 190, 0); Robot.rect(53, 58, 13, 13); break; case BUTTON_RIGHT: //right button pressed, increases tempo tempo += 5; - if(tempo > 100) tempo = 100; //highest tempo 100 - Robot.fill(255,190,0); + if (tempo > 100) tempo = 100; //highest tempo 100 + Robot.fill(255, 190, 0); Robot.rect(93, 58, 13, 13); break; case BUTTON_UP: //up button pressed, increases pitch pitch += 120; - if(pitch > 2000) pitch = 2000; + if (pitch > 2000) pitch = 2000; Robot.fill(0, 0, 255); Robot.rect(73, 38, 13, 13); @@ -106,8 +106,8 @@ void keyDown(int keyCode) { case BUTTON_DOWN: //down button pressed, reduces pitch pitch -= 120; - if(pitch < 200){ - pitch = 200; + if (pitch < 200) { + pitch = 200; } Robot.fill(0, 0, 255); @@ -117,49 +117,49 @@ void keyDown(int keyCode) { //middle button pressed, resets tempo and pitch tempo = 60; pitch = 1000; - Robot.fill(160,160,160); + Robot.fill(160, 160, 160); Robot.circle(79, 64, 6); break; case BUTTON_NONE: //Only when the keys are released(thus BUTTON_NONE is - //encountered the first time), the interface will be + //encountered the first time), the interface will be //re-drawn. - if(oldKey != BUTTON_NONE){ + if (oldKey != BUTTON_NONE) { renderUI(); } break; } - if(oldKey != keyCode) { + if (oldKey != keyCode) { // change the song's tempo Robot.tempoWrite(tempo); // change the song's pitch - Robot.tuneWrite(float(pitch/1000.0)); + Robot.tuneWrite(float(pitch / 1000.0)); } oldKey = keyCode; } //Draw a circle according to value -//of the knob. +//of the knob. void drawKnob(int val) { static int val_old; - int r=map(val,0,1023,1,15); - - //Only updates when the + int r = map(val, 0, 1023, 1, 15); + + //Only updates when the //value changes. - if(val_old!=r){ + if (val_old != r) { Robot.noFill(); - + //erase the old circle Robot.stroke(255, 255, 255); - Robot.circle(26,116,r+1); - + Robot.circle(26, 116, r + 1); + //draw the new circle Robot.stroke(255, 0, 255); - Robot.circle(26,116,r); + Robot.circle(26, 116, r); Robot.stroke(0, 0, 0); - - val_old=r; + + val_old = r; } } diff --git a/libraries/Robot_Control/examples/explore/R06_Wheel_Calibration/R06_Wheel_Calibration.ino b/libraries/Robot_Control/examples/explore/R06_Wheel_Calibration/R06_Wheel_Calibration.ino index 0c209f339..17626445a 100644 --- a/libraries/Robot_Control/examples/explore/R06_Wheel_Calibration/R06_Wheel_Calibration.ino +++ b/libraries/Robot_Control/examples/explore/R06_Wheel_Calibration/R06_Wheel_Calibration.ino @@ -1,11 +1,11 @@ /* 6 Wheel Calibration * -* Use this sketch to calibrate the wheels in your robot. -* Your robot should drive as straight as possible when +* Use this sketch to calibrate the wheels in your robot. +* Your robot should drive as straight as possible when * putting both motors at the same speed. * -* Run the software and follow the on-screen instructions. -* Use the trimmer on the bottom board to make sure the +* Run the software and follow the on-screen instructions. +* Use the trimmer on the bottom board to make sure the * robot is working at its best! * * (c) 2013 X. Yang @@ -14,7 +14,7 @@ #include -void setup(){ +void setup() { Serial.begin(9600); Robot.begin(); Robot.beginTFT(); @@ -22,17 +22,17 @@ void setup(){ Robot.setTextWrap(false); Robot.displayLogos(); - - writeAllScripts(); - -} -void loop(){ - int val=map(Robot.knobRead(),0,1023,-255,255); - Serial.println(val); - Robot.motorsWrite(val,val); - int WC=map(Robot.trimRead(),0,1023,-20,20); - Robot.debugPrint(WC,108,149); + writeAllScripts(); + +} +void loop() { + int val = map(Robot.knobRead(), 0, 1023, -255, 255); + Serial.println(val); + Robot.motorsWrite(val, val); + + int WC = map(Robot.trimRead(), 0, 1023, -20, 20); + Robot.debugPrint(WC, 108, 149); delay(40); } diff --git a/libraries/Robot_Control/examples/explore/R07_Runaway_Robot/R07_Runaway_Robot.ino b/libraries/Robot_Control/examples/explore/R07_Runaway_Robot/R07_Runaway_Robot.ino index b55f9835c..0d83c713e 100644 --- a/libraries/Robot_Control/examples/explore/R07_Runaway_Robot/R07_Runaway_Robot.ino +++ b/libraries/Robot_Control/examples/explore/R07_Runaway_Robot/R07_Runaway_Robot.ino @@ -1,20 +1,20 @@ /* Runaway Robot - Play tag with your robot! With an ultrasonic + Play tag with your robot! With an ultrasonic distance sensor, it's capable of detecting and avoiding obstacles, never bumping into walls again! - + You'll need to attach an untrasonic range finder to M1. Circuit: * Arduino Robot * US range finder like Maxbotix EZ10, with analog output - + created 1 May 2013 by X. Yang modified 12 May 2013 by D. Cuartielles - + This example is in the public domain */ @@ -30,14 +30,14 @@ void setup() { Robot.beginTFT(); Robot.beginSD(); Robot.displayLogos(); - + // draw a face on the LCD screen setFace(true); } void loop() { // If the robot is blocked, turn until free - while(getDistance() < 40) { // If an obstacle is less than 20cm away + while (getDistance() < 40) { // If an obstacle is less than 20cm away setFace(false); //shows an unhappy face Robot.motorsStop(); // stop the motors delay(1000); // wait for a moment @@ -45,7 +45,7 @@ void loop() { setFace(true); // happy face } // if there are no objects in the way, keep moving - Robot.motorsWrite(255, 255); + Robot.motorsWrite(255, 255); delay(100); } @@ -54,20 +54,20 @@ float getDistance() { // read the value from the sensor int sensorValue = Robot.analogRead(sensorPin); //Convert the sensor input to cm. - float distance_cm = sensorValue*1.27; - return distance_cm; + float distance_cm = sensorValue * 1.27; + return distance_cm; } // make a happy or sad face void setFace(boolean onOff) { - if(onOff) { + if (onOff) { // if true show a happy face Robot.background(0, 0, 255); Robot.setCursor(44, 60); Robot.stroke(0, 255, 0); Robot.setTextSize(4); Robot.print(":)"); - }else{ + } else { // if false show an upset face Robot.background(255, 0, 0); Robot.setCursor(44, 60); diff --git a/libraries/Robot_Control/examples/explore/R08_Remote_Control/R08_Remote_Control.ino b/libraries/Robot_Control/examples/explore/R08_Remote_Control/R08_Remote_Control.ino index 09432e89b..788c0f004 100644 --- a/libraries/Robot_Control/examples/explore/R08_Remote_Control/R08_Remote_Control.ino +++ b/libraries/Robot_Control/examples/explore/R08_Remote_Control/R08_Remote_Control.ino @@ -1,12 +1,12 @@ /* 08 Remote Control - - If you connect a IR receiver to the robot, - you can control it like a RC car. - Using the remote control comes with sensor - pack, You can make the robot move around + + If you connect a IR receiver to the robot, + you can control it like a RC car. + Using the remote control comes with sensor + pack, You can make the robot move around without even touching it! - Circuit: + Circuit: * Arduino Robot * Connect the IRreceiver to D2 * Remote control from Robot sensor pack @@ -14,12 +14,12 @@ based on the IRremote library by Ken Shirriff http://arcfn.com - + created 1 May 2013 by X. Yang modified 12 May 2013 by D. Cuartielles - + This example is in the public domain */ @@ -35,12 +35,12 @@ #define IR_CODE_TURN_RIGHT 284127885 #define IR_CODE_CONTINUE -1 -boolean isActing=false; //If the robot is executing command from remote -long timer; -const long TIME_OUT=150; +boolean isActing = false; //If the robot is executing command from remote +long timer; +const long TIME_OUT = 150; void setup() { - // initialize the Robot, SD card, display, and speaker + // initialize the Robot, SD card, display, and speaker Serial.begin(9600); Robot.begin(); Robot.beginTFT(); @@ -56,36 +56,36 @@ void loop() { processResult(); resumeIRremote(); // resume receiver } - + //If the robot does not receive any command, stop it - if(isActing && (millis()-timer>=TIME_OUT)){ + if (isActing && (millis() - timer >= TIME_OUT)) { Robot.motorsStop(); - isActing=false; + isActing = false; } } void processResult() { unsigned long res = getIRresult(); - switch(res){ + switch (res) { case IR_CODE_FORWARD: - changeAction(1,1); //Move the robot forward + changeAction(1, 1); //Move the robot forward break; case IR_CODE_BACKWARDS: - changeAction(-1,-1); //Move the robot backwards + changeAction(-1, -1); //Move the robot backwards break; case IR_CODE_TURN_LEFT: - changeAction(-0.5,0.5); //Turn the robot left + changeAction(-0.5, 0.5); //Turn the robot left break; case IR_CODE_TURN_RIGHT: - changeAction(0.5,-0.5); //Turn the robot Right + changeAction(0.5, -0.5); //Turn the robot Right break; case IR_CODE_CONTINUE: - timer=millis(); //Continue the last action, reset timer + timer = millis(); //Continue the last action, reset timer break; } } -void changeAction(float directionLeft, float directionRight){ - Robot.motorsWrite(255*directionLeft, 255*directionRight); - timer=millis(); - isActing=true; +void changeAction(float directionLeft, float directionRight) { + Robot.motorsWrite(255 * directionLeft, 255 * directionRight); + timer = millis(); + isActing = true; } diff --git a/libraries/Robot_Control/examples/explore/R09_Picture_Browser/R09_Picture_Browser.ino b/libraries/Robot_Control/examples/explore/R09_Picture_Browser/R09_Picture_Browser.ino index a43348cee..23a398a59 100644 --- a/libraries/Robot_Control/examples/explore/R09_Picture_Browser/R09_Picture_Browser.ino +++ b/libraries/Robot_Control/examples/explore/R09_Picture_Browser/R09_Picture_Browser.ino @@ -1,25 +1,25 @@ /* Picture Browser - You can make your own gallery/picture show with the - Robot. Put some pictures on the SD card, start the - sketch, they will diplay on the screen. - - Use the left/right buttons to navigate through the - previous and next images. - - Press up or down to enter a mode where you change + You can make your own gallery/picture show with the + Robot. Put some pictures on the SD card, start the + sketch, they will diplay on the screen. + + Use the left/right buttons to navigate through the + previous and next images. + + Press up or down to enter a mode where you change the pictures by rotating the robot. - - You can add your own pictures onto the SD card, and + + You can add your own pictures onto the SD card, and view them in the Robot's gallery! - Pictures must be uncompressed BMP, 24-bit color depth, + Pictures must be uncompressed BMP, 24-bit color depth, 160 pixels wide, and 128 pixels tall. - - They should be named as "picN.bmp". Replace 'N' with a + + They should be named as "picN.bmp". Replace 'N' with a number between 0 and 9. - The current code only supports 10 pictures. How would you + The current code only supports 10 pictures. How would you improve it to handle more? Circuit: @@ -29,7 +29,7 @@ by X. Yang modified 12 May 2013 by D. Cuartielles - + This example is in the public domain */ @@ -49,14 +49,14 @@ int mode = 0; // Current mode char modeNames[][9] = { "keyboard", "tilt " }; void setup() { - // initialize the Robot, SD card, display, and speaker + // initialize the Robot, SD card, display, and speaker Robot.beginSD(); Robot.beginTFT(); Robot.begin(); - - // draw "lg0.bmp" and "lg1.bmp" on the screen + + // draw "lg0.bmp" and "lg1.bmp" on the screen Robot.displayLogos(); - + // draw init3.bmp from the SD card on the screen Robot.drawBMP("init3.bmp", 0, 0); @@ -71,10 +71,10 @@ void setup() { } void loop() { - buffer[3] = '0'+i;// change filename of the img to be displayed + buffer[3] = '0' + i; // change filename of the img to be displayed Robot.drawBMP(buffer, 0, 0); // draw the file on the screen // change control modes - switch(mode) { + switch (mode) { case CONTROL_MODE_COMPASS: compassControl(3); break; @@ -87,15 +87,15 @@ void loop() { void keyboardControl() { //Use buttons to control the gallery - while(true) { + while (true) { int keyPressed = Robot.keyboardRead(); // read the button values - switch(keyPressed) { + switch (keyPressed) { case BUTTON_LEFT: // display previous picture - if(--i < 1) i = NUM_PICS; + if (--i < 1) i = NUM_PICS; return; case BUTTON_MIDDLE: // do nothing case BUTTON_RIGHT: // display next picture - if(++i > NUM_PICS) i = 1; + if (++i > NUM_PICS) i = 1; return; case BUTTON_UP: // change mode changeMode(-1); @@ -110,23 +110,23 @@ void keyboardControl() { // if controlling by the compass void compassControl(int change) { // Rotate the robot to change the pictures - while(true) { + while (true) { // read the value of the compass int oldV = Robot.compassRead(); - + //get the change of angle - int diff = Robot.compassRead()-oldV; - if(diff > 180) diff -= 360; - else if(diff < -180) diff += 360; - - if(abs(diff) > change) { - if(++i > NUM_PICS) i = 1; + int diff = Robot.compassRead() - oldV; + if (diff > 180) diff -= 360; + else if (diff < -180) diff += 360; + + if (abs(diff) > change) { + if (++i > NUM_PICS) i = 1; return; } - + // chage modes, if buttons are pressed int keyPressed = Robot.keyboardRead(); - switch(keyPressed) { + switch (keyPressed) { case BUTTON_UP: changeMode(-1); return; @@ -142,13 +142,13 @@ void compassControl(int change) { void changeMode(int changeDir) { // alternate modes mode += changeDir; - if(mode < 0) { + if (mode < 0) { mode = 1; - } else if(mode > 1) - mode=0; - - // display the mode on screen - Robot.fill(255, 255, 255); + } else if (mode > 1) + mode = 0; + + // display the mode on screen + Robot.fill(255, 255, 255); Robot.stroke(255, 255, 255); Robot.rect(0, 0, 128, 12); Robot.stroke(0, 0, 0); diff --git a/libraries/Robot_Control/examples/explore/R10_Rescue/R10_Rescue.ino b/libraries/Robot_Control/examples/explore/R10_Rescue/R10_Rescue.ino index 717e301e5..4f5afe43b 100644 --- a/libraries/Robot_Control/examples/explore/R10_Rescue/R10_Rescue.ino +++ b/libraries/Robot_Control/examples/explore/R10_Rescue/R10_Rescue.ino @@ -1,8 +1,8 @@ /* Robot Rescue In this example, the robot enters the line following mode and - plays some music until it reaches its target. Once it finds the - target, it pushes it out of the track. It then returns to the + plays some music until it reaches its target. Once it finds the + target, it pushes it out of the track. It then returns to the track and looks for a second target. You can make the robot push as many objects as you want to, just @@ -18,20 +18,20 @@ by X. Yang modified 12 May 2013 by D. Cuartielles - + This example is in the public domain */ #include // include the robot library -void setup(){ - // initialize the Robot, SD card, display, and speaker +void setup() { + // initialize the Robot, SD card, display, and speaker Robot.begin(); Robot.beginTFT(); Robot.beginSD(); Robot.beginSpeaker(); - - // draw "lg0.bmp" and "lg1.bmp" on the screen + + // draw "lg0.bmp" and "lg1.bmp" on the screen Robot.displayLogos(); // display the line following instructional image from the SD card @@ -51,13 +51,13 @@ void setup(){ Robot.rect(0, 0, 128, 80); // erase the previous text Robot.stroke(0, 0, 0); Robot.text("Start", 5, 5); - + // use this to calibrate the line following algorithm // uncomment one or the other to see the different behaviors of the robot // Robot.lineFollowConfig(14, 9, 50, 10); Robot.lineFollowConfig(11, 7, 60, 5); - - // run the rescue sequence + + // run the rescue sequence rescueSequence(); Robot.text("Found obstacle", 5, 12); // find the track again @@ -66,24 +66,24 @@ void setup(){ // run the rescue sequence a second time rescueSequence(); Robot.text("Found obstacle", 5, 26); - + // here you could go on ... - + // write status on the screen Robot.stroke(0, 0, 0); Robot.text("Done!", 5, 25); } -void loop(){ +void loop() { //nothing here, the program only runs once. } // run the sequence -void rescueSequence(){ +void rescueSequence() { //set the motor board into line-follow mode - Robot.setMode(MODE_LINE_FOLLOW); - - while(!Robot.isActionDone()){ // wait until it is no longer following the line + Robot.setMode(MODE_LINE_FOLLOW); + + while (!Robot.isActionDone()) { // wait until it is no longer following the line } delay(1000); @@ -92,32 +92,32 @@ void rescueSequence(){ delay(1000); } -void doRescue(){ +void doRescue() { // Reached the endline, engage the target - Robot.motorsWrite(200,200); + Robot.motorsWrite(200, 200); delay(250); Robot.motorsStop(); delay(1000); - // Turn the robot + // Turn the robot Robot.turn(90); Robot.motorsStop(); delay(1000); - + // Move forward - Robot.motorsWrite(200,200); + Robot.motorsWrite(200, 200); delay(500); Robot.motorsStop(); delay(1000); - + // move backwards, leave the target - Robot.motorsWrite(-200,-200); + Robot.motorsWrite(-200, -200); delay(500); Robot.motorsStop(); } -void goToNext(){ - // Turn the robot +void goToNext() { + // Turn the robot Robot.turn(-90); Robot.motorsStop(); delay(1000); diff --git a/libraries/Robot_Control/examples/explore/R11_Hello_User/R11_Hello_User.ino b/libraries/Robot_Control/examples/explore/R11_Hello_User/R11_Hello_User.ino index ac356a44f..cd4b7cf72 100644 --- a/libraries/Robot_Control/examples/explore/R11_Hello_User/R11_Hello_User.ino +++ b/libraries/Robot_Control/examples/explore/R11_Hello_User/R11_Hello_User.ino @@ -1,9 +1,9 @@ /* Hello User - Hello User! This sketch is the first thing you see - when starting this robot. It gives you a warm welcome, - showing you some of the really amazing abilities of - the robot, and make itself really personal to you. + Hello User! This sketch is the first thing you see + when starting this robot. It gives you a warm welcome, + showing you some of the really amazing abilities of + the robot, and make itself really personal to you. Circuit: * Arduino Robot @@ -12,18 +12,18 @@ by X. Yang modified 12 May 2013 by D. Cuartielles - + This example is in the public domain */ #include // include the robot library // include the utility function for ths sketch // see the details below -#include +#include char buffer[20];//for storing user name -void setup(){ +void setup() { //necessary initialization sequence Robot.begin(); Robot.beginTFT(); @@ -31,19 +31,19 @@ void setup(){ // show the logos from the SD card Robot.displayLogos(); - + // clear the screen Robot.clearScreen(); - - // From now on, display different slides of + + // From now on, display different slides of // text/pictures in sequence. The so-called // scripts are strings of text stored in the // robot's memory - + // these functions are explained below - + //Script 6 - textManager.writeScript(5, 4, 0); + textManager.writeScript(5, 4, 0); textManager.writeScript(9, 10, 0); Robot.waitContinue(); delay(500); @@ -59,7 +59,7 @@ void setup(){ //Script 8 // this function enables sound and images at once textManager.showPicture("init2.bmp", 0, 0); - + textManager.writeScript(7, 2, 0); textManager.writeScript(9, 7, 0); Robot.waitContinue(); @@ -84,56 +84,56 @@ void setup(){ //Input screen textManager.writeScript(0, 1, 1); textManager.input(3, 1, USERNAME); - + textManager.writeScript(1, 5, 1); textManager.input(7, 1, ROBOTNAME); delay(1000); Robot.clearScreen(); - + //last screen textManager.showPicture("init4.bmp", 0, 0); textManager.writeText(1, 2, "Hello"); Robot.userNameRead(buffer); textManager.writeText(3, 2, buffer); - textManager.writeScript(4,10,0); + textManager.writeScript(4, 10, 0); Robot.waitContinue(BUTTON_LEFT); Robot.waitContinue(BUTTON_RIGHT); textManager.showPicture("kt1.bmp", 0, 0); } -void loop(){ +void loop() { // do nothing here } /** -textManager mostly contains helper functions for +textManager mostly contains helper functions for R06_Wheel_Calibration and R01_Hello_User. The ones used in this example: textManager.setMargin(margin_left, margin_top): Configure the left and top margin for text - display. The margins will be used for + display. The margins will be used for textManager.writeText(). Parameters: margin_left, margin_top: the margin values from the top and left side of the screen. Returns: none - + textManager.writeScript(script_number,line,column): - Display a script of Hello User example. + Display a script of Hello User example. Parameters: - script_number: an int value representing the + script_number: an int value representing the script to be displayed. line, column: in which line,column is the script displayed. Same as writeText(). Returns: none - + textManager.input(line,column,codename): Print an input indicator(">") in the line and column, dispaly and receive input from a virtual keyboard, @@ -147,9 +147,9 @@ The ones used in this example: to access the values later. Returns: none; - + textManager.writeText(line,column,text): - Display text on the specific line and column. + Display text on the specific line and column. It's different from Robot.text() as the later uses pixels for positioning the text. Parameters: @@ -160,18 +160,18 @@ The ones used in this example: text:a char array(string) of the text to be displayed. Returns: none - + textManager.showPicture(filename, x, y): It has the same functionality as Robot.drawPicture(), - while fixing the conflict between drawPicture() and + while fixing the conflict between drawPicture() and sound playing. Using Robot.drawPicture(), it'll have glitches when playing sound at the same time. Using - showPicture(), it'll stop sound when displaying + showPicture(), it'll stop sound when displaying picture, so preventing the problem. Parameters: filename:string, name of the bmp file in sd x,y: int values, position of the picture Returns: - none - + none + */ diff --git a/libraries/Robot_Control/examples/learn/AllIOPorts/AllIOPorts.ino b/libraries/Robot_Control/examples/learn/AllIOPorts/AllIOPorts.ino index 924b47de8..cb9f83d22 100644 --- a/libraries/Robot_Control/examples/learn/AllIOPorts/AllIOPorts.ino +++ b/libraries/Robot_Control/examples/learn/AllIOPorts/AllIOPorts.ino @@ -1,24 +1,24 @@ /* All IO Ports - + This example goes through all the IO ports on your robot and - reads/writes from/to them. Uncomment the different lines inside + reads/writes from/to them. Uncomment the different lines inside the loop to test the different possibilities. - The M inputs on the Control Board are multiplexed and therefore + The M inputs on the Control Board are multiplexed and therefore it is not recommended to use them as outputs. The D pins on the Control Board as well as the D pins on the Motor Board go directly - to the microcontroller and therefore can be used both as inputs + to the microcontroller and therefore can be used both as inputs and outputs. - + Circuit: * Arduino Robot - + created 1 May 2013 by X. Yang modified 12 May 2013 by D. Cuartielles - + This example is in the public domain */ @@ -29,7 +29,7 @@ uint8_t arr[] = { M0, M1, M2, M3, M4, M5, M6, M7 }; uint8_t arr2[] = { D0, D1, D2, D3, D4, D5 }; uint8_t arr3[] = { D7, D8, D9, D10 }; -void setup(){ +void setup() { // initialize the robot Robot.begin(); @@ -37,8 +37,8 @@ void setup(){ Serial.begin(9600); } -void loop(){ - // read all the D inputs at the Motor Board as analog +void loop() { + // read all the D inputs at the Motor Board as analog //analogReadB_Ds(); // read all the D inputs at the Motor Board as digital @@ -61,12 +61,12 @@ void loop(){ // write all the D outputs at the Control Board as digital //digitalWriteT_Ds(); - delay(40); + delay(40); } // read all M inputs on the Control Board as analog inputs void analogReadMs() { - for(int i=0;i<8;i++) { + for (int i = 0; i < 8; i++) { Serial.print(Robot.analogRead(arr[i])); Serial.print(","); } @@ -75,7 +75,7 @@ void analogReadMs() { // read all M inputs on the Control Board as digital inputs void digitalReadMs() { - for(int i=0;i<8;i++) { + for (int i = 0; i < 8; i++) { Serial.print(Robot.digitalRead(arr[i])); Serial.print(","); } @@ -84,7 +84,7 @@ void digitalReadMs() { // read all D inputs on the Control Board as analog inputs void analogReadT_Ds() { - for(int i=0; i<6; i++) { + for (int i = 0; i < 6; i++) { Serial.print(Robot.analogRead(arr2[i])); Serial.print(","); } @@ -93,7 +93,7 @@ void analogReadT_Ds() { // read all D inputs on the Control Board as digital inputs void digitalReadT_Ds() { - for(int i=0; i<6; i++) { + for (int i = 0; i < 6; i++) { Serial.print(Robot.digitalRead(arr2[i])); Serial.print(","); } @@ -103,13 +103,13 @@ void digitalReadT_Ds() { // write all D outputs on the Control Board as digital outputs void digitalWriteT_Ds() { // turn all the pins on - for(int i=0; i<6; i++) { + for (int i = 0; i < 6; i++) { Robot.digitalWrite(arr2[i], HIGH); } delay(500); // turn all the pins off - for(int i=0; i<6; i++){ + for (int i = 0; i < 6; i++) { Robot.digitalWrite(arr2[i], LOW); } delay(500); @@ -118,13 +118,13 @@ void digitalWriteT_Ds() { // write all D outputs on the Motor Board as digital outputs void digitalWriteB_Ds() { // turn all the pins on - for(int i=0; i<4; i++) { + for (int i = 0; i < 4; i++) { Robot.digitalWrite(arr3[i], HIGH); } delay(500); // turn all the pins off - for(int i=0; i<4; i++) { + for (int i = 0; i < 4; i++) { Robot.digitalWrite(arr3[i], LOW); } delay(500); @@ -132,7 +132,7 @@ void digitalWriteB_Ds() { // read all D inputs on the Motor Board as analog inputs void analogReadB_Ds() { - for(int i=0; i<4; i++) { + for (int i = 0; i < 4; i++) { Serial.print(Robot.analogRead(arr3[i])); Serial.print(","); } @@ -141,7 +141,7 @@ void analogReadB_Ds() { // read all D inputs on the Motor Board as digital inputs void digitalReadB_Ds() { - for(int i=0; i<4; i++) { + for (int i = 0; i < 4; i++) { Serial.print(Robot.digitalRead(arr3[i])); Serial.print(","); } diff --git a/libraries/Robot_Control/examples/learn/Beep/Beep.ino b/libraries/Robot_Control/examples/learn/Beep/Beep.ino index 1a786738a..9e943e9bb 100644 --- a/libraries/Robot_Control/examples/learn/Beep/Beep.ino +++ b/libraries/Robot_Control/examples/learn/Beep/Beep.ino @@ -1,6 +1,6 @@ /* Beep - + Test different pre-configured beeps on the robot's speaker. @@ -8,15 +8,15 @@ - BEEP_SIMPLE - BEEP_DOUBLE - BEEP_LONG - + Circuit: * Arduino Robot - + created 1 May 2013 by X. Yang modified 12 May 2013 by D. Cuartielles - + This example is in the public domain */ diff --git a/libraries/Robot_Control/examples/learn/CleanEEPROM/CleanEEPROM.ino b/libraries/Robot_Control/examples/learn/CleanEEPROM/CleanEEPROM.ino index ae14bddff..938e0b82d 100644 --- a/libraries/Robot_Control/examples/learn/CleanEEPROM/CleanEEPROM.ino +++ b/libraries/Robot_Control/examples/learn/CleanEEPROM/CleanEEPROM.ino @@ -1,6 +1,6 @@ /* Clean EEPROM - + This example erases the user information stored on the external EEPROM memory chip on your robot. @@ -11,21 +11,21 @@ EEPROMs shouldn't be rewritten too often, therefore the code runs only during setup and not inside loop. - + Circuit: * Arduino Robot - + created 1 May 2013 by X. Yang modified 12 May 2013 by D. Cuartielles - + This example is in the public domain */ #include -void setup(){ +void setup() { // initialize the robot Robot.begin(); @@ -33,9 +33,9 @@ void setup(){ Robot.userNameWrite(""); Robot.robotNameWrite(""); Robot.cityNameWrite(""); - Robot.countryNameWrite(""); + Robot.countryNameWrite(""); } -void loop(){ - // do nothing +void loop() { + // do nothing } diff --git a/libraries/Robot_Control/examples/learn/Compass/Compass.ino b/libraries/Robot_Control/examples/learn/Compass/Compass.ino index 4170ab7fa..1b763cac8 100644 --- a/libraries/Robot_Control/examples/learn/Compass/Compass.ino +++ b/libraries/Robot_Control/examples/learn/Compass/Compass.ino @@ -1,17 +1,17 @@ /* Compass - + Try the compass both on the robot's TFT and through the serial port. - + Circuit: * Arduino Robot - + created 1 May 2013 by X. Yang modified 12 May 2013 by D. Cuartielles - + This example is in the public domain */ @@ -33,8 +33,8 @@ void loop() { int compass = Robot.compassRead(); // print out the sensor's value - Serial.println(compass); - + Serial.println(compass); + // show the value on the robot's screen Robot.drawCompass(compass); } diff --git a/libraries/Robot_Control/examples/learn/IRArray/IRArray.ino b/libraries/Robot_Control/examples/learn/IRArray/IRArray.ino index 36b4acf85..80926f4ab 100644 --- a/libraries/Robot_Control/examples/learn/IRArray/IRArray.ino +++ b/libraries/Robot_Control/examples/learn/IRArray/IRArray.ino @@ -1,29 +1,29 @@ /* IR array - - Read the analog value of the IR sensors at the - bottom of the robot. The also-called line following + + Read the analog value of the IR sensors at the + bottom of the robot. The also-called line following sensors are a series of pairs of IR sender/receiver used to detect how dark it is underneath the robot. The information coming from the sensor array is stored into the Robot.IRarray[] and updated using the Robot.updateIR() method. - + Circuit: * Arduino Robot - + created 1 May 2013 by X. Yang modified 12 May 2013 by D. Cuartielles - + This example is in the public domain */ #include -void setup(){ +void setup() { // initialize the robot Robot.begin(); @@ -31,12 +31,12 @@ void setup(){ Serial.begin(9600); } -void loop(){ - // store the sensor information into the array +void loop() { + // store the sensor information into the array Robot.updateIR(); // iterate the array and print the data to the Serial port - for(int i=0; i<5; i++){ + for (int i = 0; i < 5; i++) { Serial.print(Robot.IRarray[i]); Serial.print(" "); } diff --git a/libraries/Robot_Control/examples/learn/LCDDebugPrint/LCDDebugPrint.ino b/libraries/Robot_Control/examples/learn/LCDDebugPrint/LCDDebugPrint.ino index 0078b775f..5e696a98f 100644 --- a/libraries/Robot_Control/examples/learn/LCDDebugPrint/LCDDebugPrint.ino +++ b/libraries/Robot_Control/examples/learn/LCDDebugPrint/LCDDebugPrint.ino @@ -1,17 +1,17 @@ /* LCD Debug Print - + Use the Robot's library function debugPrint() to quickly send a sensor reading to the robot's creen. - + Circuit: * Arduino Robot - + created 1 May 2013 by X. Yang modified 12 May 2013 by D. Cuartielles - + This example is in the public domain */ @@ -26,7 +26,7 @@ void setup() { // initialize the screen Robot.beginTFT(); } -void loop(){ +void loop() { // read a value value = analogRead(A4); diff --git a/libraries/Robot_Control/examples/learn/LCDPrint/LCDPrint.ino b/libraries/Robot_Control/examples/learn/LCDPrint/LCDPrint.ino index 2aa7a0b3b..62f2202db 100644 --- a/libraries/Robot_Control/examples/learn/LCDPrint/LCDPrint.ino +++ b/libraries/Robot_Control/examples/learn/LCDPrint/LCDPrint.ino @@ -1,16 +1,16 @@ /* LCD Print - + Print the reading from a sensor to the screen. - + Circuit: * Arduino Robot - + created 1 May 2013 by X. Yang modified 12 May 2013 by D. Cuartielles - + This example is in the public domain */ @@ -28,17 +28,17 @@ void setup() { void loop() { // read a analog port - value=Robot.analogRead(TK4); + value = Robot.analogRead(TK4); // write the sensor value on the screen Robot.stroke(0, 255, 0); Robot.textSize(1); - Robot.text(value, 0, 0); + Robot.text(value, 0, 0); delay(500); // erase the previous text on the screen Robot.stroke(255, 255, 255); Robot.textSize(1); - Robot.text(value, 0, 0); + Robot.text(value, 0, 0); } diff --git a/libraries/Robot_Control/examples/learn/LCDWriteText/LCDWriteText.ino b/libraries/Robot_Control/examples/learn/LCDWriteText/LCDWriteText.ino index e34a7d28d..da7a7b74e 100644 --- a/libraries/Robot_Control/examples/learn/LCDWriteText/LCDWriteText.ino +++ b/libraries/Robot_Control/examples/learn/LCDWriteText/LCDWriteText.ino @@ -1,19 +1,19 @@ /* LCD Write Text - + Use the Robot's library function text() to print out text to the robot's screen. Take into account that you need to erase the information before continuing writing. - + Circuit: * Arduino Robot - + created 1 May 2013 by X. Yang modified 12 May 2013 by D. Cuartielles - + This example is in the public domain */ @@ -32,7 +32,7 @@ void loop() { delay(2000); Robot.stroke(255, 255, 255); // choose the color white Robot.text("Hello World", 0, 0); // writing text in the same color as the BG erases the text! - + Robot.stroke(0, 0, 0); // choose the color black Robot.text("I am a robot", 0, 0); // print the text delay(3000); diff --git a/libraries/Robot_Control/examples/learn/LineFollowWithPause/LineFollowWithPause.ino b/libraries/Robot_Control/examples/learn/LineFollowWithPause/LineFollowWithPause.ino index a3d3fc073..5f961f72c 100644 --- a/libraries/Robot_Control/examples/learn/LineFollowWithPause/LineFollowWithPause.ino +++ b/libraries/Robot_Control/examples/learn/LineFollowWithPause/LineFollowWithPause.ino @@ -1,22 +1,22 @@ /* Line Following with Pause - + As the robot has two processors, one to command the motors and one to - take care of the screen and user input, it is possible to write + take care of the screen and user input, it is possible to write programs that put one part of the robot to do something and get the other half to control it. This example shows how the Control Board assigns the Motor one to follow a line, but asks it to stop every 3 seconds. - + Circuit: * Arduino Robot - + created 1 May 2013 by X. Yang modified 12 May 2013 by D. Cuartielles - + This example is in the public domain */ @@ -37,13 +37,13 @@ void setup() { } void loop() { - // tell the robot to take a break and stop - Robot.pauseMode(true); - Robot.debugPrint('p'); - delay(3000); + // tell the robot to take a break and stop + Robot.pauseMode(true); + Robot.debugPrint('p'); + delay(3000); - // tell the robot to move on - Robot.pauseMode(false); - Robot.debugPrint('>'); - delay(3000); + // tell the robot to move on + Robot.pauseMode(false); + Robot.debugPrint('>'); + delay(3000); } diff --git a/libraries/Robot_Control/examples/learn/Melody/Melody.ino b/libraries/Robot_Control/examples/learn/Melody/Melody.ino index 6c049a75e..a9cef37f5 100644 --- a/libraries/Robot_Control/examples/learn/Melody/Melody.ino +++ b/libraries/Robot_Control/examples/learn/Melody/Melody.ino @@ -1,8 +1,8 @@ /* Melody - - Plays a melody stored in a string. - + + Plays a melody stored in a string. + The notes and durations are encoded as follows: NOTES: @@ -31,12 +31,12 @@ Circuit: * Arduino Robot - + created 1 May 2013 by X. Yang modified 12 May 2013 by D. Cuartielles - + This example is in the public domain This code uses the Squawk sound library designed by STG. For diff --git a/libraries/Robot_Control/examples/learn/MotorTest/MotorTest.ino b/libraries/Robot_Control/examples/learn/MotorTest/MotorTest.ino index baaaf06a2..232262ad2 100644 --- a/libraries/Robot_Control/examples/learn/MotorTest/MotorTest.ino +++ b/libraries/Robot_Control/examples/learn/MotorTest/MotorTest.ino @@ -1,16 +1,16 @@ /* Motor Test - + Just see if the robot can move and turn. - + Circuit: * Arduino Robot - + created 1 May 2013 by X. Yang modified 12 May 2013 by D. Cuartielles - + This example is in the public domain */ @@ -22,19 +22,19 @@ void setup() { } void loop() { - Robot.motorsWrite(255,255); // move forward + Robot.motorsWrite(255, 255); // move forward delay(2000); Robot.motorsStop(); // fast stop delay(1000); - Robot.motorsWrite(-255,-255); // backward + Robot.motorsWrite(-255, -255); // backward delay(1000); - Robot.motorsWrite(0,0); // slow stop + Robot.motorsWrite(0, 0); // slow stop delay(1000); - Robot.motorsWrite(-255,255); // turn left + Robot.motorsWrite(-255, 255); // turn left delay(2000); Robot.motorsStop(); // fast stop delay(1000); - Robot.motorsWrite(255,-255); // turn right + Robot.motorsWrite(255, -255); // turn right delay(2000); Robot.motorsStop(); // fast stop delay(1000); diff --git a/libraries/Robot_Control/examples/learn/SpeedByPotentiometer/SpeedByPotentiometer.ino b/libraries/Robot_Control/examples/learn/SpeedByPotentiometer/SpeedByPotentiometer.ino index e97f48d4a..586f292b7 100644 --- a/libraries/Robot_Control/examples/learn/SpeedByPotentiometer/SpeedByPotentiometer.ino +++ b/libraries/Robot_Control/examples/learn/SpeedByPotentiometer/SpeedByPotentiometer.ino @@ -1,18 +1,18 @@ /* Speed by Potentiometer - + Control the robot's speed using the on-board potentiometer. The speed will be printed on - the TFT screen. - + the TFT screen. + Circuit: * Arduino Robot - + created 1 May 2013 by X. Yang modified 12 May 2013 by D. Cuartielles - + This example is in the public domain */ @@ -28,12 +28,12 @@ void setup() { void loop() { // read the value of the potentiometer - int val=map(Robot.knobRead(), 0, 1023, -255, 255); + int val = map(Robot.knobRead(), 0, 1023, -255, 255); // print the value to the TFT screen Robot.debugPrint(val); // set the same speed on both of the robot's wheels - Robot.motorsWrite(val,val); + Robot.motorsWrite(val, val); delay(10); } diff --git a/libraries/Robot_Control/examples/learn/TurnTest/TurnTest.ino b/libraries/Robot_Control/examples/learn/TurnTest/TurnTest.ino index 543c06ca8..3db0c64e9 100644 --- a/libraries/Robot_Control/examples/learn/TurnTest/TurnTest.ino +++ b/libraries/Robot_Control/examples/learn/TurnTest/TurnTest.ino @@ -1,16 +1,16 @@ /* Turn Test - + Check if the robot turns a certain amount of degrees. - + Circuit: * Arduino Robot - + created 1 May 2013 by X. Yang modified 12 May 2013 by D. Cuartielles - + This example is in the public domain */ @@ -21,7 +21,7 @@ void setup() { Robot.begin(); } -void loop(){ +void loop() { Robot.turn(50); //turn 50 degrees to the right Robot.motorsStop(); delay(1000); diff --git a/libraries/Robot_Control/examples/learn/TurnTest/TurnTest.ino.orig b/libraries/Robot_Control/examples/learn/TurnTest/TurnTest.ino.orig deleted file mode 100644 index 4e3624ff9..000000000 --- a/libraries/Robot_Control/examples/learn/TurnTest/TurnTest.ino.orig +++ /dev/null @@ -1,37 +0,0 @@ -/* - Turn Test - - Check if the robot turns a certain amount of degrees. - - Circuit: - * Arduino Robot - - created 1 May 2013 - by X. Yang - modified 12 May 2013 - by D. Cuartielles - - This example is in the public domain - */ - -#include - -void setup() { - // initialize the robot - Robot.begin(); -} - -<<<<<<< HEAD -void loop() { - Robot.turn(50); //turn 50 degrees to the right -======= -void loop(){ - Robot.turn(50);//turn 50 degrees to the right - Robot.motorsStop(); ->>>>>>> f062f704463222e83390b4a954e211f0f7e6e66f - delay(1000); - - Robot.turn(-100);//turn 100 degrees to the left - Robot.motorsStop(); - delay(1000); -} diff --git a/libraries/Robot_Control/examples/learn/keyboardTest/keyboardTest.ino b/libraries/Robot_Control/examples/learn/keyboardTest/keyboardTest.ino index 5bbc0e520..7d9ba0b5b 100644 --- a/libraries/Robot_Control/examples/learn/keyboardTest/keyboardTest.ino +++ b/libraries/Robot_Control/examples/learn/keyboardTest/keyboardTest.ino @@ -1,6 +1,6 @@ /* Keyboard Test - + Check how the robot's keyboard works. This example sends the data about the key pressed through the serial port. @@ -12,15 +12,15 @@ It is possible to recalibrate the thresholds of the buttons using the Robot.keyboardCalibrate() function, that takes a 5 ints long array as parameter - + Circuit: * Arduino Robot - + created 1 May 2013 by X. Yang modified 12 May 2013 by D. Cuartielles - + This example is in the public domain */ diff --git a/libraries/Robot_Control/examples/learn/keyboardTest/keyboardTest.ino.orig b/libraries/Robot_Control/examples/learn/keyboardTest/keyboardTest.ino.orig deleted file mode 100644 index 6ee6c05e1..000000000 --- a/libraries/Robot_Control/examples/learn/keyboardTest/keyboardTest.ino.orig +++ /dev/null @@ -1,49 +0,0 @@ -/* - Keyboard Test - - Check how the robot's keyboard works. This example - sends the data about the key pressed through the - serial port. - - All the buttons on the Control Board are tied up to a - single analog input pin, in this way it is possible to multiplex a - whole series of buttons on one single pin. - - It is possible to recalibrate the thresholds of the buttons using - the Robot.keyboardCalibrate() function, that takes a 5 ints long - array as parameter - - Circuit: - * Arduino Robot - - created 1 May 2013 - by X. Yang - modified 12 May 2013 - by D. Cuartielles - - This example is in the public domain - */ - -#include - -<<<<<<< HEAD -// it is possible to use an array to calibrate -//int vals[] = { 0, 133, 305, 481, 724 }; - -void setup() { - // initialize the serial port - Serial.begin(9600); - - // calibrate the keyboard - //Robot.keyboardCalibrate(vals);//For the new robot only. -======= -void setup(){ - Serial.begin(9600); ->>>>>>> f062f704463222e83390b4a954e211f0f7e6e66f -} - -void loop() { - // print out the keyboard readings - Serial.println(Robot.keyboardRead()); - delay(100); -} diff --git a/libraries/Robot_Motor/examples/Robot_IR_Array_Test/Robot_IR_Array_Test.ino b/libraries/Robot_Motor/examples/Robot_IR_Array_Test/Robot_IR_Array_Test.ino index 160097e95..be19bc6ab 100644 --- a/libraries/Robot_Motor/examples/Robot_IR_Array_Test/Robot_IR_Array_Test.ino +++ b/libraries/Robot_Motor/examples/Robot_IR_Array_Test/Robot_IR_Array_Test.ino @@ -1,25 +1,25 @@ /* Motor Board IR Array Test - - This example of the Arduno robot's motor board returns the - values read fron the 5 infrared sendors on the bottom of + + This example of the Arduno robot's motor board returns the + values read fron the 5 infrared sendors on the bottom of the robot. */ -// include the motor board header +// include the motor board header #include String bar; // string for storing the informaton -void setup(){ +void setup() { // start serial communication Serial.begin(9600); // initialize the library RobotMotor.begin(); } -void loop(){ - bar=String(""); // empty the string +void loop() { + bar = String(""); // empty the string // read the sensors and add them to the string - bar=bar+RobotMotor.IRread(1)+' '+RobotMotor.IRread(2)+' '+RobotMotor.IRread(3)+' '+RobotMotor.IRread(4)+' '+RobotMotor.IRread(5); + bar = bar + RobotMotor.IRread(1) + ' ' + RobotMotor.IRread(2) + ' ' + RobotMotor.IRread(3) + ' ' + RobotMotor.IRread(4) + ' ' + RobotMotor.IRread(5); // print out the values Serial.println(bar); delay(100); diff --git a/libraries/Robot_Motor/examples/Robot_Motor_Core/Robot_Motor_Core.ino b/libraries/Robot_Motor/examples/Robot_Motor_Core/Robot_Motor_Core.ino index f74f30a29..e7911d8a3 100644 --- a/libraries/Robot_Motor/examples/Robot_Motor_Core/Robot_Motor_Core.ino +++ b/libraries/Robot_Motor/examples/Robot_Motor_Core/Robot_Motor_Core.ino @@ -1,18 +1,18 @@ /* Motor Core This code for the Arduino Robot's motor board - is the stock firmware. program the motor board with + is the stock firmware. program the motor board with this sketch whenever you want to return the motor board to its default state. - + */ #include -void setup(){ +void setup() { RobotMotor.begin(); } -void loop(){ +void loop() { RobotMotor.parseCommand(); RobotMotor.process(); } diff --git a/libraries/SD/examples/CardInfo/CardInfo.ino b/libraries/SD/examples/CardInfo/CardInfo.ino index 02673c072..03bab2fd6 100644 --- a/libraries/SD/examples/CardInfo/CardInfo.ino +++ b/libraries/SD/examples/CardInfo/CardInfo.ino @@ -1,25 +1,25 @@ /* - SD card test - + SD card test + This example shows how use the utility libraries on which the' SD library is based in order to get info about your SD card. Very useful for testing a card when you're not sure whether its working or not. - + The circuit: * SD card attached to SPI bus as follows: ** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila ** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila ** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila - ** CS - depends on your SD card shield or module. + ** CS - depends on your SD card shield or module. Pin 4 used here for consistency with other Arduino examples - + created 28 Mar 2011 - by Limor Fried + by Limor Fried modified 9 Apr 2012 by Tom Igoe */ - // include the SD library: +// include the SD library: #include #include @@ -32,22 +32,22 @@ SdFile root; // Arduino Ethernet shield: pin 4 // Adafruit SD shields and modules: pin 10 // Sparkfun SD shield: pin 8 -const int chipSelect = 4; +const int chipSelect = 4; void setup() { - // Open serial communications and wait for port to open: + // Open serial communications and wait for port to open: Serial.begin(9600); - while (!Serial) { + while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } Serial.print("\nInitializing SD card..."); // On the Ethernet Shield, CS is pin 4. It's set as an output by default. - // Note that even if it's not used as the CS pin, the hardware SS pin - // (10 on most Arduino boards, 53 on the Mega) must be left as an output - // or the SD library functions will not work. + // Note that even if it's not used as the CS pin, the hardware SS pin + // (10 on most Arduino boards, 53 on the Mega) must be left as an output + // or the SD library functions will not work. pinMode(10, OUTPUT); // change this to 53 on a mega @@ -60,12 +60,12 @@ void setup() Serial.println("* did you change the chipSelect pin to match your shield or module?"); return; } else { - Serial.println("Wiring is correct and a card is present."); + Serial.println("Wiring is correct and a card is present."); } // print the type of card Serial.print("\nCard type: "); - switch(card.type()) { + switch (card.type()) { case SD_CARD_TYPE_SD1: Serial.println("SD1"); break; @@ -91,7 +91,7 @@ void setup() Serial.print("\nVolume type is FAT"); Serial.println(volume.fatType(), DEC); Serial.println(); - + volumesize = volume.blocksPerCluster(); // clusters are collections of blocks volumesize *= volume.clusterCount(); // we'll have a lot of clusters volumesize *= 512; // SD card blocks are always 512 bytes @@ -104,15 +104,15 @@ void setup() volumesize /= 1024; Serial.println(volumesize); - + Serial.println("\nFiles found on the card (name, date and size in bytes): "); root.openRoot(volume); - + // list all files in the card with date and size root.ls(LS_R | LS_DATE | LS_SIZE); } void loop(void) { - + } diff --git a/libraries/SD/examples/Datalogger/Datalogger.ino b/libraries/SD/examples/Datalogger/Datalogger.ino index 30a010e51..70e8f7051 100644 --- a/libraries/SD/examples/Datalogger/Datalogger.ino +++ b/libraries/SD/examples/Datalogger/Datalogger.ino @@ -1,9 +1,9 @@ /* SD card datalogger - - This example shows how to log data from three analog sensors + + This example shows how to log data from three analog sensors to an SD card using the SD library. - + The circuit: * analog sensors on analog ins 0, 1, and 2 * SD card attached to SPI bus as follows: @@ -11,13 +11,13 @@ ** MISO - pin 12 ** CLK - pin 13 ** CS - pin 4 - + created 24 Nov 2010 modified 9 Apr 2012 by Tom Igoe - + This example code is in the public domain. - + */ #include @@ -31,9 +31,9 @@ const int chipSelect = 4; void setup() { - // Open serial communications and wait for port to open: + // Open serial communications and wait for port to open: Serial.begin(9600); - while (!Serial) { + while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } @@ -42,7 +42,7 @@ void setup() // make sure that the default chip select pin is set to // output, even if you don't use it: pinMode(10, OUTPUT); - + // see if the card is present and can be initialized: if (!SD.begin(chipSelect)) { Serial.println("Card failed, or not present"); @@ -62,7 +62,7 @@ void loop() int sensor = analogRead(analogPin); dataString += String(sensor); if (analogPin < 2) { - dataString += ","; + dataString += ","; } } @@ -76,11 +76,11 @@ void loop() dataFile.close(); // print to the serial port too: Serial.println(dataString); - } + } // if the file isn't open, pop up an error: else { Serial.println("error opening datalog.txt"); - } + } } diff --git a/libraries/SD/examples/DumpFile/DumpFile.ino b/libraries/SD/examples/DumpFile/DumpFile.ino index b58d50e2b..b2f510f58 100644 --- a/libraries/SD/examples/DumpFile/DumpFile.ino +++ b/libraries/SD/examples/DumpFile/DumpFile.ino @@ -1,23 +1,23 @@ /* SD card file dump - + This example shows how to read a file from the SD card using the SD library and send it over the serial port. - + The circuit: * SD card attached to SPI bus as follows: ** MOSI - pin 11 ** MISO - pin 12 ** CLK - pin 13 ** CS - pin 4 - + created 22 December 2010 by Limor Fried modified 9 Apr 2012 by Tom Igoe - + This example code is in the public domain. - + */ #include @@ -31,9 +31,9 @@ const int chipSelect = 4; void setup() { - // Open serial communications and wait for port to open: + // Open serial communications and wait for port to open: Serial.begin(9600); - while (!Serial) { + while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } @@ -42,7 +42,7 @@ void setup() // make sure that the default chip select pin is set to // output, even if you don't use it: pinMode(10, OUTPUT); - + // see if the card is present and can be initialized: if (!SD.begin(chipSelect)) { Serial.println("Card failed, or not present"); @@ -50,7 +50,7 @@ void setup() return; } Serial.println("card initialized."); - + // open the file. note that only one file can be open at a time, // so you have to close this one before opening another. File dataFile = SD.open("datalog.txt"); @@ -61,11 +61,11 @@ void setup() Serial.write(dataFile.read()); } dataFile.close(); - } + } // if the file isn't open, pop up an error: else { Serial.println("error opening datalog.txt"); - } + } } void loop() diff --git a/libraries/SD/examples/Files/Files.ino b/libraries/SD/examples/Files/Files.ino index dc172d23a..d49539f38 100644 --- a/libraries/SD/examples/Files/Files.ino +++ b/libraries/SD/examples/Files/Files.ino @@ -1,21 +1,21 @@ /* SD card basic file example - - This example shows how to create and destroy an SD card file + + This example shows how to create and destroy an SD card file The circuit: * SD card attached to SPI bus as follows: ** MOSI - pin 11 ** MISO - pin 12 ** CLK - pin 13 ** CS - pin 4 - + created Nov 2010 by David A. Mellis modified 9 Apr 2012 by Tom Igoe - + This example code is in the public domain. - + */ #include #include @@ -24,18 +24,18 @@ File myFile; void setup() { - // Open serial communications and wait for port to open: + // Open serial communications and wait for port to open: Serial.begin(9600); - while (!Serial) { + while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } Serial.print("Initializing SD card..."); // On the Ethernet Shield, CS is pin 4. It's set as an output by default. - // Note that even if it's not used as the CS pin, the hardware SS pin - // (10 on most Arduino boards, 53 on the Mega) must be left as an output - // or the SD library functions will not work. + // Note that even if it's not used as the CS pin, the hardware SS pin + // (10 on most Arduino boards, 53 on the Mega) must be left as an output + // or the SD library functions will not work. pinMode(10, OUTPUT); if (!SD.begin(4)) { @@ -56,23 +56,23 @@ void setup() myFile = SD.open("example.txt", FILE_WRITE); myFile.close(); - // Check to see if the file exists: + // Check to see if the file exists: if (SD.exists("example.txt")) { Serial.println("example.txt exists."); } else { - Serial.println("example.txt doesn't exist."); + Serial.println("example.txt doesn't exist."); } // delete the file: Serial.println("Removing example.txt..."); SD.remove("example.txt"); - if (SD.exists("example.txt")){ + if (SD.exists("example.txt")) { Serial.println("example.txt exists."); } else { - Serial.println("example.txt doesn't exist."); + Serial.println("example.txt doesn't exist."); } } diff --git a/libraries/SD/examples/ReadWrite/ReadWrite.ino b/libraries/SD/examples/ReadWrite/ReadWrite.ino index 12537c8fe..42d1de388 100644 --- a/libraries/SD/examples/ReadWrite/ReadWrite.ino +++ b/libraries/SD/examples/ReadWrite/ReadWrite.ino @@ -1,23 +1,23 @@ /* SD card read/write - - This example shows how to read and write data to and from an SD card file + + This example shows how to read and write data to and from an SD card file The circuit: * SD card attached to SPI bus as follows: ** MOSI - pin 11 ** MISO - pin 12 ** CLK - pin 13 ** CS - pin 4 - + created Nov 2010 by David A. Mellis modified 9 Apr 2012 by Tom Igoe - + This example code is in the public domain. - + */ - + #include #include @@ -25,62 +25,62 @@ File myFile; void setup() { - // Open serial communications and wait for port to open: + // Open serial communications and wait for port to open: Serial.begin(9600); - while (!Serial) { + while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } Serial.print("Initializing SD card..."); // On the Ethernet Shield, CS is pin 4. It's set as an output by default. - // Note that even if it's not used as the CS pin, the hardware SS pin - // (10 on most Arduino boards, 53 on the Mega) must be left as an output - // or the SD library functions will not work. - pinMode(10, OUTPUT); - + // Note that even if it's not used as the CS pin, the hardware SS pin + // (10 on most Arduino boards, 53 on the Mega) must be left as an output + // or the SD library functions will not work. + pinMode(10, OUTPUT); + if (!SD.begin(4)) { Serial.println("initialization failed!"); return; } Serial.println("initialization done."); - + // open the file. note that only one file can be open at a time, // so you have to close this one before opening another. myFile = SD.open("test.txt", FILE_WRITE); - + // if the file opened okay, write to it: if (myFile) { Serial.print("Writing to test.txt..."); myFile.println("testing 1, 2, 3."); - // close the file: + // close the file: myFile.close(); Serial.println("done."); } else { // if the file didn't open, print an error: Serial.println("error opening test.txt"); } - + // re-open the file for reading: myFile = SD.open("test.txt"); if (myFile) { Serial.println("test.txt:"); - + // read from the file until there's nothing else in it: while (myFile.available()) { - Serial.write(myFile.read()); + Serial.write(myFile.read()); } // close the file: myFile.close(); } else { - // if the file didn't open, print an error: + // if the file didn't open, print an error: Serial.println("error opening test.txt"); } } void loop() { - // nothing happens after setup + // nothing happens after setup } diff --git a/libraries/SD/examples/listfiles/listfiles.ino b/libraries/SD/examples/listfiles/listfiles.ino index 91252097e..ab5a8f52f 100644 --- a/libraries/SD/examples/listfiles/listfiles.ino +++ b/libraries/SD/examples/listfiles/listfiles.ino @@ -1,21 +1,21 @@ /* SD card basic file example - - This example shows how to create and destroy an SD card file + + This example shows how to create and destroy an SD card file The circuit: * SD card attached to SPI bus as follows: ** MOSI - pin 11 ** MISO - pin 12 ** CLK - pin 13 ** CS - pin 4 - + created Nov 2010 by David A. Mellis modified 9 Apr 2012 by Tom Igoe - + This example code is in the public domain. - + */ #include #include @@ -26,16 +26,16 @@ void setup() { // 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 } Serial.print("Initializing SD card..."); // On the Ethernet Shield, CS is pin 4. It's set as an output by default. - // Note that even if it's not used as the CS pin, the hardware SS pin - // (10 on most Arduino boards, 53 on the Mega) must be left as an output - // or the SD library functions will not work. + // Note that even if it's not used as the CS pin, the hardware SS pin + // (10 on most Arduino boards, 53 on the Mega) must be left as an output + // or the SD library functions will not work. pinMode(10, OUTPUT); if (!SD.begin(10)) { @@ -45,9 +45,9 @@ void setup() Serial.println("initialization done."); root = SD.open("/"); - + printDirectory(root, 0); - + Serial.println("done!"); } @@ -57,28 +57,28 @@ void loop() } void printDirectory(File dir, int numTabs) { - while(true) { - - File entry = dir.openNextFile(); - if (! entry) { - // no more files - //Serial.println("**nomorefiles**"); - break; - } - for (uint8_t i=0; i +// Controlling a servo position using a potentiometer (variable resistor) +// by Michal Rinott + +#include + +Servo myservo; // create servo object to control a servo -#include - -Servo myservo; // create servo object to control a servo - int potpin = 0; // analog pin used to connect the potentiometer -int val; // variable to read the value from the analog pin - -void setup() -{ - myservo.attach(9); // attaches the servo on pin 9 to the servo object -} - -void loop() -{ - val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023) - val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180) - myservo.write(val); // sets the servo position according to the scaled value - delay(15); // waits for the servo to get there -} +int val; // variable to read the value from the analog pin + +void setup() +{ + myservo.attach(9); // attaches the servo on pin 9 to the servo object +} + +void loop() +{ + val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023) + val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180) + myservo.write(val); // sets the servo position according to the scaled value + delay(15); // waits for the servo to get there +} diff --git a/libraries/Servo/examples/Sweep/Sweep.ino b/libraries/Servo/examples/Sweep/Sweep.ino index fb326e7e7..abe3f0453 100644 --- a/libraries/Servo/examples/Sweep/Sweep.ino +++ b/libraries/Servo/examples/Sweep/Sweep.ino @@ -1,31 +1,31 @@ // Sweep -// by BARRAGAN +// by BARRAGAN // This example code is in the public domain. -#include - -Servo myservo; // create servo object to control a servo - // a maximum of eight servo objects can be created - -int pos = 0; // variable to store the servo position - -void setup() -{ - myservo.attach(9); // attaches the servo on pin 9 to the servo object -} - - -void loop() -{ - for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees - { // in steps of 1 degree - myservo.write(pos); // tell servo to go to position in variable 'pos' - delay(15); // waits 15ms for the servo to reach the position - } - for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees - { - myservo.write(pos); // tell servo to go to position in variable 'pos' - delay(15); // waits 15ms for the servo to reach the position - } -} +#include + +Servo myservo; // create servo object to control a servo +// a maximum of eight servo objects can be created + +int pos = 0; // variable to store the servo position + +void setup() +{ + myservo.attach(9); // attaches the servo on pin 9 to the servo object +} + + +void loop() +{ + for (pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees + { // in steps of 1 degree + myservo.write(pos); // tell servo to go to position in variable 'pos' + delay(15); // waits 15ms for the servo to reach the position + } + for (pos = 180; pos >= 1; pos -= 1) // goes from 180 degrees to 0 degrees + { + myservo.write(pos); // tell servo to go to position in variable 'pos' + delay(15); // waits 15ms for the servo to reach the position + } +} diff --git a/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino b/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino index 6101bb1ad..f65913301 100644 --- a/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino +++ b/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino @@ -1,35 +1,35 @@ /* Software serial multple serial test - + Receives from the hardware serial, sends to software serial. Receives from software serial, sends to hardware serial. - - The circuit: + + The circuit: * RX is digital pin 10 (connect to TX of other device) * TX is digital pin 11 (connect to RX of other device) - + Note: - Not all pins on the Mega and Mega 2560 support change interrupts, - so only the following can be used for RX: + Not all pins on the Mega and Mega 2560 support change interrupts, + so only the following can be used for RX: 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69 - - Not all pins on the Leonardo support change interrupts, - so only the following can be used for RX: + + Not all pins on the Leonardo support change interrupts, + so only the following can be used for RX: 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI). - + created back in the mists of time modified 25 May 2012 by Tom Igoe based on Mikal Hart's example - + This example code is in the public domain. - + */ #include SoftwareSerial mySerial(10, 11); // RX, TX -void setup() +void setup() { // Open serial communications and wait for port to open: Serial.begin(57600); diff --git a/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino b/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino index d607ee622..95881a6c4 100644 --- a/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino +++ b/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino @@ -1,52 +1,52 @@ /* Software serial multple serial test - - Receives from the two software serial ports, - sends to the hardware serial port. - - In order to listen on a software port, you call port.listen(). + + Receives from the two software serial ports, + sends to the hardware serial port. + + In order to listen on a software port, you call port.listen(). When using two software serial ports, you have to switch ports by listen()ing on each one in turn. Pick a logical time to switch - ports, like the end of an expected transmission, or when the + ports, like the end of an expected transmission, or when the buffer is empty. This example switches ports when there is nothing more to read from a port - - The circuit: + + The circuit: Two devices which communicate serially are needed. * First serial device's TX attached to digital pin 2, RX to pin 3 * Second serial device's TX attached to digital pin 4, RX to pin 5 - + Note: - Not all pins on the Mega and Mega 2560 support change interrupts, - so only the following can be used for RX: + Not all pins on the Mega and Mega 2560 support change interrupts, + so only the following can be used for RX: 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69 - - Not all pins on the Leonardo support change interrupts, - so only the following can be used for RX: + + Not all pins on the Leonardo support change interrupts, + so only the following can be used for RX: 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI). - + created 18 Apr. 2011 modified 25 May 2012 by Tom Igoe based on Mikal Hart's twoPortRXExample - + This example code is in the public domain. - + */ #include // software serial #1: TX = digital pin 10, RX = digital pin 11 -SoftwareSerial portOne(10,11); +SoftwareSerial portOne(10, 11); // software serial #2: TX = digital pin 8, RX = digital pin 9 // on the Mega, use other pins instead, since 8 and 9 don't work on the Mega -SoftwareSerial portTwo(8,9); +SoftwareSerial portTwo(8, 9); void setup() { - // Open serial communications and wait for port to open: + // Open serial communications and wait for port to open: Serial.begin(9600); - while (!Serial) { + while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } diff --git a/libraries/Stepper/examples/stepper_oneRevolution/stepper_oneRevolution.ino b/libraries/Stepper/examples/stepper_oneRevolution/stepper_oneRevolution.ino index 2dbb57d7a..373eb6022 100644 --- a/libraries/Stepper/examples/stepper_oneRevolution/stepper_oneRevolution.ino +++ b/libraries/Stepper/examples/stepper_oneRevolution/stepper_oneRevolution.ino @@ -1,27 +1,27 @@ -/* +/* Stepper Motor Control - one revolution - - This program drives a unipolar or bipolar stepper motor. + + This program drives a unipolar or bipolar stepper motor. The motor is attached to digital pins 8 - 11 of the Arduino. - + The motor should revolve one revolution in one direction, then - one revolution in the other direction. - - + one revolution in the other direction. + + Created 11 Mar. 2007 Modified 30 Nov. 2009 by Tom Igoe - + */ #include const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution - // for your motor +// for your motor // initialize the stepper library on pins 8 through 11: -Stepper myStepper(stepsPerRevolution, 8,9,10,11); +Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11); void setup() { // set the speed at 60 rpm: @@ -32,13 +32,13 @@ void setup() { void loop() { // step one revolution in one direction: - Serial.println("clockwise"); + Serial.println("clockwise"); myStepper.step(stepsPerRevolution); delay(500); - - // step one revolution in the other direction: + + // step one revolution in the other direction: Serial.println("counterclockwise"); myStepper.step(-stepsPerRevolution); - delay(500); + delay(500); } diff --git a/libraries/Stepper/examples/stepper_oneStepAtATime/stepper_oneStepAtATime.ino b/libraries/Stepper/examples/stepper_oneStepAtATime/stepper_oneStepAtATime.ino index 36d32991d..c173e308a 100644 --- a/libraries/Stepper/examples/stepper_oneStepAtATime/stepper_oneStepAtATime.ino +++ b/libraries/Stepper/examples/stepper_oneStepAtATime/stepper_oneStepAtATime.ino @@ -1,30 +1,30 @@ -/* +/* Stepper Motor Control - one step at a time - - This program drives a unipolar or bipolar stepper motor. + + This program drives a unipolar or bipolar stepper motor. The motor is attached to digital pins 8 - 11 of the Arduino. - + The motor will step one step at a time, very slowly. You can use this to test that you've got the four wires of your stepper wired to the correct pins. If wired correctly, all steps should be in the same direction. - + Use this also to count the number of steps per revolution of your motor, if you don't know it. Then plug that number into the oneRevolution example to see if you got it right. - + Created 30 Nov. 2009 by Tom Igoe - + */ #include const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution - // for your motor +// for your motor // initialize the stepper library on pins 8 through 11: -Stepper myStepper(stepsPerRevolution, 8,9,10,11); +Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11); int stepCount = 0; // number of steps the motor has taken diff --git a/libraries/Stepper/examples/stepper_speedControl/stepper_speedControl.ino b/libraries/Stepper/examples/stepper_speedControl/stepper_speedControl.ino index 1a67a55ea..5eb4f6a66 100644 --- a/libraries/Stepper/examples/stepper_speedControl/stepper_speedControl.ino +++ b/libraries/Stepper/examples/stepper_speedControl/stepper_speedControl.ino @@ -1,20 +1,20 @@ -/* +/* Stepper Motor Control - speed control - - This program drives a unipolar or bipolar stepper motor. + + This program drives a unipolar or bipolar stepper motor. The motor is attached to digital pins 8 - 11 of the Arduino. A potentiometer is connected to analog input 0. - + The motor will rotate in a clockwise direction. The higher the potentiometer value, - the faster the motor speed. Because setSpeed() sets the delay between steps, + the faster the motor speed. Because setSpeed() sets the delay between steps, you may notice the motor is less responsive to changes in the sensor value at low speeds. - + Created 30 Nov. 2009 Modified 28 Oct 2010 by Tom Igoe - + */ #include @@ -24,7 +24,7 @@ const int stepsPerRevolution = 200; // change this to fit the number of steps p // initialize the stepper library on pins 8 through 11: -Stepper myStepper(stepsPerRevolution, 8,9,10,11); +Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11); int stepCount = 0; // number of steps the motor has taken @@ -41,8 +41,8 @@ void loop() { if (motorSpeed > 0) { myStepper.setSpeed(motorSpeed); // step 1/100 of a revolution: - myStepper.step(stepsPerRevolution/100); - } + myStepper.step(stepsPerRevolution / 100); + } } diff --git a/libraries/TFT/examples/Arduino/TFTBitmapLogo/TFTBitmapLogo.ino b/libraries/TFT/examples/Arduino/TFTBitmapLogo/TFTBitmapLogo.ino index da7a94d41..3b8d2cb10 100644 --- a/libraries/TFT/examples/Arduino/TFTBitmapLogo/TFTBitmapLogo.ino +++ b/libraries/TFT/examples/Arduino/TFTBitmapLogo/TFTBitmapLogo.ino @@ -1,24 +1,24 @@ /* Arduino TFT Bitmap Logo example - + This example reads an image file from a micro-SD card and draws it on the screen, at random locations. - + In this sketch, the Arduino logo is read from a micro-SD card. - There is a .bmp file included with this sketch. + There is a .bmp file included with this sketch. - open the sketch folder (Ctrl-K or Cmd-K) - copy the "arduino.bmp" file to a micro-SD - put the SD into the SD slot of the Arduino TFT module. - + This example code is in the public domain. - + Created 19 April 2013 by Enrico Gueli - + http://arduino.cc/en/Tutorial/TFTBitmapLogo - + */ - + // include the necessary libraries #include #include @@ -28,13 +28,13 @@ #define sd_cs 4 #define lcd_cs 10 #define dc 9 -#define rst 8 +#define rst 8 // pin definition for the Leonardo //#define sd_cs 8 //#define lcd_cs 7 //#define dc 0 -//#define rst 1 +//#define rst 1 TFT TFTscreen = TFT(lcd_cs, dc, rst); @@ -55,8 +55,8 @@ void setup() { TFTscreen.println("Open serial monitor"); TFTscreen.println("to run the sketch"); - // initialize the serial port: it will be used to - // print some diagnostic info + // initialize the serial port: it will be used to + // print some diagnostic info Serial.begin(9600); while (!Serial) { // wait for serial line to be ready @@ -64,7 +64,7 @@ void setup() { // clear the GLCD screen before starting TFTscreen.background(255, 255, 255); - + // try to access the SD card. If that fails (e.g. // no card present), the setup process will stop. Serial.print("Initializing SD card..."); @@ -73,7 +73,7 @@ void setup() { return; } Serial.println("OK!"); - + // initialize and clear the GLCD screen TFTscreen.begin(); TFTscreen.background(255, 255, 255); @@ -91,7 +91,7 @@ void loop() { if (logo.isValid() == false) { return; } - + Serial.println("drawing image"); // get a random location where to draw the image. diff --git a/libraries/TFT/examples/Arduino/TFTColorPicker/TFTColorPicker.ino b/libraries/TFT/examples/Arduino/TFTColorPicker/TFTColorPicker.ino index 74fc17631..da921939c 100644 --- a/libraries/TFT/examples/Arduino/TFTColorPicker/TFTColorPicker.ino +++ b/libraries/TFT/examples/Arduino/TFTColorPicker/TFTColorPicker.ino @@ -1,28 +1,28 @@ /* TFT Color Picker - - This example for the Arduino screen reads the input of + + This example for the Arduino screen reads the input of potentiometers or analog sensors attached to A0, A1, and A2 and uses the values to change the screen's color. - + This example code is in the public domain. - + Created 15 April 2013 by Scott Fitzgerald - + http://arduino.cc/en/Tutorial/TFTColorPicker - + */ - + // pin definition for the Uno #define cs 10 #define dc 9 -#define rst 8 +#define rst 8 // pin definition for the Leonardo // #define cs 7 // #define dc 0 -// #define rst 1 +// #define rst 1 #include // Arduino LCD library #include @@ -44,13 +44,13 @@ void setup() { void loop() { // read the values from your sensors and scale them to 0-255 - int redVal = map(analogRead(A0), 0, 1023, 0, 255); - int greenVal = map(analogRead(A1), 0, 1023, 0, 255); + int redVal = map(analogRead(A0), 0, 1023, 0, 255); + int greenVal = map(analogRead(A1), 0, 1023, 0, 255); int blueVal = map(analogRead(A2), 0, 1023, 0, 255); - + // draw the background based on the mapped values TFTscreen.background(redVal, greenVal, blueVal); - + // send the values to the serial monitor Serial.print("background("); Serial.print(redVal); @@ -59,7 +59,7 @@ void loop() { Serial.print(" , "); Serial.print(blueVal); Serial.println(")"); - + // wait for a moment delay(33); diff --git a/libraries/TFT/examples/Arduino/TFTDisplayText/TFTDisplayText.ino b/libraries/TFT/examples/Arduino/TFTDisplayText/TFTDisplayText.ino index f482bd1cf..b4d6cd695 100644 --- a/libraries/TFT/examples/Arduino/TFTDisplayText/TFTDisplayText.ino +++ b/libraries/TFT/examples/Arduino/TFTDisplayText/TFTDisplayText.ino @@ -1,18 +1,18 @@ /* Arduino TFT text example - - This example demonstrates how to draw text on the - TFT with an Arduino. The Arduino reads the value - of an analog sensor attached to pin A0, and writes + + This example demonstrates how to draw text on the + TFT with an Arduino. The Arduino reads the value + of an analog sensor attached to pin A0, and writes the value to the LCD screen, updating every quarter second. - + This example code is in the public domain Created 15 April 2013 by Scott Fitzgerald - + http://arduino.cc/en/Tutorial/TFTDisplayText - + */ #include // Arduino LCD library @@ -21,12 +21,12 @@ // pin definition for the Uno #define cs 10 #define dc 9 -#define rst 8 +#define rst 8 // pin definition for the Leonardo // #define cs 7 // #define dc 0 -// #define rst 1 +// #define rst 1 // create an instance of the library TFT TFTscreen = TFT(cs, dc, rst); @@ -35,20 +35,20 @@ TFT TFTscreen = TFT(cs, dc, rst); char sensorPrintout[4]; void setup() { - + // Put this line at the beginning of every sketch that uses the GLCD: TFTscreen.begin(); // clear the screen with a black background TFTscreen.background(0, 0, 0); - + // write the static text to the screen // set the font color to white - TFTscreen.stroke(255,255,255); + TFTscreen.stroke(255, 255, 255); // set the font size TFTscreen.setTextSize(2); // write the text to the top left corner of the screen - TFTscreen.text("Sensor Value :\n ",0,0); + TFTscreen.text("Sensor Value :\n ", 0, 0); // ste the font size very large for the loop TFTscreen.setTextSize(5); } @@ -57,18 +57,18 @@ void loop() { // Read the value of the sensor on A0 String sensorVal = String(analogRead(A0)); - + // convert the reading to a char array sensorVal.toCharArray(sensorPrintout, 4); // set the font color - TFTscreen.stroke(255,255,255); + TFTscreen.stroke(255, 255, 255); // print the sensor value TFTscreen.text(sensorPrintout, 0, 20); // wait for a moment delay(250); // erase the text you just wrote - TFTscreen.stroke(0,0,0); + TFTscreen.stroke(0, 0, 0); TFTscreen.text(sensorPrintout, 0, 20); } diff --git a/libraries/TFT/examples/Arduino/TFTEtchASketch/TFTEtchASketch.ino b/libraries/TFT/examples/Arduino/TFTEtchASketch/TFTEtchASketch.ino index 29e3483b6..7facbc31f 100644 --- a/libraries/TFT/examples/Arduino/TFTEtchASketch/TFTEtchASketch.ino +++ b/libraries/TFT/examples/Arduino/TFTEtchASketch/TFTEtchASketch.ino @@ -1,37 +1,37 @@ /* TFT EtchASketch - + This example for the Arduino screen draws a white point - on the GLCD based on the values of 2 potentiometers. + on the GLCD based on the values of 2 potentiometers. To clear the screen, press a button attached to pin 2. - + This example code is in the public domain. - + Created 15 April 2013 by Scott Fitzgerald - + http://arduino.cc/en/Tutorial/TFTEtchASketch - + */ - + #include // Arduino LCD library #include // pin definition for the Uno #define cs 10 #define dc 9 -#define rst 8 +#define rst 8 // pin definition for the Leonardo // #define cs 7 // #define dc 0 -// #define rst 1 +// #define rst 1 TFT TFTscreen = TFT(cs, dc, rst); // initial position of the cursor -int xPos = TFTscreen.width()/2; -int yPos = TFTscreen.height()/2; +int xPos = TFTscreen.width() / 2; +int yPos = TFTscreen.height() / 2; // pin the erase switch is connected to int erasePin = 2; @@ -42,43 +42,43 @@ void setup() { // initialize the screen TFTscreen.begin(); // make the background black - TFTscreen.background(0,0,0); + TFTscreen.background(0, 0, 0); } void loop() { - // read the potentiometers on A0 and A1 + // read the potentiometers on A0 and A1 int xValue = analogRead(A0); int yValue = analogRead(A1); // map the values and update the position xPos = xPos + (map(xValue, 0, 1023, 2, -2)); yPos = yPos + (map(yValue, 0, 1023, -2, 2)); - -// don't let the point go past the screen edges - if(xPos > 159){ + + // don't let the point go past the screen edges + if (xPos > 159) { (xPos = 159); } - if(xPos < 0){ + if (xPos < 0) { (xPos = 0); } - if(yPos > 127){ + if (yPos > 127) { (yPos = 127); } - if(yPos < 0){ + if (yPos < 0) { (yPos = 0); } - + // draw the point - TFTscreen.stroke(255,255,255); - TFTscreen.point(xPos,yPos); + TFTscreen.stroke(255, 255, 255); + TFTscreen.point(xPos, yPos); // read the value of the pin, and erase the screen if pressed - if(digitalRead(erasePin) == HIGH){ - TFTscreen.background(0,0,0); + if (digitalRead(erasePin) == HIGH) { + TFTscreen.background(0, 0, 0); } - delay(33); + delay(33); } diff --git a/libraries/TFT/examples/Arduino/TFTGraph/TFTGraph.ino b/libraries/TFT/examples/Arduino/TFTGraph/TFTGraph.ino index 39ae49b93..83fcd328d 100644 --- a/libraries/TFT/examples/Arduino/TFTGraph/TFTGraph.ino +++ b/libraries/TFT/examples/Arduino/TFTGraph/TFTGraph.ino @@ -1,38 +1,38 @@ /* TFT Graph - - This example for an Arduino screen reads - the value of an analog sensor on A0, and + + This example for an Arduino screen reads + the value of an analog sensor on A0, and graphs the values on the screen. - + This example code is in the public domain. - + Created 15 April 2013 by Scott Fitzgerald - + http://arduino.cc/en/Tutorial/TFTGraph - + */ #include // Arduino LCD library #include - - // pin definition for the Uno + +// pin definition for the Uno #define cs 10 #define dc 9 -#define rst 8 +#define rst 8 // pin definition for the Leonardo // #define cs 7 // #define dc 0 -// #define rst 1 +// #define rst 1 TFT TFTscreen = TFT(cs, dc, rst); // position of the line on screen int xPos = 0; -void setup(){ +void setup() { // initialize the serial port Serial.begin(9600); @@ -40,27 +40,27 @@ void setup(){ TFTscreen.begin(); // clear the screen with a pretty color - TFTscreen.background(250,16,200); + TFTscreen.background(250, 16, 200); } -void loop(){ +void loop() { // read the sensor and map it to the screen height int sensor = analogRead(A0); - int drawHeight = map(sensor,0,1023,0,TFTscreen.height()); - + int drawHeight = map(sensor, 0, 1023, 0, TFTscreen.height()); + // print out the height to the serial monitor Serial.println(drawHeight); - + // draw a line in a nice color - TFTscreen.stroke(250,180,10); - TFTscreen.line(xPos, TFTscreen.height()-drawHeight, xPos, TFTscreen.height()); + TFTscreen.stroke(250, 180, 10); + TFTscreen.line(xPos, TFTscreen.height() - drawHeight, xPos, TFTscreen.height()); // if the graph has reached the screen edge // erase the screen and start again if (xPos >= 160) { xPos = 0; - TFTscreen.background(250,16,200); - } + TFTscreen.background(250, 16, 200); + } else { // increment the horizontal position: xPos++; diff --git a/libraries/TFT/examples/Arduino/TFTPong/TFTPong.ino b/libraries/TFT/examples/Arduino/TFTPong/TFTPong.ino index 02ea11c4f..74c605b83 100644 --- a/libraries/TFT/examples/Arduino/TFTPong/TFTPong.ino +++ b/libraries/TFT/examples/Arduino/TFTPong/TFTPong.ino @@ -1,19 +1,19 @@ /* TFT Pong - - This example for the Arduino screen reads the values + + This example for the Arduino screen reads the values of 2 potentiometers to move a rectangular platform - on the x and y axes. The platform can intersect - with a ball causing it to bounce. - + on the x and y axes. The platform can intersect + with a ball causing it to bounce. + This example code is in the public domain. - + Created by Tom Igoe December 2012 Modified 15 April 2013 by Scott Fitzgerald - + http://arduino.cc/en/Tutorial/TFTPong - + */ #include // Arduino LCD library @@ -22,12 +22,12 @@ // pin definition for the Uno #define cs 10 #define dc 9 -#define rst 8 +#define rst 8 // pin definition for the Leonardo // #define cs 7 // #define dc 0 -// #define rst 1 +// #define rst 1 TFT TFTscreen = TFT(cs, dc, rst); @@ -46,7 +46,7 @@ void setup() { // initialize the display TFTscreen.begin(); // black background - TFTscreen.background(0,0,0); + TFTscreen.background(0, 0, 0); } void loop() { @@ -54,22 +54,22 @@ void loop() { // save the width and height of the screen int myWidth = TFTscreen.width(); int myHeight = TFTscreen.height(); - - // map the paddle's location to the position of the potentiometers - paddleX = map(analogRead(A0), 512, -512, 0, myWidth) - 20/2; - paddleY = map(analogRead(A1), 512, -512, 0, myHeight) - 5/2; - - // set the fill color to black and erase the previous - // position of the paddle if different from present - TFTscreen.fill(0,0,0); - if (oldPaddleX != paddleX || oldPaddleY != paddleY) { + // map the paddle's location to the position of the potentiometers + paddleX = map(analogRead(A0), 512, -512, 0, myWidth) - 20 / 2; + paddleY = map(analogRead(A1), 512, -512, 0, myHeight) - 5 / 2; + + // set the fill color to black and erase the previous + // position of the paddle if different from present + TFTscreen.fill(0, 0, 0); + + if (oldPaddleX != paddleX || oldPaddleY != paddleY) { TFTscreen.rect(oldPaddleX, oldPaddleY, 20, 5); } // draw the paddle on screen, save the current position // as the previous. - TFTscreen.fill(255,255,255); + TFTscreen.fill(255, 255, 255); TFTscreen.rect(paddleX, paddleY, 20, 5); oldPaddleX = paddleX; @@ -77,59 +77,59 @@ void loop() { // update the ball's position and draw it on screen if (millis() % ballSpeed < 2) { - moveBall(); + moveBall(); } } // this function determines the ball's position on screen void moveBall() { // if the ball goes offscreen, reverse the direction: - if (ballX > TFTscreen.width() || ballX < 0) { - ballDirectionX = -ballDirectionX; - } - + if (ballX > TFTscreen.width() || ballX < 0) { + ballDirectionX = -ballDirectionX; + } + if (ballY > TFTscreen.height() || ballY < 0) { - ballDirectionY = -ballDirectionY; - } - + ballDirectionY = -ballDirectionY; + } + // check if the ball and the paddle occupy the same space on screen if (inPaddle(ballX, ballY, paddleX, paddleY, 20, 5)) { ballDirectionX = -ballDirectionX; ballDirectionY = -ballDirectionY; - } - - // update the ball's position - ballX += ballDirectionX; - ballY += ballDirectionY; - -// erase the ball's previous position - TFTscreen.fill(0,0,0); - + } + + // update the ball's position + ballX += ballDirectionX; + ballY += ballDirectionY; + + // erase the ball's previous position + TFTscreen.fill(0, 0, 0); + if (oldBallX != ballX || oldBallY != ballY) { TFTscreen.rect(oldBallX, oldBallY, 5, 5); } - - + + // draw the ball's current position - TFTscreen.fill(255,255,255); + TFTscreen.fill(255, 255, 255); TFTscreen.rect(ballX, ballY, 5, 5); - + oldBallX = ballX; oldBallY = ballY; - + } // this function checks the position of the ball // to see if it intersects with the paddle boolean inPaddle(int x, int y, int rectX, int rectY, int rectWidth, int rectHeight) { boolean result = false; - - if ((x >= rectX && x <= (rectX + rectWidth)) && + + if ((x >= rectX && x <= (rectX + rectWidth)) && (y >= rectY && y <= (rectY + rectHeight))) { - result = true; - } - -return result; + result = true; + } + + return result; } diff --git a/libraries/TFT/examples/Esplora/EsploraTFTBitmapLogo/EsploraTFTBitmapLogo.ino b/libraries/TFT/examples/Esplora/EsploraTFTBitmapLogo/EsploraTFTBitmapLogo.ino index 3d3f230ce..46d7691de 100644 --- a/libraries/TFT/examples/Esplora/EsploraTFTBitmapLogo/EsploraTFTBitmapLogo.ino +++ b/libraries/TFT/examples/Esplora/EsploraTFTBitmapLogo/EsploraTFTBitmapLogo.ino @@ -1,26 +1,26 @@ /* Esplora TFT Bitmap Logos - + This example for the Arduino TFT screen is for use with an Arduino Esplora. - + This example reads an image file from a micro-SD card and draws it on the screen, at random locations. - - There is a .bmp file included with this sketch. + + There is a .bmp file included with this sketch. - open the sketch folder (Ctrl-K or Cmd-K) - copy the "arduino.bmp" file to a micro-SD - put the SD into the SD slot of the Arduino LCD module. - + This example code is in the public domain. - + Created 19 April 2013 by Enrico Gueli - + http://arduino.cc/en/Tutorial/EsploraTFTBitmapLogo - + */ - + // include the necessary libraries #include #include @@ -46,13 +46,13 @@ void setup() { EsploraTFT.println("Open serial monitor"); EsploraTFT.println("to run the sketch"); - // initialize the serial port: it will be used to + // initialize the serial port: it will be used to // print some diagnostic info Serial.begin(9600); while (!Serial) { // wait for serial monitor to be open } - + // try to access the SD card. If that fails (e.g. // no card present), the Esplora's LED will turn red. Serial.print("Initializing SD card..."); @@ -62,10 +62,10 @@ void setup() { return; } Serial.println("OK!"); - + // clear the GLCD screen before starting EsploraTFT.background(255, 255, 255); - + // now that the SD card can be access, try to load the // image file. The Esplora LED will turn green or red if // the loading went OK or not. @@ -84,18 +84,18 @@ void loop() { if (logo.isValid() == false) { return; } - + Serial.println("drawing image"); - + // get a random location where to draw the image. // To avoid the image to be draw outside the screen, // take into account the image size. int x = random(EsploraTFT.width() - logo.width()); int y = random(EsploraTFT.height() - logo.height()); - + // draw the image to the screen EsploraTFT.image(logo, x, y); - + // wait a little bit before drawing again delay(1500); } diff --git a/libraries/TFT/examples/Esplora/EsploraTFTColorPicker/EsploraTFTColorPicker.ino b/libraries/TFT/examples/Esplora/EsploraTFTColorPicker/EsploraTFTColorPicker.ino index 63a0ee216..0d9e42599 100644 --- a/libraries/TFT/examples/Esplora/EsploraTFTColorPicker/EsploraTFTColorPicker.ino +++ b/libraries/TFT/examples/Esplora/EsploraTFTColorPicker/EsploraTFTColorPicker.ino @@ -1,17 +1,17 @@ /* Esplora TFT Color Picker - - This example for the Esplora with an Arduino TFT reads + + This example for the Esplora with an Arduino TFT reads the input of the joystick and slider, using the values to change the screen's color. - + This example code is in the public domain. - + Created 15 April 2013 by Scott Fitzgerald - + http://arduino.cc/en/Tutorial/TFTColorPicker - + */ #include @@ -35,10 +35,10 @@ void loop() { int xValue = map(Esplora.readJoystickX(), -512, 512, 0, 255); // read the joystick's X position int yValue = map(Esplora.readJoystickY(), -512, 512, 0, 255); // read the joystick's Y position int slider = map(Esplora.readSlider(), 0, 1023, 0, 255); // read the slider's position - + // change the background color based on the mapped values EsploraTFT.background(xValue, yValue, slider); - + // print the mapped values to the Serial monitor Serial.print("background("); Serial.print(xValue); @@ -47,7 +47,7 @@ void loop() { Serial.print(" , "); Serial.print(slider); Serial.println(")"); - + delay(33); } diff --git a/libraries/TFT/examples/Esplora/EsploraTFTEtchASketch/EsploraTFTEtchASketch.ino b/libraries/TFT/examples/Esplora/EsploraTFTEtchASketch/EsploraTFTEtchASketch.ino index a1430d301..24f1901f2 100644 --- a/libraries/TFT/examples/Esplora/EsploraTFTEtchASketch/EsploraTFTEtchASketch.ino +++ b/libraries/TFT/examples/Esplora/EsploraTFTEtchASketch/EsploraTFTEtchASketch.ino @@ -1,34 +1,34 @@ /* Esplora TFT EtchASketch - - This example for the Arduino TFT and Esplora draws - a white line on the screen, based on the position - of the joystick. To clear the screen, shake the + + This example for the Arduino TFT and Esplora draws + a white line on the screen, based on the position + of the joystick. To clear the screen, shake the Esplora, using the values from the accelerometer. - + This example code is in the public domain. - + Created 15 April 2013 by Scott Fitzgerald - + http://arduino.cc/en/Tutorial/EsploraTFTEtchASketch - + */ - + #include #include // Arduino LCD library #include // initial position of the cursor -int xPos = EsploraTFT.width()/2; -int yPos = EsploraTFT.height()/2; +int xPos = EsploraTFT.width() / 2; +int yPos = EsploraTFT.height() / 2; void setup() { // initialize the display EsploraTFT.begin(); - + // clear the background - EsploraTFT.background(0,0,0); + EsploraTFT.background(0, 0, 0); } void loop() @@ -39,45 +39,45 @@ void loop() // update the position of the line // depending on the position of the joystick - if (xAxis<10 && xAxis>-10){ - xPos=xPos; + if (xAxis < 10 && xAxis > -10) { + xPos = xPos; } - else{ + else { xPos = xPos + (map(xAxis, -512, 512, 2, -2)); } - if (yAxis<10 && yAxis>-10){ - yAxis=yAxis; + if (yAxis < 10 && yAxis > -10) { + yAxis = yAxis; } - else{ + else { yPos = yPos + (map(yAxis, -512, 512, -2, 2)); } -// don't let the point go past the screen edges - if(xPos > 159){ + // don't let the point go past the screen edges + if (xPos > 159) { (xPos = 159); } - if(xPos < 0){ + if (xPos < 0) { (xPos = 0); } - if(yPos > 127){ + if (yPos > 127) { (yPos = 127); } - if(yPos < 0){ + if (yPos < 0) { (yPos = 0); } - + // draw the point - EsploraTFT.stroke(255,255,255); - EsploraTFT.point(xPos,yPos); + EsploraTFT.stroke(255, 255, 255); + EsploraTFT.point(xPos, yPos); // check the accelerometer values and clear - // the screen if it is being shaken - if(abs(Esplora.readAccelerometer(X_AXIS))>200 || abs(Esplora.readAccelerometer(Y_AXIS))>200){ - EsploraTFT.background(0,0,0); + // the screen if it is being shaken + if (abs(Esplora.readAccelerometer(X_AXIS)) > 200 || abs(Esplora.readAccelerometer(Y_AXIS)) > 200) { + EsploraTFT.background(0, 0, 0); } - - delay(33); + + delay(33); } diff --git a/libraries/TFT/examples/Esplora/EsploraTFTGraph/EsploraTFTGraph.ino b/libraries/TFT/examples/Esplora/EsploraTFTGraph/EsploraTFTGraph.ino index 7f2a42761..e46c03c50 100644 --- a/libraries/TFT/examples/Esplora/EsploraTFTGraph/EsploraTFTGraph.ino +++ b/libraries/TFT/examples/Esplora/EsploraTFTGraph/EsploraTFTGraph.ino @@ -1,17 +1,17 @@ /* Esplora TFT Graph - - This example for the Esplora with an Arduino TFT reads + + This example for the Esplora with an Arduino TFT reads the value of the light sensor, and graphs the values on the screen. - + This example code is in the public domain. - + Created 15 April 2013 by Scott Fitzgerald - + http://arduino.cc/en/Tutorial/EsploraTFTGraph - + */ #include @@ -21,32 +21,32 @@ // position of the line on screen int xPos = 0; -void setup(){ +void setup() { // initialize the screen EsploraTFT.begin(); // clear the screen with a nice color - EsploraTFT.background(250,16,200); + EsploraTFT.background(250, 16, 200); } -void loop(){ +void loop() { // read the sensor value int sensor = Esplora.readLightSensor(); // map the sensor value to the height of the screen - int graphHeight = map(sensor,0,1023,0,EsploraTFT.height()); + int graphHeight = map(sensor, 0, 1023, 0, EsploraTFT.height()); // draw the line in a pretty color - EsploraTFT.stroke(250,180,10); + EsploraTFT.stroke(250, 180, 10); EsploraTFT.line(xPos, EsploraTFT.height() - graphHeight, xPos, EsploraTFT.height()); // if the graph reaches the edge of the screen // erase it and start over from the other side if (xPos >= 160) { xPos = 0; - EsploraTFT.background(250,16,200); - } + EsploraTFT.background(250, 16, 200); + } else { // increment the horizontal position: xPos++; diff --git a/libraries/TFT/examples/Esplora/EsploraTFTHorizon/EsploraTFTHorizon.ino b/libraries/TFT/examples/Esplora/EsploraTFTHorizon/EsploraTFTHorizon.ino index a7945c931..3be485d8d 100644 --- a/libraries/TFT/examples/Esplora/EsploraTFTHorizon/EsploraTFTHorizon.ino +++ b/libraries/TFT/examples/Esplora/EsploraTFTHorizon/EsploraTFTHorizon.ino @@ -1,17 +1,17 @@ /* Esplora TFT Horizon - - This example for the Arduino TFT and Esplora draws + + This example for the Arduino TFT and Esplora draws a line on the screen that stays level with the ground as you tile the Esplora side to side - + This example code is in the public domain. - + Created 15 April 2013 by Scott Fitzgerald - + http://arduino.cc/en/Tutorial/EsploraTFTHorizon - + */ #include @@ -19,8 +19,8 @@ #include // horizontal start and end positions -int yStart = EsploraTFT.height()/2; -int yEnd = EsploraTFT.height()/2; +int yStart = EsploraTFT.height() / 2; +int yEnd = EsploraTFT.height() / 2; // previous start and end positions int oldEndY; @@ -30,7 +30,7 @@ void setup() { // initialize the display EsploraTFT.begin(); // make the background black - EsploraTFT.background(0,0,0); + EsploraTFT.background(0, 0, 0); } void loop() @@ -41,23 +41,23 @@ void loop() // the values are 100 when tilted to the left // and -100 when tilted to the right // map these values to the start and end points - yStart = map(tilt,-100,100,EsploraTFT.height(),0); - yEnd = map(tilt,-100,100,0,EsploraTFT.height()); + yStart = map(tilt, -100, 100, EsploraTFT.height(), 0); + yEnd = map(tilt, -100, 100, 0, EsploraTFT.height()); // if the previous values are different than the current values // erase the previous line if (oldStartY != yStart || oldEndY != yEnd) { - EsploraTFT.stroke(0,0,0); + EsploraTFT.stroke(0, 0, 0); EsploraTFT.line(0, oldStartY, EsploraTFT.width(), oldEndY); } // draw the line in magenta - EsploraTFT.stroke(255,0,255); - EsploraTFT.line(0,yStart,EsploraTFT.width(),yEnd); + EsploraTFT.stroke(255, 0, 255); + EsploraTFT.line(0, yStart, EsploraTFT.width(), yEnd); // save the current start and end points // to compare int he next loop - oldStartY= yStart; + oldStartY = yStart; oldEndY = yEnd; - delay(10); + delay(10); } diff --git a/libraries/TFT/examples/Esplora/EsploraTFTPong/EsploraTFTPong.ino b/libraries/TFT/examples/Esplora/EsploraTFTPong/EsploraTFTPong.ino index e3422d48d..e6c793df7 100644 --- a/libraries/TFT/examples/Esplora/EsploraTFTPong/EsploraTFTPong.ino +++ b/libraries/TFT/examples/Esplora/EsploraTFTPong/EsploraTFTPong.ino @@ -1,20 +1,20 @@ /* Esplora TFT Pong - - This example for the Esplora with an Arduino TFT screen reads + + This example for the Esplora with an Arduino TFT screen reads the value of the joystick to move a rectangular platform on the x and y axes. The platform can intersect with a ball causing it to bounce. The Esplora's slider adjusts the speed of the ball. - + This example code is in the public domain. - + Created by Tom Igoe December 2012 Modified 15 April 2013 by Scott Fitzgerald - + http://arduino.cc/en/Tutorial/EsploraTFTPong - + */ #include @@ -37,7 +37,7 @@ void setup() { // initialize the display EsploraTFT.begin(); // set the background the black - EsploraTFT.background(0,0,0); + EsploraTFT.background(0, 0, 0); } void loop() { @@ -45,16 +45,16 @@ void loop() { int myWidth = EsploraTFT.width(); int myHeight = EsploraTFT.height(); - // map the paddle's location to the joystick's position - paddleX = map(Esplora.readJoystickX(), 512, -512, 0, myWidth) - 20/2; - paddleY = map(Esplora.readJoystickY(), -512, 512, 0, myHeight) - 5/2; + // map the paddle's location to the joystick's position + paddleX = map(Esplora.readJoystickX(), 512, -512, 0, myWidth) - 20 / 2; + paddleY = map(Esplora.readJoystickY(), -512, 512, 0, myHeight) - 5 / 2; Serial.print(paddleX); Serial.print(" "); Serial.println(paddleY); - // set the fill color to black and erase the previous + // set the fill color to black and erase the previous // position of the paddle if different from present - EsploraTFT.fill(0,0,0); + EsploraTFT.fill(0, 0, 0); if (oldPaddleX != paddleX || oldPaddleY != paddleY) { EsploraTFT.rect(oldPaddleX, oldPaddleY, 20, 5); @@ -62,13 +62,13 @@ void loop() { // draw the paddle on screen, save the current position // as the previous. - EsploraTFT.fill(255,255,255); + EsploraTFT.fill(255, 255, 255); EsploraTFT.rect(paddleX, paddleY, 20, 5); oldPaddleX = paddleX; oldPaddleY = paddleY; // read the slider to determinde the speed of the ball - int ballSpeed = map(Esplora.readSlider(), 0, 1023, 0, 80)+1; + int ballSpeed = map(Esplora.readSlider(), 0, 1023, 0, 80) + 1; if (millis() % ballSpeed < 2) { moveBall(); } @@ -84,7 +84,7 @@ void moveBall() { if (ballY > EsploraTFT.height() || ballY < 0) { ballDirectionY = -ballDirectionY; - } + } // check if the ball and the paddle occupy the same space on screen if (inPaddle(ballX, ballY, paddleX, paddleY, 20, 5)) { @@ -96,14 +96,14 @@ void moveBall() { ballY += ballDirectionY; // erase the ball's previous position - EsploraTFT.fill(0,0,0); + EsploraTFT.fill(0, 0, 0); if (oldBallX != ballX || oldBallY != ballY) { EsploraTFT.rect(oldBallX, oldBallY, 5, 5); } // draw the ball's current position - EsploraTFT.fill(255,255,255); + EsploraTFT.fill(255, 255, 255); EsploraTFT.rect(ballX, ballY, 5, 5); @@ -117,10 +117,10 @@ void moveBall() { boolean inPaddle(int x, int y, int rectX, int rectY, int rectWidth, int rectHeight) { boolean result = false; - if ((x >= rectX && x <= (rectX + rectWidth)) && - (y >= rectY && y <= (rectY + rectHeight))) { - result = true; + if ((x >= rectX && x <= (rectX + rectWidth)) && + (y >= rectY && y <= (rectY + rectHeight))) { + result = true; } - return result; + return result; } diff --git a/libraries/TFT/examples/Esplora/EsploraTFTTemp/EsploraTFTTemp.ino b/libraries/TFT/examples/Esplora/EsploraTFTTemp/EsploraTFTTemp.ino index b475d2da7..f3c529482 100644 --- a/libraries/TFT/examples/Esplora/EsploraTFTTemp/EsploraTFTTemp.ino +++ b/libraries/TFT/examples/Esplora/EsploraTFTTemp/EsploraTFTTemp.ino @@ -1,24 +1,24 @@ /* Esplora TFT Temperature Display - + This example for the Arduino TFT screen is for use with an Arduino Esplora. - + This example reads the temperature of the Esplora's on board thermisistor and displays it on an attached LCD screen, updating every second. - + This example code is in the public domain. - + Created 15 April 2013 by Scott Fitzgerald - + http://arduino.cc/en/Tutorial/EsploraTFTTemp - + */ // include the necessary libraries -#include +#include #include // Arduino LCD library #include @@ -30,15 +30,15 @@ void setup() { EsploraTFT.begin(); // clear the screen with a black background - EsploraTFT.background(0,0,0); - + EsploraTFT.background(0, 0, 0); + // set the text color to magenta - EsploraTFT.stroke(200,20,180); + EsploraTFT.stroke(200, 20, 180); // set the text to size 2 EsploraTFT.setTextSize(2); // start the text at the top left of the screen // this text is going to remain static - EsploraTFT.text("Degrees in C :\n ",0,0); + EsploraTFT.text("Degrees in C :\n ", 0, 0); // set the text in the loop to size 5 EsploraTFT.setTextSize(5); @@ -53,12 +53,12 @@ void loop() { temperature.toCharArray(tempPrintout, 3); // set the text color to white - EsploraTFT.stroke(255,255,255); + EsploraTFT.stroke(255, 255, 255); // print the temperature one line below the static text EsploraTFT.text(tempPrintout, 0, 30); - + delay(1000); // erase the text for the next loop - EsploraTFT.stroke(0,0,0); + EsploraTFT.stroke(0, 0, 0); EsploraTFT.text(tempPrintout, 0, 30); } diff --git a/libraries/USBHost/examples/ADKTerminalTest/ADKTerminalTest.ino b/libraries/USBHost/examples/ADKTerminalTest/ADKTerminalTest.ino index 2789ec842..2d4f14e2b 100644 --- a/libraries/USBHost/examples/ADKTerminalTest/ADKTerminalTest.ino +++ b/libraries/USBHost/examples/ADKTerminalTest/ADKTerminalTest.ino @@ -2,11 +2,11 @@ ADK Terminal Test - This demonstrates USB Host connectivity between an + This demonstrates USB Host connectivity between an Android phone and an Arduino Due. The ADK for the Arduino Due is a work in progress - For additional information on the Arduino ADK visit + For additional information on the Arduino ADK visit http://labs.arduino.cc/ADK/Index created 27 June 2012 @@ -29,42 +29,42 @@ char serialNumber[] = "1"; char url[] = "http://labs.arduino.cc/uploads/ADK/ArduinoTerminal/ThibaultTerminal_ICS_0001.apk"; USBHost Usb; -ADK adk(&Usb, companyName, applicationName, accessoryName,versionNumber,url,serialNumber); +ADK adk(&Usb, companyName, applicationName, accessoryName, versionNumber, url, serialNumber); void setup() { - cpu_irq_enable(); - printf("\r\nADK demo start\r\n"); - delay(200); + cpu_irq_enable(); + printf("\r\nADK demo start\r\n"); + delay(200); } #define RCVSIZE 128 void loop() { - uint8_t buf[RCVSIZE]; - uint32_t nbread = 0; - char helloworld[] = "Hello World!\r\n"; + uint8_t buf[RCVSIZE]; + uint32_t nbread = 0; + char helloworld[] = "Hello World!\r\n"; - Usb.Task(); + Usb.Task(); - if (adk.isReady()) - { - /* Write hello string to ADK */ - adk.write(strlen(helloworld), (uint8_t *)helloworld); + if (adk.isReady()) + { + /* Write hello string to ADK */ + adk.write(strlen(helloworld), (uint8_t *)helloworld); - delay(1000); + delay(1000); - /* Read data from ADK and print to UART */ - adk.read(&nbread, RCVSIZE, buf); - if (nbread > 0) - { - printf("RCV: "); - for (uint32_t i = 0; i < nbread; ++i) - { - printf("%c", (char)buf[i]); - } - printf("\r\n"); - } - } + /* Read data from ADK and print to UART */ + adk.read(&nbread, RCVSIZE, buf); + if (nbread > 0) + { + printf("RCV: "); + for (uint32_t i = 0; i < nbread; ++i) + { + printf("%c", (char)buf[i]); + } + printf("\r\n"); + } + } } diff --git a/libraries/USBHost/examples/KeyboardController/KeyboardController.ino b/libraries/USBHost/examples/KeyboardController/KeyboardController.ino index e86696a15..aa744543d 100644 --- a/libraries/USBHost/examples/KeyboardController/KeyboardController.ino +++ b/libraries/USBHost/examples/KeyboardController/KeyboardController.ino @@ -1,14 +1,14 @@ /* Keyboard Controller Example - - Shows the output of a USB Keyboard connected to + + Shows the output of a USB Keyboard connected to the Native USB port on an Arduino Due Board. - + created 8 Oct 2012 by Cristian Maglie - + http://arduino.cc/en/Tutorial/KeyboardController - + This sample code is part of the public domain. */ diff --git a/libraries/USBHost/examples/MouseController/MouseController.ino b/libraries/USBHost/examples/MouseController/MouseController.ino index 63c2a681a..81d0d8827 100644 --- a/libraries/USBHost/examples/MouseController/MouseController.ino +++ b/libraries/USBHost/examples/MouseController/MouseController.ino @@ -1,14 +1,14 @@ /* Mouse Controller Example - - Shows the output of a USB Mouse connected to + + Shows the output of a USB Mouse connected to the Native USB port on an Arduino Due Board. - + created 8 Oct 2012 by Cristian Maglie - + http://arduino.cc/en/Tutorial/MouseController - + This sample code is part of the public domain. */ @@ -45,15 +45,15 @@ void mouseDragged() { // This function intercepts mouse button press void mousePressed() { Serial.print("Pressed: "); - if (mouse.getButton(LEFT_BUTTON)){ + if (mouse.getButton(LEFT_BUTTON)) { Serial.print("L"); leftButton = true; } - if (mouse.getButton(MIDDLE_BUTTON)){ + if (mouse.getButton(MIDDLE_BUTTON)) { Serial.print("M"); middleButton = true; } - if (mouse.getButton(RIGHT_BUTTON)){ + if (mouse.getButton(RIGHT_BUTTON)) { Serial.print("R"); Serial.println(); rightButton = true; diff --git a/libraries/WiFi/examples/ConnectNoEncryption/ConnectNoEncryption.ino b/libraries/WiFi/examples/ConnectNoEncryption/ConnectNoEncryption.ino index b4bf3d69d..9c3224247 100644 --- a/libraries/WiFi/examples/ConnectNoEncryption/ConnectNoEncryption.ino +++ b/libraries/WiFi/examples/ConnectNoEncryption/ConnectNoEncryption.ino @@ -1,42 +1,42 @@ /* - - This example connects to an unencrypted Wifi network. + + This example connects to an unencrypted Wifi network. Then it prints the MAC address of the Wifi shield, the IP address obtained, and other network details. Circuit: * WiFi shield attached - + created 13 July 2010 by dlf (Metodo2 srl) modified 31 May 2012 by Tom Igoe */ - #include +#include char ssid[] = "yourNetwork"; // the name of your network int status = WL_IDLE_STATUS; // the Wifi radio's status void setup() { //Initialize serial and wait for port to open: - Serial.begin(9600); + Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } - + // check for the presence of the shield: if (WiFi.status() == WL_NO_SHIELD) { - Serial.println("WiFi shield not present"); + Serial.println("WiFi shield not present"); // don't continue: - while(true); - } + while (true); + } String fv = WiFi.firmwareVersion(); - if( fv != "1.1.0" ) + if ( fv != "1.1.0" ) Serial.println("Please upgrade the firmware"); - - // attempt to connect to Wifi network: - while ( status != WL_CONNECTED) { + + // attempt to connect to Wifi network: + while ( status != WL_CONNECTED) { Serial.print("Attempting to connect to open SSID: "); Serial.println(ssid); status = WiFi.begin(ssid); @@ -44,7 +44,7 @@ void setup() { // wait 10 seconds for connection: delay(10000); } - + // you're connected now, so print out the data: Serial.print("You're connected to the network"); printCurrentNet(); @@ -60,26 +60,26 @@ void loop() { void printWifiData() { // print your WiFi shield's IP address: IPAddress ip = WiFi.localIP(); - Serial.print("IP Address: "); + Serial.print("IP Address: "); Serial.println(ip); Serial.println(ip); - + // print your MAC address: - byte mac[6]; + byte mac[6]; WiFi.macAddress(mac); Serial.print("MAC address: "); - Serial.print(mac[5],HEX); + Serial.print(mac[5], HEX); Serial.print(":"); - Serial.print(mac[4],HEX); + Serial.print(mac[4], HEX); Serial.print(":"); - Serial.print(mac[3],HEX); + Serial.print(mac[3], HEX); Serial.print(":"); - Serial.print(mac[2],HEX); + Serial.print(mac[2], HEX); Serial.print(":"); - Serial.print(mac[1],HEX); + Serial.print(mac[1], HEX); Serial.print(":"); - Serial.println(mac[0],HEX); - + Serial.println(mac[0], HEX); + // print your subnet mask: IPAddress subnet = WiFi.subnetMask(); Serial.print("NetMask: "); @@ -98,19 +98,19 @@ void printCurrentNet() { // print the MAC address of the router you're attached to: byte bssid[6]; - WiFi.BSSID(bssid); + WiFi.BSSID(bssid); Serial.print("BSSID: "); - Serial.print(bssid[5],HEX); + Serial.print(bssid[5], HEX); Serial.print(":"); - Serial.print(bssid[4],HEX); + Serial.print(bssid[4], HEX); Serial.print(":"); - Serial.print(bssid[3],HEX); + Serial.print(bssid[3], HEX); Serial.print(":"); - Serial.print(bssid[2],HEX); + Serial.print(bssid[2], HEX); Serial.print(":"); - Serial.print(bssid[1],HEX); + Serial.print(bssid[1], HEX); Serial.print(":"); - Serial.println(bssid[0],HEX); + Serial.println(bssid[0], HEX); // print the received signal strength: long rssi = WiFi.RSSI(); @@ -120,6 +120,6 @@ void printCurrentNet() { // print the encryption type: byte encryption = WiFi.encryptionType(); Serial.print("Encryption Type:"); - Serial.println(encryption,HEX); + Serial.println(encryption, HEX); } diff --git a/libraries/WiFi/examples/ConnectWithWEP/ConnectWithWEP.ino b/libraries/WiFi/examples/ConnectWithWEP/ConnectWithWEP.ino index 8b14a1a2b..70bc50eaa 100644 --- a/libraries/WiFi/examples/ConnectWithWEP/ConnectWithWEP.ino +++ b/libraries/WiFi/examples/ConnectWithWEP/ConnectWithWEP.ino @@ -1,22 +1,22 @@ /* - - This example connects to a WEP-encrypted Wifi network. + + This example connects to a WEP-encrypted Wifi network. Then it prints the MAC address of the Wifi shield, the IP address obtained, and other network details. - - If you use 40-bit WEP, you need a key that is 10 characters long, - and the characters must be hexadecimal (0-9 or A-F). - e.g. for 40-bit, ABBADEAF01 will work, but ABBADEAF won't work - (too short) and ABBAISDEAF won't work (I and S are not - hexadecimal characters). - - For 128-bit, you need a string that is 26 characters long. - D0D0DEADF00DABBADEAFBEADED will work because it's 26 characters, + + If you use 40-bit WEP, you need a key that is 10 characters long, + and the characters must be hexadecimal (0-9 or A-F). + e.g. for 40-bit, ABBADEAF01 will work, but ABBADEAF won't work + (too short) and ABBAISDEAF won't work (I and S are not + hexadecimal characters). + + For 128-bit, you need a string that is 26 characters long. + D0D0DEADF00DABBADEAFBEADED will work because it's 26 characters, all in the 0-9, A-F range. - + Circuit: * WiFi shield attached - + created 13 July 2010 by dlf (Metodo2 srl) modified 31 May 2012 @@ -24,31 +24,31 @@ */ #include -char ssid[] = "yourNetwork"; // your network SSID (name) +char ssid[] = "yourNetwork"; // your network SSID (name) char key[] = "D0D0DEADF00DABBADEAFBEADED"; // your network key int keyIndex = 0; // your network key Index number int status = WL_IDLE_STATUS; // the Wifi radio's status void setup() { //Initialize serial and wait for port to open: - Serial.begin(9600); + Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } // check for the presence of the shield: if (WiFi.status() == WL_NO_SHIELD) { - Serial.println("WiFi shield not present"); + Serial.println("WiFi shield not present"); // don't continue: - while(true); - } + while (true); + } String fv = WiFi.firmwareVersion(); - if( fv != "1.1.0" ) + if ( fv != "1.1.0" ) Serial.println("Please upgrade the firmware"); // attempt to connect to Wifi network: - while ( status != WL_CONNECTED) { + while ( status != WL_CONNECTED) { Serial.print("Attempting to connect to WEP network, SSID: "); Serial.println(ssid); status = WiFi.begin(ssid, keyIndex, key); @@ -56,7 +56,7 @@ void setup() { // wait 10 seconds for connection: delay(10000); } - + // once you are connected : Serial.print("You're connected to the network"); printCurrentNet(); @@ -77,20 +77,20 @@ void printWifiData() { Serial.println(ip); // print your MAC address: - byte mac[6]; + byte mac[6]; WiFi.macAddress(mac); Serial.print("MAC address: "); - Serial.print(mac[5],HEX); + Serial.print(mac[5], HEX); Serial.print(":"); - Serial.print(mac[4],HEX); + Serial.print(mac[4], HEX); Serial.print(":"); - Serial.print(mac[3],HEX); + Serial.print(mac[3], HEX); Serial.print(":"); - Serial.print(mac[2],HEX); + Serial.print(mac[2], HEX); Serial.print(":"); - Serial.print(mac[1],HEX); + Serial.print(mac[1], HEX); Serial.print(":"); - Serial.println(mac[0],HEX); + Serial.println(mac[0], HEX); } void printCurrentNet() { @@ -100,19 +100,19 @@ void printCurrentNet() { // print the MAC address of the router you're attached to: byte bssid[6]; - WiFi.BSSID(bssid); + WiFi.BSSID(bssid); Serial.print("BSSID: "); - Serial.print(bssid[5],HEX); + Serial.print(bssid[5], HEX); Serial.print(":"); - Serial.print(bssid[4],HEX); + Serial.print(bssid[4], HEX); Serial.print(":"); - Serial.print(bssid[3],HEX); + Serial.print(bssid[3], HEX); Serial.print(":"); - Serial.print(bssid[2],HEX); + Serial.print(bssid[2], HEX); Serial.print(":"); - Serial.print(bssid[1],HEX); + Serial.print(bssid[1], HEX); Serial.print(":"); - Serial.println(bssid[0],HEX); + Serial.println(bssid[0], HEX); // print the received signal strength: long rssi = WiFi.RSSI(); @@ -122,7 +122,7 @@ void printCurrentNet() { // print the encryption type: byte encryption = WiFi.encryptionType(); Serial.print("Encryption Type:"); - Serial.println(encryption,HEX); + Serial.println(encryption, HEX); Serial.println(); } diff --git a/libraries/WiFi/examples/ConnectWithWPA/ConnectWithWPA.ino b/libraries/WiFi/examples/ConnectWithWPA/ConnectWithWPA.ino index 4950736fd..06b0e80e5 100644 --- a/libraries/WiFi/examples/ConnectWithWPA/ConnectWithWPA.ino +++ b/libraries/WiFi/examples/ConnectWithWPA/ConnectWithWPA.ino @@ -1,52 +1,52 @@ /* - - This example connects to an unencrypted Wifi network. + + This example connects to an unencrypted Wifi network. Then it prints the MAC address of the Wifi shield, the IP address obtained, and other network details. Circuit: * WiFi shield attached - + created 13 July 2010 by dlf (Metodo2 srl) modified 31 May 2012 by Tom Igoe */ - #include +#include -char ssid[] = "yourNetwork"; // your network SSID (name) +char ssid[] = "yourNetwork"; // your network SSID (name) char pass[] = "secretPassword"; // your network password int status = WL_IDLE_STATUS; // the Wifi radio's status void setup() { //Initialize serial and wait for port to open: - Serial.begin(9600); + Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } - + // check for the presence of the shield: if (WiFi.status() == WL_NO_SHIELD) { - Serial.println("WiFi shield not present"); + Serial.println("WiFi shield not present"); // don't continue: - while(true); - } + while (true); + } String fv = WiFi.firmwareVersion(); - if( fv != "1.1.0" ) + if ( fv != "1.1.0" ) Serial.println("Please upgrade the firmware"); - - // attempt to connect to Wifi network: - while ( status != WL_CONNECTED) { + + // attempt to connect to Wifi network: + while ( status != WL_CONNECTED) { Serial.print("Attempting to connect to WPA SSID: "); Serial.println(ssid); - // Connect to WPA/WPA2 network: + // Connect to WPA/WPA2 network: status = WiFi.begin(ssid, pass); // wait 10 seconds for connection: delay(10000); } - + // you're connected now, so print out the data: Serial.print("You're connected to the network"); printCurrentNet(); @@ -63,26 +63,26 @@ void loop() { void printWifiData() { // print your WiFi shield's IP address: IPAddress ip = WiFi.localIP(); - Serial.print("IP Address: "); + Serial.print("IP Address: "); Serial.println(ip); Serial.println(ip); - + // print your MAC address: - byte mac[6]; + byte mac[6]; WiFi.macAddress(mac); Serial.print("MAC address: "); - Serial.print(mac[5],HEX); + Serial.print(mac[5], HEX); Serial.print(":"); - Serial.print(mac[4],HEX); + Serial.print(mac[4], HEX); Serial.print(":"); - Serial.print(mac[3],HEX); + Serial.print(mac[3], HEX); Serial.print(":"); - Serial.print(mac[2],HEX); + Serial.print(mac[2], HEX); Serial.print(":"); - Serial.print(mac[1],HEX); + Serial.print(mac[1], HEX); Serial.print(":"); - Serial.println(mac[0],HEX); - + Serial.println(mac[0], HEX); + } void printCurrentNet() { @@ -92,19 +92,19 @@ void printCurrentNet() { // print the MAC address of the router you're attached to: byte bssid[6]; - WiFi.BSSID(bssid); + WiFi.BSSID(bssid); Serial.print("BSSID: "); - Serial.print(bssid[5],HEX); + Serial.print(bssid[5], HEX); Serial.print(":"); - Serial.print(bssid[4],HEX); + Serial.print(bssid[4], HEX); Serial.print(":"); - Serial.print(bssid[3],HEX); + Serial.print(bssid[3], HEX); Serial.print(":"); - Serial.print(bssid[2],HEX); + Serial.print(bssid[2], HEX); Serial.print(":"); - Serial.print(bssid[1],HEX); + Serial.print(bssid[1], HEX); Serial.print(":"); - Serial.println(bssid[0],HEX); + Serial.println(bssid[0], HEX); // print the received signal strength: long rssi = WiFi.RSSI(); @@ -114,7 +114,7 @@ void printCurrentNet() { // print the encryption type: byte encryption = WiFi.encryptionType(); Serial.print("Encryption Type:"); - Serial.println(encryption,HEX); + Serial.println(encryption, HEX); Serial.println(); } diff --git a/libraries/WiFi/examples/ScanNetworks/ScanNetworks.ino b/libraries/WiFi/examples/ScanNetworks/ScanNetworks.ino index c47cae566..8658ef0cb 100644 --- a/libraries/WiFi/examples/ScanNetworks/ScanNetworks.ino +++ b/libraries/WiFi/examples/ScanNetworks/ScanNetworks.ino @@ -1,13 +1,13 @@ /* - + This example prints the Wifi shield's MAC address, and scans for available Wifi networks using the Wifi shield. - Every ten seconds, it scans again. It doesn't actually + Every ten seconds, it scans again. It doesn't actually connect to any network, so no encryption scheme is specified. - + Circuit: * WiFi shield attached - + created 13 July 2010 by dlf (Metodo2 srl) modified 21 Junn 2012 @@ -20,20 +20,20 @@ void setup() { //Initialize serial and wait for port to open: - Serial.begin(9600); + Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } // check for the presence of the shield: if (WiFi.status() == WL_NO_SHIELD) { - Serial.println("WiFi shield not present"); + Serial.println("WiFi shield not present"); // don't continue: - while(true); - } + while (true); + } String fv = WiFi.firmwareVersion(); - if( fv != "1.1.0" ) + if ( fv != "1.1.0" ) Serial.println("Please upgrade the firmware"); // Print WiFi MAC address: @@ -53,22 +53,22 @@ void loop() { void printMacAddress() { // the MAC address of your Wifi shield - byte mac[6]; + byte mac[6]; // print your MAC address: WiFi.macAddress(mac); Serial.print("MAC: "); - Serial.print(mac[5],HEX); + Serial.print(mac[5], HEX); Serial.print(":"); - Serial.print(mac[4],HEX); + Serial.print(mac[4], HEX); Serial.print(":"); - Serial.print(mac[3],HEX); + Serial.print(mac[3], HEX); Serial.print(":"); - Serial.print(mac[2],HEX); + Serial.print(mac[2], HEX); Serial.print(":"); - Serial.print(mac[1],HEX); + Serial.print(mac[1], HEX); Serial.print(":"); - Serial.println(mac[0],HEX); + Serial.println(mac[0], HEX); } void listNetworks() { @@ -76,17 +76,17 @@ void listNetworks() { Serial.println("** Scan Networks **"); int numSsid = WiFi.scanNetworks(); if (numSsid == -1) - { + { Serial.println("Couldn't get a wifi connection"); - while(true); - } + while (true); + } // print the list of networks seen: Serial.print("number of available networks:"); Serial.println(numSsid); // print the network number and name for each network found: - for (int thisNet = 0; thisNet #include -char ssid[] = "yourNetwork"; // your network SSID (name) +char ssid[] = "yourNetwork"; // your network SSID (name) char pass[] = "secretPassword"; // your network password int keyIndex = 0; // your network key Index number (needed only for WEP) @@ -36,24 +36,24 @@ void setup() { // check for the presence of the shield: if (WiFi.status() == WL_NO_SHIELD) { - Serial.println("WiFi shield not present"); - while(true); // don't continue - } + Serial.println("WiFi shield not present"); + while (true); // don't continue + } String fv = WiFi.firmwareVersion(); - if( fv != "1.1.0" ) + if ( fv != "1.1.0" ) Serial.println("Please upgrade the firmware"); // attempt to connect to Wifi network: - while ( status != WL_CONNECTED) { + while ( status != WL_CONNECTED) { Serial.print("Attempting to connect to Network named: "); Serial.println(ssid); // print the network name (SSID); - // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: status = WiFi.begin(ssid, pass); // wait 10 seconds for connection: delay(10000); - } + } server.begin(); // start the web server on port 80 printWifiStatus(); // you're connected now, so print out the status } @@ -73,9 +73,9 @@ void loop() { // if the current line is blank, you got two newline characters in a row. // that's the end of the client HTTP request, so send a response: - if (currentLine.length() == 0) { + if (currentLine.length() == 0) { // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) - // and a content-type so the client knows what's coming, then a blank line: + // and a content-type so the client knows what's coming, then a blank line: client.println("HTTP/1.1 200 OK"); client.println("Content-type:text/html"); client.println(); @@ -87,12 +87,12 @@ void loop() { // The HTTP response ends with another blank line: client.println(); // break out of the while loop: - break; - } + break; + } else { // if you got a newline, then clear currentLine: currentLine = ""; } - } + } else if (c != '\r') { // if you got anything else but a carriage return character, currentLine += c; // add it to the end of the currentLine } diff --git a/libraries/WiFi/examples/WiFiChatServer/WiFiChatServer.ino b/libraries/WiFi/examples/WiFiChatServer/WiFiChatServer.ino index 8043ec560..b50a38ae0 100644 --- a/libraries/WiFi/examples/WiFiChatServer/WiFiChatServer.ino +++ b/libraries/WiFi/examples/WiFiChatServer/WiFiChatServer.ino @@ -1,28 +1,28 @@ /* Chat Server - + A simple server that distributes any incoming messages to all connected clients. To use telnet to your device's IP address and type. You can see the client's input in the serial monitor as well. - - This example is written for a network using WPA encryption. For + + This example is written for a network using WPA encryption. For WEP or WPA, change the Wifi.begin() call accordingly. - - + + Circuit: * WiFi shield attached - + created 18 Dec 2009 by David A. Mellis modified 31 May 2012 by Tom Igoe - + */ #include #include -char ssid[] = "yourNetwork"; // your network SSID (name) +char ssid[] = "yourNetwork"; // your network SSID (name) char pass[] = "secretPassword"; // your network password (use for WPA, or use as key for WEP) int keyIndex = 0; // your network key Index number (needed only for WEP) @@ -35,38 +35,38 @@ boolean alreadyConnected = false; // whether or not the client was connected pre void setup() { //Initialize serial and wait for port to open: - Serial.begin(9600); + Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } - + // check for the presence of the shield: if (WiFi.status() == WL_NO_SHIELD) { - Serial.println("WiFi shield not present"); + Serial.println("WiFi shield not present"); // don't continue: - while(true); - } + while (true); + } String fv = WiFi.firmwareVersion(); - if( fv != "1.1.0" ) + if ( fv != "1.1.0" ) Serial.println("Please upgrade the firmware"); - + // attempt to connect to Wifi network: - while ( status != WL_CONNECTED) { + while ( status != WL_CONNECTED) { Serial.print("Attempting to connect to SSID: "); Serial.println(ssid); - // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: status = WiFi.begin(ssid, pass); // wait 10 seconds for connection: delay(10000); - } + } // start the server: server.begin(); // you're connected now, so print out the status: printWifiStatus(); - } +} void loop() { @@ -78,11 +78,11 @@ void loop() { if (client) { if (!alreadyConnected) { // clead out the input buffer: - client.flush(); + client.flush(); Serial.println("We have a new client"); - client.println("Hello, client!"); + client.println("Hello, client!"); alreadyConnected = true; - } + } if (client.available() > 0) { // read the bytes incoming from the client: diff --git a/libraries/WiFi/examples/WiFiPachubeClient/WiFiPachubeClient.ino b/libraries/WiFi/examples/WiFiPachubeClient/WiFiPachubeClient.ino index 045f8e950..449cf3ed7 100644 --- a/libraries/WiFi/examples/WiFiPachubeClient/WiFiPachubeClient.ino +++ b/libraries/WiFi/examples/WiFiPachubeClient/WiFiPachubeClient.ino @@ -1,28 +1,28 @@ /* Wifi Pachube sensor client - + This sketch connects an analog sensor to Pachube (http://www.pachube.com) using an Arduino Wifi shield. - - This example is written for a network using WPA encryption. For + + This example is written for a network using WPA encryption. For WEP or WPA, change the Wifi.begin() call accordingly. - - This example has been updated to use version 2.0 of the Pachube API. + + This example has been updated to use version 2.0 of the Pachube API. To make it work, create a feed with a datastream, and give it the ID sensor1. Or change the code below to match your feed. - + Circuit: * Analog sensor attached to analog in 0 * Wifi shield attached to pins 10, 11, 12, 13 - + created 13 Mar 2012 modified 31 May 2012 by Tom Igoe modified 8 Sept 2012 by Scott Fitzgerald - + This code is in the public domain. - + */ #include #include @@ -31,7 +31,7 @@ #define FEEDID 00000 // replace your feed ID #define USERAGENT "My Arduino Project" // user agent is the project name -char ssid[] = "yourNetwork"; // your network SSID (name) +char ssid[] = "yourNetwork"; // your network SSID (name) char pass[] = "secretPassword"; // your network password int status = WL_IDLE_STATUS; @@ -40,41 +40,41 @@ int status = WL_IDLE_STATUS; WiFiClient client; // if you don't want to use DNS (and reduce your sketch size) // use the numeric IP instead of the name for the server: -IPAddress server(216,52,233,121); // numeric IP for api.pachube.com +IPAddress server(216, 52, 233, 121); // numeric IP for api.pachube.com //char server[] = "api.pachube.com"; // name address for pachube API unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds boolean lastConnected = false; // state of the connection last time through the main loop -const unsigned long postingInterval = 10*1000; //delay between updates to pachube.com +const unsigned long postingInterval = 10 * 1000; //delay between updates to pachube.com void setup() { //Initialize serial and wait for port to open: - Serial.begin(9600); + Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } - + // check for the presence of the shield: if (WiFi.status() == WL_NO_SHIELD) { - Serial.println("WiFi shield not present"); + Serial.println("WiFi shield not present"); // don't continue: - while(true); - } + while (true); + } String fv = WiFi.firmwareVersion(); - if( fv != "1.1.0" ) + if ( fv != "1.1.0" ) Serial.println("Please upgrade the firmware"); - + // attempt to connect to Wifi network: - while ( status != WL_CONNECTED) { + while ( status != WL_CONNECTED) { Serial.print("Attempting to connect to SSID: "); Serial.println(ssid); - // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: status = WiFi.begin(ssid, pass); // wait 10 seconds for connection: delay(10000); - } + } // you're connected now, so print out the status: printWifiStatus(); } @@ -82,7 +82,7 @@ void setup() { void loop() { // read the analog sensor: - int sensorReading = analogRead(A0); + int sensorReading = analogRead(A0); // if there's incoming data from the net connection. // send it out the serial port. This is for debugging @@ -102,7 +102,7 @@ void loop() { // if you're not connected, and ten seconds have passed since // your last connection, then connect again and send data: - if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) { + if (!client.connected() && (millis() - lastConnectionTime > postingInterval)) { sendData(sensorReading); } // store the state of the connection for next time through @@ -139,8 +139,8 @@ void sendData(int thisData) { // here's the actual content of the PUT request: client.print("sensor1,"); client.println(thisData); - - } + + } else { // if you couldn't make a connection: Serial.println("connection failed"); @@ -148,7 +148,7 @@ void sendData(int thisData) { Serial.println("disconnecting."); client.stop(); } - // note the time that the connection was made or attempted: + // note the time that the connection was made or attempted: lastConnectionTime = millis(); } @@ -161,12 +161,12 @@ void sendData(int thisData) { int getLength(int someValue) { // there's at least one byte: int digits = 1; - // continually divide the value by ten, + // continually divide the value by ten, // adding one to the digit count for each // time you divide, until you're at 0: - int dividend = someValue /10; + int dividend = someValue / 10; while (dividend > 0) { - dividend = dividend /10; + dividend = dividend / 10; digits++; } // return the number of digits: diff --git a/libraries/WiFi/examples/WiFiPachubeClientString/WiFiPachubeClientString.ino b/libraries/WiFi/examples/WiFiPachubeClientString/WiFiPachubeClientString.ino index 9a6d3095d..ac8007f0e 100644 --- a/libraries/WiFi/examples/WiFiPachubeClientString/WiFiPachubeClientString.ino +++ b/libraries/WiFi/examples/WiFiPachubeClientString/WiFiPachubeClientString.ino @@ -1,31 +1,31 @@ /* Wifi Pachube sensor client with Strings - + This sketch connects an analog sensor to Pachube (http://www.pachube.com) using a Arduino Wifi shield. - - This example is written for a network using WPA encryption. For + + This example is written for a network using WPA encryption. For WEP or WPA, change the Wifi.begin() call accordingly. - - This example has been updated to use version 2.0 of the pachube.com API. + + This example has been updated to use version 2.0 of the pachube.com API. To make it work, create a feed with a datastream, and give it the ID sensor1. Or change the code below to match your feed. - + This example uses the String library, which is part of the Arduino core from - version 0019. - + version 0019. + Circuit: * Analog sensor attached to analog in 0 * Wifi shield attached to pins 10, 11, 12, 13 - + created 16 Mar 2012 modified 31 May 2012 by Tom Igoe modified 8 Sept 2012 by Scott Fitzgerald - + This code is in the public domain. - + */ #include @@ -35,7 +35,7 @@ #define FEEDID 00000 // replace your feed ID #define USERAGENT "My Arduino Project" // user agent is the project name -char ssid[] = "yourNetwork"; // your network SSID (name) +char ssid[] = "yourNetwork"; // your network SSID (name) char pass[] = "secretPassword"; // your network password int status = WL_IDLE_STATUS; @@ -50,43 +50,43 @@ char server[] = "api.pachube.com"; // name address for pachube API unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds boolean lastConnected = false; // state of the connection last time through the main loop -const unsigned long postingInterval = 10*1000; //delay between updates to pachube.com +const unsigned long postingInterval = 10 * 1000; //delay between updates to pachube.com void setup() { //Initialize serial and wait for port to open: - Serial.begin(9600); + Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } - + // check for the presence of the shield: if (WiFi.status() == WL_NO_SHIELD) { - Serial.println("WiFi shield not present"); + Serial.println("WiFi shield not present"); // don't continue: - while(true); - } + while (true); + } String fv = WiFi.firmwareVersion(); - if( fv != "1.1.0" ) + if ( fv != "1.1.0" ) Serial.println("Please upgrade the firmware"); - + // attempt to connect to Wifi network: - while ( status != WL_CONNECTED) { + while ( status != WL_CONNECTED) { Serial.print("Attempting to connect to SSID: "); Serial.println(ssid); - // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: status = WiFi.begin(ssid, pass); // wait 10 seconds for connection: delay(10000); - } + } // you're connected now, so print out the status: printWifiStatus(); } void loop() { // read the analog sensor: - int sensorReading = analogRead(A0); + int sensorReading = analogRead(A0); // convert the data to a String to send it: String dataString = "sensor1,"; @@ -115,8 +115,8 @@ void loop() { } // if you're not connected, and ten seconds have passed since - // your last connection, then connect again and send data: - if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) { + // your last connection, then connect again and send data: + if (!client.connected() && (millis() - lastConnectionTime > postingInterval)) { sendData(dataString); } // store the state of the connection for next time through @@ -148,7 +148,7 @@ void sendData(String thisData) { // here's the actual content of the PUT request: client.println(thisData); - } + } else { // if you couldn't make a connection: Serial.println("connection failed"); diff --git a/libraries/WiFi/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino b/libraries/WiFi/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino index e958f8371..059b2679d 100644 --- a/libraries/WiFi/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino +++ b/libraries/WiFi/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino @@ -1,22 +1,22 @@ /* Udp NTP Client - + Get the time from a Network Time Protocol (NTP) time server - Demonstrates use of UDP sendPacket and ReceivePacket - For more on NTP time servers and the messages needed to communicate with them, + Demonstrates use of UDP sendPacket and ReceivePacket + For more on NTP time servers and the messages needed to communicate with them, see http://en.wikipedia.org/wiki/Network_Time_Protocol - - created 4 Sep 2010 + + created 4 Sep 2010 by Michael Margolis modified 9 Apr 2012 by Tom Igoe - + This code is in the public domain. - + */ -#include +#include #include #include @@ -31,12 +31,12 @@ IPAddress timeServer(129, 6, 15, 28); // time.nist.gov NTP server const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message -byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets +byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets // A UDP instance to let us send and receive packets over UDP WiFiUDP Udp; -void setup() +void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); @@ -46,20 +46,20 @@ void setup() // check for the presence of the shield: if (WiFi.status() == WL_NO_SHIELD) { - Serial.println("WiFi shield not present"); + Serial.println("WiFi shield not present"); // don't continue: - while(true); - } + while (true); + } String fv = WiFi.firmwareVersion(); - if( fv != "1.1.0" ) + if ( fv != "1.1.0" ) Serial.println("Please upgrade the firmware"); // attempt to connect to Wifi network: - while ( status != WL_CONNECTED) { + while ( status != WL_CONNECTED) { Serial.print("Attempting to connect to SSID: "); Serial.println(ssid); - // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: status = WiFi.begin(ssid, pass); // wait 10 seconds for connection: @@ -76,61 +76,61 @@ void setup() void loop() { sendNTPpacket(timeServer); // send an NTP packet to a time server - // wait to see if a reply is available - delay(1000); + // wait to see if a reply is available + delay(1000); Serial.println( Udp.parsePacket() ); - if ( Udp.parsePacket() ) { - Serial.println("packet received"); + if ( Udp.parsePacket() ) { + Serial.println("packet received"); // We've received a packet, read the data from it - Udp.read(packetBuffer,NTP_PACKET_SIZE); // read the packet into the buffer + Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer //the timestamp starts at byte 40 of the received packet and is four bytes, // or two words, long. First, esxtract the two words: unsigned long highWord = word(packetBuffer[40], packetBuffer[41]); - unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); + unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); // combine the four bytes (two words) into a long integer // this is NTP time (seconds since Jan 1 1900): - unsigned long secsSince1900 = highWord << 16 | lowWord; + unsigned long secsSince1900 = highWord << 16 | lowWord; Serial.print("Seconds since Jan 1 1900 = " ); - Serial.println(secsSince1900); + Serial.println(secsSince1900); // now convert NTP time into everyday time: Serial.print("Unix time = "); // Unix time starts on Jan 1 1970. In seconds, that's 2208988800: - const unsigned long seventyYears = 2208988800UL; + const unsigned long seventyYears = 2208988800UL; // subtract seventy years: - unsigned long epoch = secsSince1900 - seventyYears; + unsigned long epoch = secsSince1900 - seventyYears; // print Unix time: - Serial.println(epoch); + Serial.println(epoch); // print the hour, minute and second: Serial.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT) Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day) - Serial.print(':'); + Serial.print(':'); if ( ((epoch % 3600) / 60) < 10 ) { // In the first 10 minutes of each hour, we'll want a leading '0' Serial.print('0'); } Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute) - Serial.print(':'); + Serial.print(':'); if ( (epoch % 60) < 10 ) { // In the first 10 seconds of each minute, we'll want a leading '0' Serial.print('0'); } - Serial.println(epoch %60); // print the second + Serial.println(epoch % 60); // print the second } // wait ten seconds before asking for the time again - delay(10000); + delay(10000); } -// send an NTP request to the time server at the given address +// send an NTP request to the time server at the given address unsigned long sendNTPpacket(IPAddress& address) { //Serial.println("1"); // set all bytes in the buffer to 0 - memset(packetBuffer, 0, NTP_PACKET_SIZE); + memset(packetBuffer, 0, NTP_PACKET_SIZE); // Initialize values needed to form NTP request // (see URL above for details on the packets) //Serial.println("2"); @@ -139,20 +139,20 @@ unsigned long sendNTPpacket(IPAddress& address) packetBuffer[2] = 6; // Polling Interval packetBuffer[3] = 0xEC; // Peer Clock Precision // 8 bytes of zero for Root Delay & Root Dispersion - packetBuffer[12] = 49; + packetBuffer[12] = 49; packetBuffer[13] = 0x4E; packetBuffer[14] = 49; packetBuffer[15] = 52; - + //Serial.println("3"); // all NTP fields have been given values, now - // you can send a packet requesting a timestamp: + // you can send a packet requesting a timestamp: Udp.beginPacket(address, 123); //NTP requests are to port 123 //Serial.println("4"); - Udp.write(packetBuffer,NTP_PACKET_SIZE); + Udp.write(packetBuffer, NTP_PACKET_SIZE); //Serial.println("5"); - Udp.endPacket(); + Udp.endPacket(); //Serial.println("6"); } diff --git a/libraries/WiFi/examples/WiFiUdpSendReceiveString/WiFiUdpSendReceiveString.ino b/libraries/WiFi/examples/WiFiUdpSendReceiveString/WiFiUdpSendReceiveString.ino index b87dcf71a..90deef81e 100644 --- a/libraries/WiFi/examples/WiFiUdpSendReceiveString/WiFiUdpSendReceiveString.ino +++ b/libraries/WiFi/examples/WiFiUdpSendReceiveString/WiFiUdpSendReceiveString.ino @@ -1,13 +1,13 @@ /* WiFi UDP Send and Receive String - + This sketch wait an UDP packet on localPort using a WiFi shield. When a packet is received an Acknowledge packet is sent to the client on port remotePort - + Circuit: * WiFi shield attached - + created 30 December 2012 by dlf (Metodo2 srl) @@ -19,7 +19,7 @@ #include int status = WL_IDLE_STATUS; -char ssid[] = "yourNetwork"; // your network SSID (name) +char ssid[] = "yourNetwork"; // your network SSID (name) char pass[] = "secretPassword"; // your network password (use for WPA, or use as key for WEP) int keyIndex = 0; // your network key Index number (needed only for WEP) @@ -32,46 +32,46 @@ WiFiUDP Udp; void setup() { //Initialize serial and wait for port to open: - Serial.begin(9600); + Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } - + // check for the presence of the shield: if (WiFi.status() == WL_NO_SHIELD) { - Serial.println("WiFi shield not present"); + Serial.println("WiFi shield not present"); // don't continue: - while(true); - } + while (true); + } String fv = WiFi.firmwareVersion(); - if( fv != "1.1.0" ) + if ( fv != "1.1.0" ) Serial.println("Please upgrade the firmware"); - + // attempt to connect to Wifi network: - while ( status != WL_CONNECTED) { + while ( status != WL_CONNECTED) { Serial.print("Attempting to connect to SSID: "); Serial.println(ssid); - // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: status = WiFi.begin(ssid); - + // wait 10 seconds for connection: delay(10000); - } + } Serial.println("Connected to wifi"); printWifiStatus(); - + Serial.println("\nStarting connection to server..."); // if you get a connection, report back via serial: - Udp.begin(localPort); + Udp.begin(localPort); } 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 "); @@ -81,16 +81,16 @@ void loop() { Serial.println(Udp.remotePort()); // read the packet into packetBufffer - int len = Udp.read(packetBuffer,255); - if (len >0) packetBuffer[len]=0; + int len = Udp.read(packetBuffer, 255); + if (len > 0) packetBuffer[len] = 0; Serial.println("Contents:"); Serial.println(packetBuffer); - + // send a reply, to the IP address and port that sent us the packet we received Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); Udp.write(ReplyBuffer); Udp.endPacket(); - } + } } diff --git a/libraries/WiFi/examples/WiFiWebClient/WiFiWebClient.ino b/libraries/WiFi/examples/WiFiWebClient/WiFiWebClient.ino index ed02a8498..017b3572a 100644 --- a/libraries/WiFi/examples/WiFiWebClient/WiFiWebClient.ino +++ b/libraries/WiFi/examples/WiFiWebClient/WiFiWebClient.ino @@ -1,19 +1,19 @@ /* Web client - + This sketch connects to a website (http://www.google.com) using a WiFi shield. - - This example is written for a network using WPA encryption. For + + This example is written for a network using WPA encryption. For WEP or WPA, change the Wifi.begin() call accordingly. - - This example is written for a network using WPA encryption. For + + This example is written for a network using WPA encryption. For WEP or WPA, change the Wifi.begin() call accordingly. - + Circuit: * WiFi shield attached - + created 13 July 2010 by dlf (Metodo2 srl) modified 31 May 2012 @@ -24,7 +24,7 @@ #include #include -char ssid[] = "yourNetwork"; // your network SSID (name) +char ssid[] = "yourNetwork"; // your network SSID (name) char pass[] = "secretPassword"; // your network password (use for WPA, or use as key for WEP) int keyIndex = 0; // your network key Index number (needed only for WEP) @@ -35,41 +35,41 @@ int status = WL_IDLE_STATUS; char server[] = "www.google.com"; // name address for Google (using DNS) // Initialize the Ethernet client library -// with the IP address and port of the server +// with the IP address and port of the server // that you want to connect to (port 80 is default for HTTP): WiFiClient client; void setup() { //Initialize serial and wait for port to open: - Serial.begin(9600); + Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } - + // check for the presence of the shield: if (WiFi.status() == WL_NO_SHIELD) { - Serial.println("WiFi shield not present"); + Serial.println("WiFi shield not present"); // don't continue: - while(true); - } + while (true); + } String fv = WiFi.firmwareVersion(); - if( fv != "1.1.0" ) + if ( fv != "1.1.0" ) Serial.println("Please upgrade the firmware"); - + // attempt to connect to Wifi network: - while (status != WL_CONNECTED) { + while (status != WL_CONNECTED) { Serial.print("Attempting to connect to SSID: "); Serial.println(ssid); - // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: status = WiFi.begin(ssid, pass); - + // wait 10 seconds for connection: delay(10000); - } + } Serial.println("Connected to wifi"); printWifiStatus(); - + Serial.println("\nStarting connection to server..."); // if you get a connection, report back via serial: if (client.connect(server, 80)) { @@ -83,7 +83,7 @@ void setup() { } void loop() { - // if there are incoming bytes available + // if there are incoming bytes available // from the server, read them and print them: while (client.available()) { char c = client.read(); @@ -97,7 +97,7 @@ void loop() { client.stop(); // do nothing forevermore: - while(true); + while (true); } } diff --git a/libraries/WiFi/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino b/libraries/WiFi/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino index d4b5cf80f..b73494154 100644 --- a/libraries/WiFi/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino +++ b/libraries/WiFi/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino @@ -1,16 +1,16 @@ /* Repeating Wifi Web client - + This sketch connects to a a web server and makes a request using an Arduino Wifi shield. - + Circuit: * Wifi shield attached to pins 10, 11, 12, 13 - + created 23 April 2012 modifide 31 May 2012 by Tom Igoe - + http://arduino.cc/en/Tutorial/WifiWebClientRepeating This code is in the public domain. */ @@ -18,7 +18,7 @@ #include #include -char ssid[] = "yourNetwork"; // your network SSID (name) +char ssid[] = "yourNetwork"; // your network SSID (name) char pass[] = "secretPassword"; // your network password int keyIndex = 0; // your network key Index number (needed only for WEP) @@ -33,36 +33,36 @@ char server[] = "www.arduino.cc"; unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds boolean lastConnected = false; // state of the connection last time through the main loop -const unsigned long postingInterval = 10*1000; // delay between updates, in milliseconds +const unsigned long postingInterval = 10 * 1000; // delay between updates, in milliseconds void setup() { //Initialize serial and wait for port to open: - Serial.begin(9600); + Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } - + // check for the presence of the shield: if (WiFi.status() == WL_NO_SHIELD) { - Serial.println("WiFi shield not present"); + Serial.println("WiFi shield not present"); // don't continue: - while(true); - } + while (true); + } String fv = WiFi.firmwareVersion(); - if( fv != "1.1.0" ) + if ( fv != "1.1.0" ) Serial.println("Please upgrade the firmware"); - + // attempt to connect to Wifi network: - while ( status != WL_CONNECTED) { + while ( status != WL_CONNECTED) { Serial.print("Attempting to connect to SSID: "); Serial.println(ssid); - // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: status = WiFi.begin(ssid, pass); // wait 10 seconds for connection: delay(10000); - } + } // you're connected now, so print out the status: printWifiStatus(); } @@ -86,7 +86,7 @@ void loop() { // if you're not connected, and ten seconds have passed since // your last connection, then connect again and send data: - if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) { + if (!client.connected() && (millis() - lastConnectionTime > postingInterval)) { httpRequest(); } // store the state of the connection for next time through @@ -108,7 +108,7 @@ void httpRequest() { // note the time that the connection was made: lastConnectionTime = millis(); - } + } else { // if you couldn't make a connection: Serial.println("connection failed"); diff --git a/libraries/WiFi/examples/WiFiWebServer/WiFiWebServer.ino b/libraries/WiFi/examples/WiFiWebServer/WiFiWebServer.ino index c2ed9d1a8..4ea045683 100644 --- a/libraries/WiFi/examples/WiFiWebServer/WiFiWebServer.ino +++ b/libraries/WiFi/examples/WiFiWebServer/WiFiWebServer.ino @@ -1,16 +1,16 @@ /* WiFi Web Server - + A simple web server that shows the value of the analog input pins. using a WiFi shield. - - This example is written for a network using WPA encryption. For + + This example is written for a network using WPA encryption. For WEP or WPA, change the Wifi.begin() call accordingly. - + Circuit: * WiFi shield attached * Analog inputs attached to pins A0 through A5 (optional) - + created 13 July 2010 by dlf (Metodo2 srl) modified 31 May 2012 @@ -22,7 +22,7 @@ #include -char ssid[] = "yourNetwork"; // your network SSID (name) +char ssid[] = "yourNetwork"; // your network SSID (name) char pass[] = "secretPassword"; // your network password int keyIndex = 0; // your network key Index number (needed only for WEP) @@ -32,32 +32,32 @@ WiFiServer server(80); void setup() { //Initialize serial and wait for port to open: - Serial.begin(9600); + Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } - + // check for the presence of the shield: if (WiFi.status() == WL_NO_SHIELD) { - Serial.println("WiFi shield not present"); + Serial.println("WiFi shield not present"); // don't continue: - while(true); - } + while (true); + } String fv = WiFi.firmwareVersion(); - if( fv != "1.1.0" ) + if ( fv != "1.1.0" ) Serial.println("Please upgrade the firmware"); - + // attempt to connect to Wifi network: - while ( status != WL_CONNECTED) { + while ( status != WL_CONNECTED) { Serial.print("Attempting to connect to SSID: "); Serial.println(ssid); - // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: status = WiFi.begin(ssid, pass); // wait 10 seconds for connection: delay(10000); - } + } server.begin(); // you're connected now, so print out the status: printWifiStatus(); @@ -94,15 +94,15 @@ void loop() { client.print(analogChannel); client.print(" is "); client.print(sensorReading); - client.println("
"); + client.println("
"); } client.println(""); - break; + break; } if (c == '\n') { // you're starting a new line currentLineIsBlank = true; - } + } else if (c != '\r') { // you've gotten a character on the current line currentLineIsBlank = false; @@ -111,7 +111,7 @@ void loop() { } // give the web browser time to receive the data delay(1); - + // close the connection: client.stop(); Serial.println("client disonnected"); diff --git a/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino b/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino index 9c41c18f1..d97a9e3cf 100644 --- a/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino +++ b/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino @@ -1,8 +1,8 @@ -// I2C SRF10 or SRF08 Devantech Ultrasonic Ranger Finder +// I2C SRF10 or SRF08 Devantech Ultrasonic Ranger Finder // by Nicholas Zambetti -// and James Tichenor +// and James Tichenor -// Demonstrates use of the Wire library reading data from the +// Demonstrates use of the Wire library reading data from the // Devantech Utrasonic Rangers SFR08 and SFR10 // Created 29 April 2006 @@ -24,12 +24,12 @@ 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) - // but i2c adressing uses the high 7 bits so it's 112 - Wire.write(byte(0x00)); // sets register pointer to the command register (0x00) - Wire.write(byte(0x50)); // command sensor to measure in "inches" (0x50) - // use 0x51 for centimeters - // use 0x52 for ping microseconds + // the address specified in the datasheet is 224 (0xE0) + // but i2c adressing uses the high 7 bits so it's 112 + Wire.write(byte(0x00)); // sets register pointer to the command register (0x00) + Wire.write(byte(0x50)); // command sensor to measure in "inches" (0x50) + // use 0x51 for centimeters + // use 0x52 for ping microseconds Wire.endTransmission(); // stop transmitting // step 2: wait for readings to happen @@ -44,7 +44,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 diff --git a/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino b/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino index 38da1c543..4d1580a61 100644 --- a/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino +++ b/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino @@ -24,13 +24,13 @@ byte val = 0; void loop() { Wire.beginTransmission(44); // transmit to device #44 (0x2c) - // device address is specified in datasheet - Wire.write(byte(0x00)); // sends instruction byte - Wire.write(val); // sends potentiometer value byte + // device address is specified in datasheet + Wire.write(byte(0x00)); // sends instruction byte + Wire.write(val); // sends potentiometer value byte 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 } diff --git a/libraries/Wire/examples/master_reader/master_reader.ino b/libraries/Wire/examples/master_reader/master_reader.ino index 4124d7d6b..74f0155f8 100644 --- a/libraries/Wire/examples/master_reader/master_reader.ino +++ b/libraries/Wire/examples/master_reader/master_reader.ino @@ -22,8 +22,8 @@ void loop() { Wire.requestFrom(2, 6); // request 6 bytes from slave device #2 - 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 } diff --git a/libraries/Wire/examples/master_writer/master_writer.ino b/libraries/Wire/examples/master_writer/master_writer.ino index ccaa0361b..482e92237 100644 --- a/libraries/Wire/examples/master_writer/master_writer.ino +++ b/libraries/Wire/examples/master_writer/master_writer.ino @@ -23,7 +23,7 @@ void loop() { Wire.beginTransmission(4); // transmit to device #4 Wire.write("x is "); // sends five bytes - Wire.write(x); // sends one byte + Wire.write(x); // sends one byte Wire.endTransmission(); // stop transmitting x++; diff --git a/libraries/Wire/examples/slave_receiver/slave_receiver.ino b/libraries/Wire/examples/slave_receiver/slave_receiver.ino index 60dd4bdde..15eff9a54 100644 --- a/libraries/Wire/examples/slave_receiver/slave_receiver.ino +++ b/libraries/Wire/examples/slave_receiver/slave_receiver.ino @@ -28,7 +28,7 @@ void loop() // this function is registered as an event, see setup() void receiveEvent(int howMany) { - while(1 < Wire.available()) // loop through all but the last + 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 diff --git a/libraries/Wire/examples/slave_sender/slave_sender.ino b/libraries/Wire/examples/slave_sender/slave_sender.ino index d3b238af9..4437ab152 100644 --- a/libraries/Wire/examples/slave_sender/slave_sender.ino +++ b/libraries/Wire/examples/slave_sender/slave_sender.ino @@ -28,5 +28,5 @@ void loop() void requestEvent() { Wire.write("hello "); // respond with message of 6 bytes - // as expected by master + // as expected by master }