diff --git a/build/shared/examples/02.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino b/build/shared/examples/02.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino index 537353f6e..ca4ac95fa 100644 --- a/build/shared/examples/02.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino +++ b/build/shared/examples/02.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino @@ -8,17 +8,17 @@ * LED attached from pin 13 to ground. * Note: on most Arduinos, there is already an LED on the board that's attached to pin 13, so no hardware is needed for this example. - + created 2005 by David A. Mellis modified 8 Feb 2010 by Paul Stoffregen modified 11 Nov 2013 by Scott Fitzgerald - - + + This example code is in the public domain. - + http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay */ @@ -40,8 +40,7 @@ void setup() { pinMode(ledPin, OUTPUT); } -void loop() -{ +void loop() { // here is where you'd put code that needs to be running all the time. // check to see if it's time to blink the LED; that is, if the @@ -49,16 +48,17 @@ void loop() // the LED is bigger than the interval at which you want to // blink the LED. unsigned long currentMillis = millis(); - - if(currentMillis - previousMillis >= interval) { - // save the last time you blinked the LED - previousMillis = currentMillis; + + if (currentMillis - previousMillis >= interval) { + // save the last time you blinked the LED + previousMillis = currentMillis; // if the LED is off turn it on and vice-versa: - if (ledState == LOW) + if (ledState == LOW) { ledState = HIGH; - else + } else { ledState = LOW; + } // set the LED with the ledState of the variable: digitalWrite(ledPin, ledState); diff --git a/build/shared/examples/02.Digital/Button/Button.ino b/build/shared/examples/02.Digital/Button/Button.ino index 887d84da8..33cc454f4 100644 --- a/build/shared/examples/02.Digital/Button/Button.ino +++ b/build/shared/examples/02.Digital/Button/Button.ino @@ -48,8 +48,7 @@ void loop() { if (buttonState == HIGH) { // turn LED on: digitalWrite(ledPin, HIGH); - } - else { + } else { // turn LED off: digitalWrite(ledPin, LOW); } diff --git a/build/shared/examples/02.Digital/DigitalInputPullup/DigitalInputPullup.ino b/build/shared/examples/02.Digital/DigitalInputPullup/DigitalInputPullup.ino index 1ef28057e..7d9276b40 100644 --- a/build/shared/examples/02.Digital/DigitalInputPullup/DigitalInputPullup.ino +++ b/build/shared/examples/02.Digital/DigitalInputPullup/DigitalInputPullup.ino @@ -42,8 +42,7 @@ void loop() { // button's pressed, and off when it's not: if (sensorVal == HIGH) { digitalWrite(13, LOW); - } - else { + } else { digitalWrite(13, HIGH); } } diff --git a/build/shared/examples/02.Digital/StateChangeDetection/StateChangeDetection.ino b/build/shared/examples/02.Digital/StateChangeDetection/StateChangeDetection.ino index 148d5b202..3e2f3b365 100644 --- a/build/shared/examples/02.Digital/StateChangeDetection/StateChangeDetection.ino +++ b/build/shared/examples/02.Digital/StateChangeDetection/StateChangeDetection.ino @@ -58,8 +58,7 @@ void loop() { Serial.println("on"); Serial.print("number of button pushes: "); Serial.println(buttonPushCounter); - } - else { + } else { // if the current state is LOW then the button // wend from on to off: Serial.println("off"); diff --git a/build/shared/examples/03.Analog/AnalogInOutSerial/AnalogInOutSerial.ino b/build/shared/examples/03.Analog/AnalogInOutSerial/AnalogInOutSerial.ino index 42b5c1880..60c52ee9e 100644 --- a/build/shared/examples/03.Analog/AnalogInOutSerial/AnalogInOutSerial.ino +++ b/build/shared/examples/03.Analog/AnalogInOutSerial/AnalogInOutSerial.ino @@ -41,7 +41,7 @@ void loop() { analogWrite(analogOutPin, outputValue); // print the results to the serial monitor: - Serial.print("sensor = " ); + Serial.print("sensor = "); Serial.print(sensorValue); Serial.print("\t output = "); Serial.println(outputValue); diff --git a/build/shared/examples/03.Analog/Smoothing/Smoothing.ino b/build/shared/examples/03.Analog/Smoothing/Smoothing.ino index 7bd12082f..9a79c9caa 100644 --- a/build/shared/examples/03.Analog/Smoothing/Smoothing.ino +++ b/build/shared/examples/03.Analog/Smoothing/Smoothing.ino @@ -34,13 +34,13 @@ int average = 0; // the average int inputPin = A0; -void setup() -{ +void setup() { // initialize serial communication with computer: Serial.begin(9600); // initialize all the readings to 0: - for (int thisReading = 0; thisReading < numReadings; thisReading++) + for (int thisReading = 0; thisReading < numReadings; thisReading++) { readings[thisReading] = 0; + } } void loop() { @@ -54,9 +54,10 @@ void loop() { readIndex = readIndex + 1; // if we're at the end of the array... - if (readIndex >= numReadings) + if (readIndex >= numReadings) { // ...wrap around to the beginning: readIndex = 0; + } // calculate the average: average = total / numReadings; diff --git a/build/shared/examples/04.Communication/Dimmer/Dimmer.ino b/build/shared/examples/04.Communication/Dimmer/Dimmer.ino index 1555bc985..ef0e084de 100644 --- a/build/shared/examples/04.Communication/Dimmer/Dimmer.ino +++ b/build/shared/examples/04.Communication/Dimmer/Dimmer.ino @@ -23,8 +23,7 @@ const int ledPin = 9; // the pin that the LED is attached to -void setup() -{ +void setup() { // initialize the serial communication: Serial.begin(9600); // initialize the ledPin as an output: diff --git a/build/shared/examples/04.Communication/Graph/Graph.ino b/build/shared/examples/04.Communication/Graph/Graph.ino index 3d719499b..ee2ac0315 100644 --- a/build/shared/examples/04.Communication/Graph/Graph.ino +++ b/build/shared/examples/04.Communication/Graph/Graph.ino @@ -65,15 +65,15 @@ void loop() { // List all the available serial ports // if using Processing 2.1 or later, use Serial.printArray() println(Serial.list()); - + // I know that the first port in the serial list on my mac // is always my Arduino, so I open Serial.list()[0]. // Open whatever port is the one you're using. myPort = new Serial(this, Serial.list()[0], 9600); - + // don't generate a serialEvent() unless you get a newline character: myPort.bufferUntil('\n'); - + // set inital background: background(0); } diff --git a/build/shared/examples/04.Communication/PhysicalPixel/PhysicalPixel.ino b/build/shared/examples/04.Communication/PhysicalPixel/PhysicalPixel.ino index 355d849b7..25556af56 100644 --- a/build/shared/examples/04.Communication/PhysicalPixel/PhysicalPixel.ino +++ b/build/shared/examples/04.Communication/PhysicalPixel/PhysicalPixel.ino @@ -78,19 +78,19 @@ void loop() { size(200, 200); boxX = width/2.0; boxY = height/2.0; - rectMode(RADIUS); - - // List all the available serial ports in the output pane. - // You will need to choose the port that the Arduino board is - // connected to from this list. The first port in the list is - // port #0 and the third port in the list is port #2. + rectMode(RADIUS); + + // List all the available serial ports in the output pane. + // You will need to choose the port that the Arduino board is + // connected to from this list. The first port in the list is + // port #0 and the third port in the list is port #2. // if using Processing 2.1 or later, use Serial.printArray() - println(Serial.list()); - - // Open the port that the Arduino board is connected to (in this case #0) - // Make sure to open the port at the same speed Arduino is using (9600bps) - port = new Serial(this, Serial.list()[0], 9600); - + println(Serial.list()); + + // Open the port that the Arduino board is connected to (in this case #0) + // Make sure to open the port at the same speed Arduino is using (9600bps) + port = new Serial(this, Serial.list()[0], 9600); + } void draw() diff --git a/build/shared/examples/04.Communication/SerialCallResponse/SerialCallResponse.ino b/build/shared/examples/04.Communication/SerialCallResponse/SerialCallResponse.ino index 4982ea9b4..6f154c3ff 100644 --- a/build/shared/examples/04.Communication/SerialCallResponse/SerialCallResponse.ino +++ b/build/shared/examples/04.Communication/SerialCallResponse/SerialCallResponse.ino @@ -29,8 +29,7 @@ int secondSensor = 0; // second analog sensor int thirdSensor = 0; // digital sensor int inByte = 0; // incoming serial byte -void setup() -{ +void setup() { // start serial port at 9600 bps: Serial.begin(9600); while (!Serial) { @@ -41,8 +40,7 @@ void setup() establishContact(); // send a byte to establish contact until receiver responds } -void loop() -{ +void loop() { // if we get a valid byte, read analog ins: if (Serial.available() > 0) { // get incoming byte: diff --git a/build/shared/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino b/build/shared/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino index fd6cfc21e..837600788 100644 --- a/build/shared/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino +++ b/build/shared/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino @@ -33,8 +33,7 @@ int secondSensor = 0; // second analog sensor int thirdSensor = 0; // digital sensor int inByte = 0; // incoming serial byte -void setup() -{ +void setup() { // start serial port at 9600 bps and wait for port to open: Serial.begin(9600); while (!Serial) { @@ -46,8 +45,7 @@ void setup() establishContact(); // send a byte to establish contact until receiver responds } -void loop() -{ +void loop() { // if we get a valid byte, read analog ins: if (Serial.available() > 0) { // get incoming byte: diff --git a/build/shared/examples/04.Communication/VirtualColorMixer/VirtualColorMixer.ino b/build/shared/examples/04.Communication/VirtualColorMixer/VirtualColorMixer.ino index cd19ccbcb..d89b3d772 100644 --- a/build/shared/examples/04.Communication/VirtualColorMixer/VirtualColorMixer.ino +++ b/build/shared/examples/04.Communication/VirtualColorMixer/VirtualColorMixer.ino @@ -20,13 +20,11 @@ const int redPin = A0; // sensor to control red color const int greenPin = A1; // sensor to control green color const int bluePin = A2; // sensor to control blue color -void setup() -{ +void setup() { Serial.begin(9600); } -void loop() -{ +void loop() { Serial.print(analogRead(redPin)); Serial.print(","); Serial.print(analogRead(greenPin)); @@ -52,7 +50,7 @@ void loop() // List all the available serial ports // if using Processing 2.1 or later, use Serial.printArray() println(Serial.list()); - + // I know that the first port in the serial list on my mac // is always my Arduino, so I open Serial.list()[0]. // Open whatever port is the one you're using. diff --git a/build/shared/examples/05.Control/IfStatementConditional/IfStatementConditional.ino b/build/shared/examples/05.Control/IfStatementConditional/IfStatementConditional.ino index 2e7ce8f26..d9a4acf3e 100644 --- a/build/shared/examples/05.Control/IfStatementConditional/IfStatementConditional.ino +++ b/build/shared/examples/05.Control/IfStatementConditional/IfStatementConditional.ino @@ -44,8 +44,7 @@ void loop() { // if the analog value is high enough, turn on the LED: if (analogValue > threshold) { digitalWrite(ledPin, HIGH); - } - else { + } else { digitalWrite(ledPin, LOW); } diff --git a/build/shared/examples/05.Control/WhileStatementConditional/WhileStatementConditional.ino b/build/shared/examples/05.Control/WhileStatementConditional/WhileStatementConditional.ino index 543303eea..3da75a55c 100644 --- a/build/shared/examples/05.Control/WhileStatementConditional/WhileStatementConditional.ino +++ b/build/shared/examples/05.Control/WhileStatementConditional/WhileStatementConditional.ino @@ -43,8 +43,8 @@ int sensorValue = 0; // the sensor value void setup() { // set the LED pins as outputs and the switch pin as input: pinMode(indicatorLedPin, OUTPUT); - pinMode (ledPin, OUTPUT); - pinMode (buttonPin, INPUT); + pinMode(ledPin, OUTPUT); + pinMode(buttonPin, INPUT); } void loop() { diff --git a/build/shared/examples/06.Sensors/ADXL3xx/ADXL3xx.ino b/build/shared/examples/06.Sensors/ADXL3xx/ADXL3xx.ino index 19b073a4f..2515d60a0 100644 --- a/build/shared/examples/06.Sensors/ADXL3xx/ADXL3xx.ino +++ b/build/shared/examples/06.Sensors/ADXL3xx/ADXL3xx.ino @@ -33,8 +33,7 @@ const int xpin = A3; // x-axis of the accelerometer const int ypin = A2; // y-axis const int zpin = A1; // z-axis (only on 3-axis models) -void setup() -{ +void setup() { // initialize the serial communications: Serial.begin(9600); @@ -48,8 +47,7 @@ void setup() digitalWrite(powerpin, HIGH); } -void loop() -{ +void loop() { // print the sensor values: Serial.print(analogRead(xpin)); // print a tab between values: diff --git a/build/shared/examples/06.Sensors/Ping/Ping.ino b/build/shared/examples/06.Sensors/Ping/Ping.ino index 77adcb733..ab0cb899c 100644 --- a/build/shared/examples/06.Sensors/Ping/Ping.ino +++ b/build/shared/examples/06.Sensors/Ping/Ping.ino @@ -31,8 +31,7 @@ void setup() { Serial.begin(9600); } -void loop() -{ +void loop() { // establish variables for duration of the ping, // and the distance result in inches and centimeters: long duration, inches, cm; @@ -65,8 +64,7 @@ void loop() delay(100); } -long microsecondsToInches(long microseconds) -{ +long microsecondsToInches(long microseconds) { // According to Parallax's datasheet for the PING))), there are // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per // second). This gives the distance travelled by the ping, outbound @@ -75,8 +73,7 @@ long microsecondsToInches(long microseconds) return microseconds / 74 / 2; } -long microsecondsToCentimeters(long microseconds) -{ +long microsecondsToCentimeters(long microseconds) { // The speed of sound is 340 m/s or 29 microseconds per centimeter. // The ping travels out and back, so to find the distance of the // object we take half of the distance travelled. diff --git a/build/shared/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino b/build/shared/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino index 7386d2f50..ad731de51 100644 --- a/build/shared/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino +++ b/build/shared/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino @@ -25,7 +25,7 @@ void setup() { stringOne = String("stringThree = "); stringTwo = String("this string"); - stringThree = String (); + stringThree = String(); // send an intro: Serial.println("\n\nAdding strings together (concatenation):"); Serial.println(); diff --git a/build/shared/examples/08.Strings/StringComparisonOperators/StringComparisonOperators.ino b/build/shared/examples/08.Strings/StringComparisonOperators/StringComparisonOperators.ino index f58ca0ff5..d11c202fa 100644 --- a/build/shared/examples/08.Strings/StringComparisonOperators/StringComparisonOperators.ino +++ b/build/shared/examples/08.Strings/StringComparisonOperators/StringComparisonOperators.ino @@ -49,16 +49,14 @@ void loop() { // you can also use equals() to see if two strings are the same: if (stringOne.equals(stringTwo)) { Serial.println(stringOne + " equals " + stringTwo); - } - else { + } else { Serial.println(stringOne + " does not equal " + stringTwo); } // or perhaps you want to ignore case: if (stringOne.equalsIgnoreCase(stringTwo)) { Serial.println(stringOne + " equals (ignoring case) " + stringTwo); - } - else { + } else { Serial.println(stringOne + " does not equal (ignoring case) " + stringTwo); } @@ -103,10 +101,9 @@ void loop() { // comes first in alphanumeric order, then compareTo() is greater than 0: stringOne = "Cucumber"; stringTwo = "Cucuracha"; - if (stringOne.compareTo(stringTwo) < 0 ) { + if (stringOne.compareTo(stringTwo) < 0) { Serial.println(stringOne + " comes before " + stringTwo); - } - else { + } else { Serial.println(stringOne + " comes after " + stringTwo); } @@ -121,10 +118,9 @@ void loop() { stringOne += analogRead(A0); stringTwo += analogRead(A5); - if (stringOne.compareTo(stringTwo) < 0 ) { + if (stringOne.compareTo(stringTwo) < 0) { Serial.println(stringOne + " comes before " + stringTwo); - } - else { + } else { Serial.println(stringOne + " comes after " + stringTwo); } diff --git a/build/shared/examples/08.Strings/StringIndexOf/StringIndexOf.ino b/build/shared/examples/08.Strings/StringIndexOf/StringIndexOf.ino index d9cff117b..c7daddf9a 100644 --- a/build/shared/examples/08.Strings/StringIndexOf/StringIndexOf.ino +++ b/build/shared/examples/08.Strings/StringIndexOf/StringIndexOf.ino @@ -33,7 +33,7 @@ void loop() { stringOne = ""; int secondOpeningBracket = firstClosingBracket + 1; - int secondClosingBracket = stringOne.indexOf('>', secondOpeningBracket ); + int secondClosingBracket = stringOne.indexOf('>', secondOpeningBracket); Serial.println("The index of the second > in the string " + stringOne + " is " + secondClosingBracket); // you can also use indexOf() to search for Strings: @@ -43,7 +43,7 @@ void loop() { stringOne = ""; int firstListItem = stringOne.indexOf("
  • "); - int secondListItem = stringOne.indexOf("item", firstListItem + 1 ); + int secondListItem = stringOne.indexOf("item", firstListItem + 1); Serial.println("The index of the second list item in the string " + stringOne + " is " + secondClosingBracket); // lastIndexOf() gives you the last occurrence of a character or string: diff --git a/build/shared/examples/08.Strings/StringLength/StringLength.ino b/build/shared/examples/08.Strings/StringLength/StringLength.ino index 5ce9f29dd..9aa921011 100644 --- a/build/shared/examples/08.Strings/StringLength/StringLength.ino +++ b/build/shared/examples/08.Strings/StringLength/StringLength.ino @@ -41,8 +41,7 @@ void loop() { // if the String's longer than 140 characters, complain: if (txtMsg.length() < 140) { Serial.println("That's a perfectly acceptable text message"); - } - else { + } else { Serial.println("That's too long for a text message."); } // note the length for next time through the loop: diff --git a/build/shared/examples/08.Strings/StringStartsWithEndsWith/StringStartsWithEndsWith.ino b/build/shared/examples/08.Strings/StringStartsWithEndsWith/StringStartsWithEndsWith.ino index feba23395..3a5fb924d 100644 --- a/build/shared/examples/08.Strings/StringStartsWithEndsWith/StringStartsWithEndsWith.ino +++ b/build/shared/examples/08.Strings/StringStartsWithEndsWith/StringStartsWithEndsWith.ino @@ -41,11 +41,10 @@ void loop() { // endsWith() checks to see if a String ends with a particular character: String sensorReading = "sensor = "; sensorReading += analogRead(A0); - Serial.print (sensorReading); + Serial.print(sensorReading); if (sensorReading.endsWith("0")) { Serial.println(". This reading is divisible by ten"); - } - else { + } else { Serial.println(". This reading is not divisible by ten"); } diff --git a/build/shared/examples/09.USB/Keyboard/KeyboardMessage/KeyboardMessage.ino b/build/shared/examples/09.USB/Keyboard/KeyboardMessage/KeyboardMessage.ino index cf8ba5245..40a91abbe 100644 --- a/build/shared/examples/09.USB/Keyboard/KeyboardMessage/KeyboardMessage.ino +++ b/build/shared/examples/09.USB/Keyboard/KeyboardMessage/KeyboardMessage.ino @@ -1,22 +1,22 @@ -/* +/* Keyboard Message test - + For the Arduino Leonardo and Micro. - + Sends a text string when a button is pressed. The circuit: * pushbutton attached from pin 4 to +5V * 10-kilohm resistor attached from pin 4 to ground - + created 24 Oct 2011 modified 27 Mar 2012 by Tom Igoe modified 11 Nov 2013 by Scott Fitzgerald - + This example code is in the public domain. - + http://www.arduino.cc/en/Tutorial/KeyboardMessage */ diff --git a/build/shared/examples/09.USB/Keyboard/KeyboardReprogram/KeyboardReprogram.ino b/build/shared/examples/09.USB/Keyboard/KeyboardReprogram/KeyboardReprogram.ino index 02020751e..bc486a044 100644 --- a/build/shared/examples/09.USB/Keyboard/KeyboardReprogram/KeyboardReprogram.ino +++ b/build/shared/examples/09.USB/Keyboard/KeyboardReprogram/KeyboardReprogram.ino @@ -21,7 +21,7 @@ by Tom Igoe modified 3 May 2014 by Scott Fitzgerald - + This example is in the public domain http://www.arduino.cc/en/Tutorial/KeyboardReprogram @@ -58,7 +58,7 @@ void loop() { // wait for new window to open: delay(1000); - // versions of the Arduino IDE after 1.5 pre-populate + // versions of the Arduino IDE after 1.5 pre-populate // new sketches with setup() and loop() functions // let's clear the window before typing anything new // select all 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 db07cb4b4..f51a5e225 100644 --- a/build/shared/examples/10.StarterKit/p02_SpaceshipInterface/p02_SpaceshipInterface.ino +++ b/build/shared/examples/10.StarterKit/p02_SpaceshipInterface/p02_SpaceshipInterface.ino @@ -44,7 +44,7 @@ void loop() { switchstate = digitalRead(2); // if the button is not pressed - // turn on the green LED and off the red LEDs + // turn on the green LED and off the red LEDs if (switchstate == LOW) { digitalWrite(3, HIGH); // turn the green LED on pin 3 on digitalWrite(4, LOW); // turn the red LED on pin 4 off @@ -52,7 +52,7 @@ void loop() { } // this else is part of the above if() statement. // if the switch is not LOW (the button is pressed) - // turn off the green LED and blink alternatively the red LEDs + // turn off the green LED and blink alternatively the red LEDs else { digitalWrite(3, LOW); // turn the green LED on pin 3 off digitalWrite(4, LOW); // turn the red LED on pin 4 off 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 379a7dde9..ba913f25c 100644 --- a/build/shared/examples/10.StarterKit/p07_Keyboard/p07_Keyboard.ino +++ b/build/shared/examples/10.StarterKit/p07_Keyboard/p07_Keyboard.ino @@ -40,20 +40,16 @@ void loop() { if (keyVal == 1023) { // play the first frequency in the array on pin 8 tone(8, notes[0]); - } - else if (keyVal >= 990 && keyVal <= 1010) { + } else if (keyVal >= 990 && keyVal <= 1010) { // play the second frequency in the array on pin 8 tone(8, notes[1]); - } - else if (keyVal >= 505 && keyVal <= 515) { + } else if (keyVal >= 505 && keyVal <= 515) { // play the third frequency in the array on pin 8 tone(8, notes[2]); - } - else if (keyVal >= 5 && keyVal <= 10) { + } else if (keyVal >= 5 && keyVal <= 10) { // play the fourth frequency in the array on pin 8 tone(8, notes[3]); - } - else { + } else { // if the value is out of range, play no tone noTone(8); } 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 d4efae454..3c89a6ae4 100644 --- a/build/shared/examples/10.StarterKit/p09_MotorizedPinwheel/p09_MotorizedPinwheel.ino +++ b/build/shared/examples/10.StarterKit/p09_MotorizedPinwheel/p09_MotorizedPinwheel.ino @@ -42,8 +42,7 @@ void loop() { if (switchState == HIGH) { // turn motor on: digitalWrite(motorPin, HIGH); - } - else { + } else { // turn motor off: 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 7b1b7fa54..44d13ba63 100644 --- a/build/shared/examples/10.StarterKit/p10_Zoetrope/p10_Zoetrope.ino +++ b/build/shared/examples/10.StarterKit/p10_Zoetrope/p10_Zoetrope.ino @@ -84,8 +84,7 @@ void loop() { if (motorDirection == 1) { digitalWrite(controlPin1, HIGH); digitalWrite(controlPin2, LOW); - } - else { + } else { digitalWrite(controlPin1, LOW); digitalWrite(controlPin2, HIGH); } @@ -94,8 +93,7 @@ void loop() { if (motorEnabled == 1) { // PWM the enable pin to vary the speed analogWrite(enablePin, motorSpeed); - } - else { // if the motor is not supposed to be on + } else { // if the motor is not supposed to be on //turn the motor off analogWrite(enablePin, 0); } 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 042cdec8e..a1bb7e723 100644 --- a/build/shared/examples/10.StarterKit/p12_KnockLock/p12_KnockLock.ino +++ b/build/shared/examples/10.StarterKit/p12_KnockLock/p12_KnockLock.ino @@ -100,7 +100,7 @@ void loop() { Serial.println("the box is locked!"); // wait for the servo to move into position - delay (1000); + delay(1000); } } diff --git a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino index 7aaf1e680..d5bf7b81a 100644 --- a/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino +++ b/build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino @@ -105,8 +105,12 @@ parameter param; uint8_t hbval = 128; int8_t hbdelta = 8; void heartbeat() { - if (hbval > 192) hbdelta = -hbdelta; - if (hbval < 32) hbdelta = -hbdelta; + if (hbval > 192) { + hbdelta = -hbdelta; + } + if (hbval < 32) { + hbdelta = -hbdelta; + } hbval += hbdelta; analogWrite(LED_HB, hbval); delay(20); @@ -115,11 +119,17 @@ void heartbeat() { void loop(void) { // is pmode active? - if (pmode) digitalWrite(LED_PMODE, HIGH); - else digitalWrite(LED_PMODE, LOW); + if (pmode) { + digitalWrite(LED_PMODE, HIGH); + } else { + digitalWrite(LED_PMODE, LOW); + } // is there an error? - if (error) digitalWrite(LED_ERR, HIGH); - else digitalWrite(LED_ERR, LOW); + if (error) { + digitalWrite(LED_ERR, HIGH); + } else { + digitalWrite(LED_ERR, LOW); + } // light the heartbeat LED heartbeat(); @@ -145,13 +155,13 @@ void pulse(int pin, int times) { delay(PTIME); digitalWrite(pin, LOW); delay(PTIME); - } - while (times--); + } while (times--); } void prog_lamp(int state) { - if (PROG_FLICKER) + if (PROG_FLICKER) { digitalWrite(LED_PMODE, state); + } } void spi_init() { @@ -163,8 +173,7 @@ void spi_init() { void spi_wait() { do { - } - while (!(SPSR & (1 << SPIF))); + } while (!(SPSR & (1 << SPIF))); } uint8_t spi_send(uint8_t b) { @@ -188,8 +197,7 @@ void empty_reply() { if (CRC_EOP == getch()) { Serial.print((char)STK_INSYNC); Serial.print((char)STK_OK); - } - else { + } else { error++; Serial.print((char)STK_NOSYNC); } @@ -200,8 +208,7 @@ void breply(uint8_t b) { Serial.print((char)STK_INSYNC); Serial.print((char)b); Serial.print((char)STK_OK); - } - else { + } else { error++; Serial.print((char)STK_NOSYNC); } @@ -291,7 +298,9 @@ void flash(uint8_t hilo, int addr, uint8_t data) { data); } void commit(int addr) { - if (PROG_FLICKER) prog_lamp(LOW); + if (PROG_FLICKER) { + prog_lamp(LOW); + } spi_transaction(0x4C, (addr >> 8) & 0xFF, addr & 0xFF, 0); if (PROG_FLICKER) { delay(PTIME); @@ -301,10 +310,18 @@ void commit(int addr) { //#define _current_page(x) (here & 0xFFFFE0) int current_page(int addr) { - if (param.pagesize == 32) return here & 0xFFFFFFF0; - if (param.pagesize == 64) return here & 0xFFFFFFE0; - if (param.pagesize == 128) return here & 0xFFFFFFC0; - if (param.pagesize == 256) return here & 0xFFFFFF80; + if (param.pagesize == 32) { + return here & 0xFFFFFFF0; + } + if (param.pagesize == 64) { + return here & 0xFFFFFFE0; + } + if (param.pagesize == 128) { + return here & 0xFFFFFFC0; + } + if (param.pagesize == 256) { + return here & 0xFFFFFF80; + } return here; } @@ -314,8 +331,7 @@ void write_flash(int length) { if (CRC_EOP == getch()) { Serial.print((char) STK_INSYNC); Serial.print((char) write_flash_pages(length)); - } - else { + } else { error++; Serial.print((char) STK_NOSYNC); } @@ -386,8 +402,7 @@ void program_page() { if (CRC_EOP == getch()) { Serial.print((char) STK_INSYNC); Serial.print(result); - } - else { + } else { error++; Serial.print((char) STK_NOSYNC); } @@ -437,8 +452,12 @@ void read_page() { return; } Serial.print((char) STK_INSYNC); - if (memtype == 'F') result = flash_read_page(length); - if (memtype == 'E') result = eeprom_read_page(length); + if (memtype == 'F') { + result = flash_read_page(length); + } + if (memtype == 'E') { + result = eeprom_read_page(length); + } Serial.print(result); return; } @@ -533,20 +552,21 @@ int avrisp() { read_signature(); break; - // expecting a command, not CRC_EOP - // this is how we can get back in sync + // expecting a command, not CRC_EOP + // this is how we can get back in sync case CRC_EOP: error++; Serial.print((char) STK_NOSYNC); break; - // anything else we will return STK_UNKNOWN + // anything else we will return STK_UNKNOWN default: error++; - if (CRC_EOP == getch()) + if (CRC_EOP == getch()) { Serial.print((char)STK_UNKNOWN); - else + } else { Serial.print((char)STK_NOSYNC); + } } } diff --git a/examples_formatter.conf b/examples_formatter.conf new file mode 100644 index 000000000..5dc587ac0 --- /dev/null +++ b/examples_formatter.conf @@ -0,0 +1,44 @@ +# This configuration file contains a selection of the available options provided by the formatting tool "Artistic Style" +# http://astyle.sourceforge.net/astyle.html +# +# If you wish to change them, don't edit this file. +# Instead, copy it in the same folder of file "preferences.txt" and modify the copy. This way, you won't lose your custom formatter settings when upgrading the IDE +# If you don't know where file preferences.txt is stored, open the IDE, File -> Preferences and you'll find a link + +mode=c + +# 2 spaces indentation +indent=spaces=2 + +# also indent macros +indent-preprocessor + +# indent classes, switches (and cases), comments starting at column 1 +indent-classes +indent-switches +indent-cases +indent-col1-comments + +# put a space around operators +pad-oper + +# put a space after if/for/while +pad-header + +# if you like one-liners, keep them +keep-one-line-statements + +style=java +xn +xc +xl +xk +indent-modifiers +N +L +xW +w +xw +U +j + diff --git a/format.every.sketch.sh b/format.every.sketch.sh index 24b0ebc3e..02bfa9f5c 100644 --- a/format.every.sketch.sh +++ b/format.every.sketch.sh @@ -1,2 +1,2 @@ # you need to have astyle installed before running this -find libraries/ hardware/ -name '*.ino' -exec astyle --options=build/shared/lib/formatter.conf {} \; +find -name '*.ino' -exec /home/federico/materiale/works_Arduino/astyle/astyle-code/AStyle/build/gcc/bin/astyle --options=examples_formatter.conf {} \; diff --git a/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_clear/eeprom_clear.ino b/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_clear/eeprom_clear.ino index 49eb5fe55..73d64a723 100644 --- a/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_clear/eeprom_clear.ino +++ b/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_clear/eeprom_clear.ino @@ -10,26 +10,28 @@ #include -void setup() -{ +void setup() { /*** - Iterate through each byte of the EEPROM storage. - + Iterate through each byte of the EEPROM storage. + Larger AVR processors have larger EEPROM sizes, E.g: - Arduno Duemilanove: 512b EEPROM storage. - Arduino Uno: 1kb EEPROM storage. - Arduino Mega: 4kb EEPROM storage. - + Rather than hard-coding the length, you should use the pre-provided length function. - This will make your code portable to all AVR processors. + This will make your code portable to all AVR processors. ***/ - - for ( int i = 0 ; i < EEPROM.length() ; i++ ) + + for (int i = 0 ; i < EEPROM.length() ; i++) { EEPROM.write(i, 0); + } // turn the LED on when we're done digitalWrite(13, HIGH); } -void loop(){ /** Empty loop. **/ } +void loop() { + /** Empty loop. **/ +} diff --git a/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino b/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino index 8461d566a..d14b4b3d4 100644 --- a/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino +++ b/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino @@ -1,7 +1,7 @@ /*** Written by Christopher Andrews. CRC algorithm generated by pycrc, MIT licence ( https://github.com/tpircher/pycrc ). - + A CRC is a simple way of checking whether data has changed or become corrupted. This example calculates a CRC value directly on the EEPROM values. The purpose of this example is to highlight how the EEPROM object can be used just like an array. @@ -10,8 +10,8 @@ #include #include -void setup(){ - +void setup() { + //Start serial Serial.begin(9600); while (!Serial) { @@ -19,31 +19,33 @@ void setup(){ } //Print length of data to run CRC on. - Serial.print( "EEPROM length: " ); - Serial.println( EEPROM.length() ); - + Serial.print("EEPROM length: "); + Serial.println(EEPROM.length()); + //Print the result of calling eeprom_crc() - Serial.print( "CRC32 of EEPROM data: 0x" ); - Serial.println( eeprom_crc(), HEX ); - Serial.print( "\n\nDone!" ); + Serial.print("CRC32 of EEPROM data: 0x"); + Serial.println(eeprom_crc(), HEX); + Serial.print("\n\nDone!"); } -void loop(){ /* Empty loop */ } +void loop() { + /* Empty loop */ +} + +unsigned long eeprom_crc(void) { -unsigned long eeprom_crc( void ){ - const unsigned long crc_table[16] = { - 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, - 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c, - 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, - 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c - }; - + 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, + 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c, + 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, + 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c + }; + unsigned long crc = ~0L; - - for( int index = 0 ; index < EEPROM.length() ; ++index ){ - crc = crc_table[( crc ^ EEPROM[index] ) & 0x0f] ^ (crc >> 4); - crc = crc_table[( crc ^ ( EEPROM[index] >> 4 )) & 0x0f] ^ (crc >> 4); + + for (int index = 0 ; index < EEPROM.length() ; ++index) { + crc = crc_table[(crc ^ EEPROM[index]) & 0x0f] ^ (crc >> 4); + crc = crc_table[(crc ^ (EEPROM[index] >> 4)) & 0x0f] ^ (crc >> 4); crc = ~crc; } return crc; diff --git a/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_get/eeprom_get.ino b/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_get/eeprom_get.ino index 662099990..bbebc480e 100644 --- a/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_get/eeprom_get.ino +++ b/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_get/eeprom_get.ino @@ -1,66 +1,68 @@ /*** eeprom_get example. - + This shows how to use the EEPROM.get() method. - + To pre-set the EEPROM data, run the example sketch eeprom_put. - This sketch will run without it, however, the values shown + This sketch will run without it, however, the values shown will be shown from what ever is already on the EEPROM. - + This may cause the serial object to print out a large string of garbage if there is no null character inside one of the strings loaded. - + Written by Christopher Andrews 2015 - Released under MIT licence. + Released under MIT licence. ***/ #include -void setup(){ - +void setup() { + float f = 0.00f; //Variable to store data read from EEPROM. int eeAddress = 0; //EEPROM address to start reading from - - Serial.begin( 9600 ); + + Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } - Serial.print( "Read float from EEPROM: " ); + Serial.print("Read float from EEPROM: "); //Get the float data from the EEPROM at position 'eeAddress' - EEPROM.get( eeAddress, f ); - Serial.println( f, 3 ); //This may print 'ovf, nan' if the data inside the EEPROM is not a valid float. - + EEPROM.get(eeAddress, f); + Serial.println(f, 3); //This may print 'ovf, nan' if the data inside the EEPROM is not a valid float. + /*** As get also returns a reference to 'f', you can use it inline. E.g: Serial.print( EEPROM.get( eeAddress, f ) ); ***/ - - /*** - Get can be used with custom structures too. + + /*** + Get can be used with custom structures too. I have separated this into an extra function. ***/ - + secondTest(); //Run the next test. } -struct MyObject{ +struct MyObject { float field1; byte field2; char name[10]; }; -void secondTest(){ +void secondTest() { int eeAddress = sizeof(float); //Move address to the next byte after float 'f'. MyObject customVar; //Variable to store custom object read from EEPROM. - EEPROM.get( eeAddress, customVar ); - - Serial.println( "Read custom object from EEPROM: " ); - Serial.println( customVar.field1 ); - Serial.println( customVar.field2 ); - Serial.println( customVar.name ); + EEPROM.get(eeAddress, customVar); + + Serial.println("Read custom object from EEPROM: "); + Serial.println(customVar.field1); + Serial.println(customVar.field2); + Serial.println(customVar.name); } -void loop(){ /* Empty loop */ } \ No newline at end of file +void loop() { + /* Empty loop */ +} \ No newline at end of file diff --git a/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino b/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino index 650c90a75..3673b472f 100644 --- a/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino +++ b/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino @@ -1,12 +1,12 @@ /*** eeprom_iteration example. - + A set of example snippets highlighting the simplest methods for traversing the EEPROM. - - Running this sketch is not necessary, this is + + Running this sketch is not necessary, this is simply highlighting certain programming methods. - + Written by Christopher Andrews 2015 Released under MIT licence. ***/ @@ -18,40 +18,40 @@ void setup() { /*** Iterate the EEPROM using a for loop. ***/ - - for( int index = 0 ; index < EEPROM.length() ; index++ ){ + + for (int index = 0 ; index < EEPROM.length() ; index++) { //Add one to each cell in the EEPROM EEPROM[ index ] += 1; } - + /*** Iterate the EEPROM using a while loop. ***/ - + int index = 0; - - while( index < EEPROM.length() ){ - + + while (index < EEPROM.length()) { + //Add one to each cell in the EEPROM - EEPROM[ index ] += 1; + EEPROM[ index ] += 1; index++; } - + /*** Iterate the EEPROM using a do-while loop. ***/ - + int idx = 0; //Used 'idx' to avoid name conflict with 'index' above. - - do{ - + + do { + //Add one to each cell in the EEPROM - EEPROM[ idx ] += 1; + EEPROM[ idx ] += 1; idx++; - }while( idx < EEPROM.length() ); - - + } while (idx < EEPROM.length()); + + } //End of setup function. -void loop(){} \ No newline at end of file +void loop() {} \ No newline at end of file diff --git a/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_put/eeprom_put.ino b/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_put/eeprom_put.ino index 186cf95bd..fe8a9fb8b 100644 --- a/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_put/eeprom_put.ino +++ b/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_put/eeprom_put.ino @@ -1,28 +1,28 @@ /*** eeprom_put example. - + This shows how to use the EEPROM.put() method. - Also, this sketch will pre-set the EEPROM data for the + Also, this sketch will pre-set the EEPROM data for the example sketch eeprom_get. - + Note, unlike the single byte version EEPROM.write(), the put method will use update semantics. As in a byte will only be written to the EEPROM if the data is actually different. Written by Christopher Andrews 2015 - Released under MIT licence. + Released under MIT licence. ***/ #include -struct MyObject{ +struct MyObject { float field1; byte field2; char name[10]; }; -void setup(){ +void setup() { Serial.begin(9600); while (!Serial) { @@ -31,15 +31,15 @@ void setup(){ float f = 123.456f; //Variable to store in EEPROM. int eeAddress = 0; //Location we want the data to be put. - - + + //One simple call, with the address first and the object second. - EEPROM.put( eeAddress, f ); - + EEPROM.put(eeAddress, f); + Serial.println("Written float data type!"); - + /** Put is designed for use with custom structures also. **/ - + //Data to store. MyObject customVar = { 3.14f, @@ -48,9 +48,11 @@ void setup(){ }; eeAddress += sizeof(float); //Move address to the next byte after float 'f'. - - EEPROM.put( eeAddress, customVar ); - Serial.print( "Written custom data type! \n\nView the example sketch eeprom_get to see how you can retrieve the values!" ); + + EEPROM.put(eeAddress, customVar); + Serial.print("Written custom data type! \n\nView the example sketch eeprom_get to see how you can retrieve the values!"); } -void loop(){ /* Empty loop */ } \ No newline at end of file +void loop() { + /* Empty loop */ +} \ No newline at end of file diff --git a/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino b/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino index 68c4ffc74..25bc5d93d 100644 --- a/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino +++ b/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino @@ -12,8 +12,7 @@ int address = 0; byte value; -void setup() -{ +void setup() { // initialize serial and wait for port to open: Serial.begin(9600); while (!Serial) { @@ -21,8 +20,7 @@ void setup() } } -void loop() -{ +void loop() { // read a byte from the current address of the EEPROM value = EEPROM.read(address); @@ -32,24 +30,25 @@ void loop() Serial.println(); /*** - Advance to the next address, when at the end restart at the beginning. - + Advance to the next address, when at the end restart at the beginning. + Larger AVR processors have larger EEPROM sizes, E.g: - Arduno Duemilanove: 512b EEPROM storage. - Arduino Uno: 1kb EEPROM storage. - Arduino Mega: 4kb EEPROM storage. - + Rather than hard-coding the length, you should use the pre-provided length function. - This will make your code portable to all AVR processors. + This will make your code portable to all AVR processors. ***/ address = address + 1; - if(address == EEPROM.length()) + if (address == EEPROM.length()) { address = 0; - + } + /*** - As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an + As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an EEPROM address is also doable by a bitwise and of the length - 1. - + ++address &= EEPROM.length() - 1; ***/ diff --git a/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_update/eeprom_update.ino b/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_update/eeprom_update.ino index 831056fd7..5e3db5b4f 100644 --- a/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_update/eeprom_update.ino +++ b/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_update/eeprom_update.ino @@ -1,13 +1,13 @@ /*** EEPROM Update method - + Stores values read from analog input 0 into the EEPROM. These values will stay in the EEPROM when the board is turned off and may be retrieved later by another sketch. - + If a value has not changed in the EEPROM, it is not overwritten which would reduce the life span of the EEPROM unnecessarily. - + Released using MIT licence. ***/ @@ -16,10 +16,11 @@ /** the current address in the EEPROM (i.e. which byte we're going to write to next) **/ int address = 0; -void setup(){ /** EMpty setup **/ } +void setup() { + /** EMpty setup **/ +} -void loop() -{ +void loop() { /*** need to divide by 4 because analog inputs range from 0 to 1023 and each byte of the EEPROM can only hold a @@ -33,35 +34,36 @@ void loop() turned off. ***/ EEPROM.update(address, val); - + /*** The function EEPROM.update(address, val) is equivalent to the following: - + if( EEPROM.read(address) != val ){ EEPROM.write(address, val); } ***/ - + /*** - Advance to the next address, when at the end restart at the beginning. - + Advance to the next address, when at the end restart at the beginning. + Larger AVR processors have larger EEPROM sizes, E.g: - Arduno Duemilanove: 512b EEPROM storage. - Arduino Uno: 1kb EEPROM storage. - Arduino Mega: 4kb EEPROM storage. - + Rather than hard-coding the length, you should use the pre-provided length function. - This will make your code portable to all AVR processors. + This will make your code portable to all AVR processors. ***/ address = address + 1; - if(address == EEPROM.length()) + if (address == EEPROM.length()) { address = 0; - + } + /*** - As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an + As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an EEPROM address is also doable by a bitwise and of the length - 1. - + ++address &= EEPROM.length() - 1; ***/ diff --git a/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_write/eeprom_write.ino b/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_write/eeprom_write.ino index f07446c5a..f9bea641f 100644 --- a/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_write/eeprom_write.ino +++ b/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_write/eeprom_write.ino @@ -9,18 +9,19 @@ #include /** the current address in the EEPROM (i.e. which byte we're going to write to next) **/ -int addr = 0; +int addr = 0; -void setup(){ /** Empty setup. **/} +void setup() { + /** Empty setup. **/ +} -void loop() -{ +void loop() { /*** Need to divide by 4 because analog inputs range from 0 to 1023 and each byte of the EEPROM can only hold a value from 0 to 255. ***/ - + int val = analogRead(0) / 4; /*** @@ -28,28 +29,29 @@ void loop() these values will remain there when the board is turned off. ***/ - + EEPROM.write(addr, val); /*** - Advance to the next address, when at the end restart at the beginning. - + Advance to the next address, when at the end restart at the beginning. + Larger AVR processors have larger EEPROM sizes, E.g: - Arduno Duemilanove: 512b EEPROM storage. - Arduino Uno: 1kb EEPROM storage. - Arduino Mega: 4kb EEPROM storage. - + Rather than hard-coding the length, you should use the pre-provided length function. - This will make your code portable to all AVR processors. + This will make your code portable to all AVR processors. ***/ addr = addr + 1; - if(addr == EEPROM.length()) + if (addr == EEPROM.length()) { addr = 0; - + } + /*** - As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an + As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an EEPROM address is also doable by a bitwise and of the length - 1. - + ++addr &= EEPROM.length() - 1; ***/ diff --git a/hardware/arduino/avr/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino b/hardware/arduino/avr/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino index 8104fcbc2..df73adeb2 100644 --- a/hardware/arduino/avr/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino +++ b/hardware/arduino/avr/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino @@ -85,7 +85,7 @@ void loop() { } //Read from or write to register from the SCP1000: -unsigned int readRegister(byte thisRegister, int bytesToRead ) { +unsigned int readRegister(byte thisRegister, int bytesToRead) { byte inByte = 0; // incoming byte from the SPI unsigned int result = 0; // result to return Serial.print(thisRegister, BIN); @@ -117,7 +117,7 @@ unsigned int readRegister(byte thisRegister, int bytesToRead ) { // take the chip select high to de-select: digitalWrite(chipSelectPin, HIGH); // return the result: - return(result); + return (result); } diff --git a/hardware/arduino/avr/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino b/hardware/arduino/avr/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino index b135a74f4..c7afcc0a3 100644 --- a/hardware/arduino/avr/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino +++ b/hardware/arduino/avr/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino @@ -36,7 +36,7 @@ const int slaveSelectPin = 10; void setup() { // set the slaveSelectPin as an output: - pinMode (slaveSelectPin, OUTPUT); + pinMode(slaveSelectPin, OUTPUT); // initialize SPI: SPI.begin(); } diff --git a/hardware/arduino/avr/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino b/hardware/arduino/avr/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino index f65913301..d35303d55 100644 --- a/hardware/arduino/avr/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino +++ b/hardware/arduino/avr/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino @@ -29,8 +29,7 @@ SoftwareSerial mySerial(10, 11); // RX, TX -void setup() -{ +void setup() { // Open serial communications and wait for port to open: Serial.begin(57600); while (!Serial) { @@ -45,11 +44,12 @@ void setup() mySerial.println("Hello, world?"); } -void loop() // run over and over -{ - if (mySerial.available()) +void loop() { // run over and over + if (mySerial.available()) { Serial.write(mySerial.read()); - if (Serial.available()) + } + if (Serial.available()) { mySerial.write(Serial.read()); + } } diff --git a/hardware/arduino/avr/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino b/hardware/arduino/avr/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino index 95881a6c4..2c501e551 100644 --- a/hardware/arduino/avr/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino +++ b/hardware/arduino/avr/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino @@ -42,8 +42,7 @@ SoftwareSerial portOne(10, 11); // on the Mega, use other pins instead, since 8 and 9 don't work on the Mega SoftwareSerial portTwo(8, 9); -void setup() -{ +void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { @@ -56,8 +55,7 @@ void setup() portTwo.begin(9600); } -void loop() -{ +void loop() { // By default, the last intialized port is listening. // when you want to listen on a port, explicitly select it: portOne.listen(); diff --git a/hardware/arduino/avr/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino b/hardware/arduino/avr/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino index d97a9e3cf..4d0a68f8d 100644 --- a/hardware/arduino/avr/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino +++ b/hardware/arduino/avr/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino @@ -12,16 +12,14 @@ #include -void setup() -{ +void setup() { Wire.begin(); // join i2c bus (address optional for master) Serial.begin(9600); // start serial communication at 9600bps } int reading = 0; -void loop() -{ +void loop() { // step 1: instruct sensor to read echoes Wire.beginTransmission(112); // transmit to device #112 (0x70) // the address specified in the datasheet is 224 (0xE0) @@ -44,8 +42,7 @@ void loop() Wire.requestFrom(112, 2); // request 2 bytes from slave device #112 // step 5: receive reading from sensor - if (2 <= Wire.available()) // if two bytes were received - { + if (2 <= Wire.available()) { // if two bytes were received reading = Wire.read(); // receive high byte (overwrites previous reading) reading = reading << 8; // shift high byte to be high 8 bits reading |= Wire.read(); // receive low byte as lower 8 bits diff --git a/hardware/arduino/avr/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino b/hardware/arduino/avr/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino index 4d1580a61..5fb91fba0 100644 --- a/hardware/arduino/avr/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino +++ b/hardware/arduino/avr/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino @@ -14,15 +14,13 @@ #include -void setup() -{ +void setup() { Wire.begin(); // join i2c bus (address optional for master) } byte val = 0; -void loop() -{ +void loop() { Wire.beginTransmission(44); // transmit to device #44 (0x2c) // device address is specified in datasheet Wire.write(byte(0x00)); // sends instruction byte @@ -30,8 +28,7 @@ void loop() Wire.endTransmission(); // stop transmitting val++; // increment value - if (val == 64) // if reached 64th position (max) - { + if (val == 64) { // if reached 64th position (max) val = 0; // start over from lowest value } delay(500); diff --git a/hardware/arduino/avr/libraries/Wire/examples/master_reader/master_reader.ino b/hardware/arduino/avr/libraries/Wire/examples/master_reader/master_reader.ino index 2d2419b32..ecab72ab9 100644 --- a/hardware/arduino/avr/libraries/Wire/examples/master_reader/master_reader.ino +++ b/hardware/arduino/avr/libraries/Wire/examples/master_reader/master_reader.ino @@ -12,18 +12,15 @@ #include -void setup() -{ +void setup() { Wire.begin(); // join i2c bus (address optional for master) Serial.begin(9600); // start serial for output } -void loop() -{ +void loop() { Wire.requestFrom(8, 6); // request 6 bytes from slave device #8 - while (Wire.available()) // slave may send less than requested - { + while (Wire.available()) { // slave may send less than requested char c = Wire.read(); // receive a byte as character Serial.print(c); // print the character } diff --git a/hardware/arduino/avr/libraries/Wire/examples/master_writer/master_writer.ino b/hardware/arduino/avr/libraries/Wire/examples/master_writer/master_writer.ino index 9933cc2cd..5cbea1179 100644 --- a/hardware/arduino/avr/libraries/Wire/examples/master_writer/master_writer.ino +++ b/hardware/arduino/avr/libraries/Wire/examples/master_writer/master_writer.ino @@ -12,15 +12,13 @@ #include -void setup() -{ +void setup() { Wire.begin(); // join i2c bus (address optional for master) } byte x = 0; -void loop() -{ +void loop() { Wire.beginTransmission(8); // transmit to device #8 Wire.write("x is "); // sends five bytes Wire.write(x); // sends one byte diff --git a/hardware/arduino/avr/libraries/Wire/examples/slave_receiver/slave_receiver.ino b/hardware/arduino/avr/libraries/Wire/examples/slave_receiver/slave_receiver.ino index 53df27449..8051d53ac 100644 --- a/hardware/arduino/avr/libraries/Wire/examples/slave_receiver/slave_receiver.ino +++ b/hardware/arduino/avr/libraries/Wire/examples/slave_receiver/slave_receiver.ino @@ -12,24 +12,20 @@ #include -void setup() -{ +void setup() { Wire.begin(8); // join i2c bus with address #8 Wire.onReceive(receiveEvent); // register event Serial.begin(9600); // start serial for output } -void loop() -{ +void loop() { delay(100); } // function that executes whenever data is received from master // this function is registered as an event, see setup() -void receiveEvent(int howMany) -{ - while (1 < Wire.available()) // loop through all but the last - { +void receiveEvent(int howMany) { + while (1 < Wire.available()) { // loop through all but the last char c = Wire.read(); // receive byte as a character Serial.print(c); // print the character } diff --git a/hardware/arduino/avr/libraries/Wire/examples/slave_sender/slave_sender.ino b/hardware/arduino/avr/libraries/Wire/examples/slave_sender/slave_sender.ino index 26b9e5260..d2e72bbcf 100644 --- a/hardware/arduino/avr/libraries/Wire/examples/slave_sender/slave_sender.ino +++ b/hardware/arduino/avr/libraries/Wire/examples/slave_sender/slave_sender.ino @@ -12,21 +12,18 @@ #include -void setup() -{ +void setup() { Wire.begin(8); // join i2c bus with address #8 Wire.onRequest(requestEvent); // register event } -void loop() -{ +void loop() { delay(100); } // function that executes whenever data is requested by master // this function is registered as an event, see setup() -void requestEvent() -{ +void requestEvent() { Wire.write("hello "); // respond with message of 6 bytes // as expected by master } diff --git a/hardware/arduino/sam/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino b/hardware/arduino/sam/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino index 8104fcbc2..df73adeb2 100644 --- a/hardware/arduino/sam/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino +++ b/hardware/arduino/sam/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino @@ -85,7 +85,7 @@ void loop() { } //Read from or write to register from the SCP1000: -unsigned int readRegister(byte thisRegister, int bytesToRead ) { +unsigned int readRegister(byte thisRegister, int bytesToRead) { byte inByte = 0; // incoming byte from the SPI unsigned int result = 0; // result to return Serial.print(thisRegister, BIN); @@ -117,7 +117,7 @@ unsigned int readRegister(byte thisRegister, int bytesToRead ) { // take the chip select high to de-select: digitalWrite(chipSelectPin, HIGH); // return the result: - return(result); + return (result); } diff --git a/hardware/arduino/sam/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino b/hardware/arduino/sam/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino index b135a74f4..c7afcc0a3 100644 --- a/hardware/arduino/sam/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino +++ b/hardware/arduino/sam/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino @@ -36,7 +36,7 @@ const int slaveSelectPin = 10; void setup() { // set the slaveSelectPin as an output: - pinMode (slaveSelectPin, OUTPUT); + pinMode(slaveSelectPin, OUTPUT); // initialize SPI: SPI.begin(); } diff --git a/libraries/Audio/examples/SimpleAudioPlayer/SimpleAudioPlayer.ino b/libraries/Audio/examples/SimpleAudioPlayer/SimpleAudioPlayer.ino index f8e12bedd..2587cff86 100644 --- a/libraries/Audio/examples/SimpleAudioPlayer/SimpleAudioPlayer.ino +++ b/libraries/Audio/examples/SimpleAudioPlayer/SimpleAudioPlayer.ino @@ -22,8 +22,7 @@ #include #include -void setup() -{ +void setup() { // debug output at 9600 baud Serial.begin(9600); @@ -42,8 +41,7 @@ void setup() Audio.begin(88200, 100); } -void loop() -{ +void loop() { int count = 0; // open wave file from sdcard diff --git a/libraries/Bridge/examples/Bridge/Bridge.ino b/libraries/Bridge/examples/Bridge/Bridge.ino index aa90d5ca4..c6c7be3af 100644 --- a/libraries/Bridge/examples/Bridge/Bridge.ino +++ b/libraries/Bridge/examples/Bridge/Bridge.ino @@ -1,26 +1,26 @@ /* Arduino Yún Bridge example - This example for the Arduino Yún shows how to use the - Bridge library to access the digital and analog pins - on the board through REST calls. It demonstrates how - you can create your own API when using REST style - calls through the browser. + This example for the Arduino Yún shows how to use the + Bridge library to access the digital and analog pins + on the board through REST calls. It demonstrates how + you can create your own API when using REST style + calls through the browser. - Possible commands created in this shetch: + Possible commands created in this shetch: - * "/arduino/digital/13" -> digitalRead(13) - * "/arduino/digital/13/1" -> digitalWrite(13, HIGH) - * "/arduino/analog/2/123" -> analogWrite(2, 123) - * "/arduino/analog/2" -> analogRead(2) - * "/arduino/mode/13/input" -> pinMode(13, INPUT) - * "/arduino/mode/13/output" -> pinMode(13, OUTPUT) + "/arduino/digital/13" -> digitalRead(13) + "/arduino/digital/13/1" -> digitalWrite(13, HIGH) + "/arduino/analog/2/123" -> analogWrite(2, 123) + "/arduino/analog/2" -> analogRead(2) + "/arduino/mode/13/input" -> pinMode(13, INPUT) + "/arduino/mode/13/output" -> pinMode(13, OUTPUT) - This example code is part of the public domain + This example code is part of the public domain - http://www.arduino.cc/en/Tutorial/Bridge + http://www.arduino.cc/en/Tutorial/Bridge - */ +*/ #include #include @@ -90,8 +90,7 @@ void digitalCommand(BridgeClient client) { if (client.read() == '/') { value = client.parseInt(); digitalWrite(pin, value); - } - else { + } else { value = digitalRead(pin); } @@ -130,8 +129,7 @@ void analogCommand(BridgeClient client) { String key = "D"; key += pin; Bridge.put(key, String(value)); - } - else { + } else { // Read analog pin value = analogRead(pin); diff --git a/libraries/Bridge/examples/ConsoleRead/ConsoleRead.ino b/libraries/Bridge/examples/ConsoleRead/ConsoleRead.ino index cf4e149b4..8fc37fbe6 100644 --- a/libraries/Bridge/examples/ConsoleRead/ConsoleRead.ino +++ b/libraries/Bridge/examples/ConsoleRead/ConsoleRead.ino @@ -49,8 +49,7 @@ void loop() { // Ask again for name and clear the old name Console.println("Hi, what's your name?"); name = ""; // clear the name string - } - else { // if the buffer is empty Cosole.read() returns -1 + } else { // if the buffer is empty Cosole.read() returns -1 name += c; // append the read char from Console to the name string } } else { diff --git a/libraries/Bridge/examples/Datalogger/Datalogger.ino b/libraries/Bridge/examples/Datalogger/Datalogger.ino index 1aa5f5db3..c70134819 100644 --- a/libraries/Bridge/examples/Datalogger/Datalogger.ino +++ b/libraries/Bridge/examples/Datalogger/Datalogger.ino @@ -43,7 +43,7 @@ void setup() { } -void loop () { +void loop() { // make a string that start with a timestamp for assembling the data to log: String dataString; dataString += getTimeStamp(); @@ -93,8 +93,9 @@ String getTimeStamp() { // read the output of the command while (time.available() > 0) { char c = time.read(); - if (c != '\n') + if (c != '\n') { result += c; + } } return result; diff --git a/libraries/Bridge/examples/MailboxReadMessage/MailboxReadMessage.ino b/libraries/Bridge/examples/MailboxReadMessage/MailboxReadMessage.ino index 3e8115d9f..dc128ca7b 100644 --- a/libraries/Bridge/examples/MailboxReadMessage/MailboxReadMessage.ino +++ b/libraries/Bridge/examples/MailboxReadMessage/MailboxReadMessage.ino @@ -43,11 +43,9 @@ void loop() { String message; // if there is a message in the Mailbox - if (Mailbox.messageAvailable()) - { + if (Mailbox.messageAvailable()) { // read all the messages present in the queue - while (Mailbox.messageAvailable()) - { + while (Mailbox.messageAvailable()) { Mailbox.readMessage(message); Serial.println(message); } diff --git a/libraries/Bridge/examples/SpacebrewYun/inputOutput/inputOutput.ino b/libraries/Bridge/examples/SpacebrewYun/inputOutput/inputOutput.ino index e90a8a325..617e4e867 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 Yún is connected to the internet for this example to function properly. - + The circuit: - No circuit required - + created 2013 by Julio Terra - + This example code is in the public domain. - - More information about Spacebrew is available at: + + More information about Spacebrew is available at: http://spacebrew.cc/ - + */ #include @@ -33,100 +33,102 @@ int interval = 2000; int counter = 0; -void setup() { +void setup() { - // start the serial port - Serial.begin(57600); + // start the serial port + Serial.begin(57600); - // for debugging, wait until a serial console is connected - delay(4000); - while (!Serial) { ; } + // for debugging, wait until a serial console is connected + delay(4000); + while (!Serial) { + ; + } - // start-up the bridge - Bridge.begin(); + // start-up the bridge + Bridge.begin(); - // configure the spacebrew object to print status messages to serial - sb.verbose(true); + // configure the spacebrew object to print status messages to serial + sb.verbose(true); - // configure the spacebrew publisher and subscriber - sb.addPublish("string test", "string"); - sb.addPublish("range test", "range"); - sb.addPublish("boolean test", "boolean"); - sb.addPublish("custom test", "crazy"); - sb.addSubscribe("string test", "string"); - sb.addSubscribe("range test", "range"); - sb.addSubscribe("boolean test", "boolean"); - sb.addSubscribe("custom test", "crazy"); + // configure the spacebrew publisher and subscriber + sb.addPublish("string test", "string"); + sb.addPublish("range test", "range"); + sb.addPublish("boolean test", "boolean"); + sb.addPublish("custom test", "crazy"); + sb.addSubscribe("string test", "string"); + sb.addSubscribe("range test", "range"); + sb.addSubscribe("boolean test", "boolean"); + sb.addSubscribe("custom test", "crazy"); - // register the string message handler method - sb.onRangeMessage(handleRange); - sb.onStringMessage(handleString); - sb.onBooleanMessage(handleBoolean); - sb.onCustomMessage(handleCustom); + // register the string message handler method + sb.onRangeMessage(handleRange); + sb.onStringMessage(handleString); + sb.onBooleanMessage(handleBoolean); + sb.onCustomMessage(handleCustom); - // connect to cloud spacebrew server at "sandbox.spacebrew.cc" - sb.connect("sandbox.spacebrew.cc"); - // we give some time to arduino to connect to sandbox, otherwise the first sb.monitor(); call will give an error - delay(1000); -} + // connect to cloud spacebrew server at "sandbox.spacebrew.cc" + sb.connect("sandbox.spacebrew.cc"); + // we give some time to arduino to connect to sandbox, otherwise the first sb.monitor(); call will give an error + delay(1000); +} -void loop() { - // monitor spacebrew connection for new data - sb.monitor(); +void loop() { + // monitor spacebrew connection for new data + sb.monitor(); - // connected to spacebrew then send a string every 2 seconds - if ( sb.connected() ) { + // connected to spacebrew then send a string every 2 seconds + if (sb.connected()) { - // check if it is time to send a new message - if ( (millis() - last) > interval ) { - String test_str_msg = "testing, testing, "; - test_str_msg += counter; - counter ++; + // check if it is time to send a new message + if ((millis() - last) > interval) { + String test_str_msg = "testing, testing, "; + test_str_msg += counter; + counter ++; - sb.send("string test", test_str_msg); - sb.send("range test", 500); - sb.send("boolean test", true); - sb.send("custom test", "youre loco"); + sb.send("string test", test_str_msg); + sb.send("range test", 500); + sb.send("boolean test", true); + sb.send("custom test", "youre loco"); - last = millis(); + last = millis(); - } - } - delay(1000); -} + } + } + delay(1000); +} // define handler methods, all standard data type handlers take two appropriate arguments -void handleRange (String route, int value) { - Serial.print("Range msg "); - Serial.print(route); - Serial.print(", value "); - Serial.println(value); +void handleRange(String route, int value) { + Serial.print("Range msg "); + Serial.print(route); + Serial.print(", value "); + Serial.println(value); } -void handleString (String route, String value) { - Serial.print("String msg "); - Serial.print(route); - Serial.print(", value "); - Serial.println(value); +void handleString(String route, String value) { + Serial.print("String msg "); + Serial.print(route); + Serial.print(", value "); + Serial.println(value); } -void handleBoolean (String route, boolean value) { - Serial.print("Boolen msg "); - Serial.print(route); - Serial.print(", value "); - Serial.println(value ? "true" : "false"); +void handleBoolean(String route, boolean value) { + Serial.print("Boolen msg "); + Serial.print(route); + Serial.print(", value "); + Serial.println(value ? "true" : "false"); } // custom data type handlers takes three String arguments -void handleCustom (String route, String value, String type) { - Serial.print("Custom msg "); - Serial.print(route); - Serial.print(" of type "); - Serial.print(type); - Serial.print(", value "); - Serial.println(value); +void handleCustom(String route, String value, String type) { + Serial.print("Custom msg "); + Serial.print(route); + Serial.print(" of type "); + Serial.print(type); + Serial.print(", value "); + Serial.println(value); } diff --git a/libraries/Bridge/examples/SpacebrewYun/spacebrewBoolean/spacebrewBoolean.ino b/libraries/Bridge/examples/SpacebrewYun/spacebrewBoolean/spacebrewBoolean.ino index 656f81ed2..97d188b08 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 Yún is connected to the internet for this example to function properly. - + The circuit: - Button connected to Yún, using the Arduino's internal pullup resistor. - + created 2013 by Julio Terra - + This example code is in the public domain. - - More information about Spacebrew is available at: + + More information about Spacebrew is available at: http://spacebrew.cc/ - + */ #include @@ -33,57 +33,62 @@ SpacebrewYun sb = SpacebrewYun("spacebrewYun Boolean", "Boolean sender and recei int last_value = 0; // create variables to manage interval between each time we send a string -void setup() { +void setup() { - // start the serial port - Serial.begin(57600); + // start the serial port + Serial.begin(57600); - // for debugging, wait until a serial console is connected - delay(4000); - while (!Serial) { ; } + // for debugging, wait until a serial console is connected + delay(4000); + while (!Serial) { + ; + } - // start-up the bridge - Bridge.begin(); + // start-up the bridge + Bridge.begin(); - // configure the spacebrew object to print status messages to serial - sb.verbose(true); + // configure the spacebrew object to print status messages to serial + sb.verbose(true); - // configure the spacebrew publisher and subscriber - sb.addPublish("physical button", "boolean"); - sb.addSubscribe("virtual button", "boolean"); + // configure the spacebrew publisher and subscriber + sb.addPublish("physical button", "boolean"); + sb.addSubscribe("virtual button", "boolean"); - // register the string message handler method - sb.onBooleanMessage(handleBoolean); + // register the string message handler method + sb.onBooleanMessage(handleBoolean); - // connect to cloud spacebrew server at "sandbox.spacebrew.cc" - sb.connect("sandbox.spacebrew.cc"); + // connect to cloud spacebrew server at "sandbox.spacebrew.cc" + sb.connect("sandbox.spacebrew.cc"); - pinMode(3, INPUT); - digitalWrite(3, HIGH); -} - - -void loop() { - // monitor spacebrew connection for new data - sb.monitor(); - - // connected to spacebrew then send a new value whenever the pot value changes - if ( sb.connected() ) { - int cur_value = digitalRead(3); - if ( last_value != cur_value ) { - if (cur_value == HIGH) sb.send("physical button", false); - else sb.send("physical button", true); - last_value = cur_value; - } - } -} - -// handler method that is called whenever a new string message is received -void handleBoolean (String route, boolean value) { - // print the message that was received - Serial.print("From "); - Serial.print(route); - Serial.print(", received msg: "); - Serial.println(value ? "true" : "false"); + pinMode(3, INPUT); + digitalWrite(3, HIGH); +} + + +void loop() { + // monitor spacebrew connection for new data + sb.monitor(); + + // connected to spacebrew then send a new value whenever the pot value changes + if (sb.connected()) { + int cur_value = digitalRead(3); + if (last_value != cur_value) { + if (cur_value == HIGH) { + sb.send("physical button", false); + } else { + sb.send("physical button", true); + } + last_value = cur_value; + } + } +} + +// handler method that is called whenever a new string message is received +void handleBoolean(String route, boolean value) { + // print the message that was received + Serial.print("From "); + Serial.print(route); + Serial.print(", received msg: "); + Serial.println(value ? "true" : "false"); } diff --git a/libraries/Bridge/examples/SpacebrewYun/spacebrewRange/spacebrewRange.ino b/libraries/Bridge/examples/SpacebrewYun/spacebrewRange/spacebrewRange.ino index 75de12936..c1c752a69 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 Yún is connected to the internet for this example to function properly. - + The circuit: - Potentiometer connected to Yún. Middle pin connected to analog pin A0, other pins connected to 5v and GND pins. - + created 2013 by Julio Terra - + This example code is in the public domain. - - More information about Spacebrew is available at: + + More information about Spacebrew is available at: http://spacebrew.cc/ - + */ #include @@ -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 e339cbfbc..40cdc55d8 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 Yún is connected to the internet for this example to function properly. - + The circuit: - No circuit required - + created 2013 by Julio Terra - + This example code is in the public domain. - - More information about Spacebrew is available at: + + More information about Spacebrew is available at: http://spacebrew.cc/ - + */ #include @@ -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/GetYahooWeatherReport/GetYahooWeatherReport.ino b/libraries/Bridge/examples/Temboo/GetYahooWeatherReport/GetYahooWeatherReport.ino index f28117f59..8eb36dfb2 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 Yún. Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino - - A Temboo account and application key are necessary to run all Temboo examples. - If you don't already have one, you can register for a free Temboo account at + + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at http://www.temboo.com - + This example assumes basic familiarity with Arduino sketches, and that your Yún is connected to the Internet. Looking for another API to use with your Arduino Yún? We've got over 100 in our Library! - + This example code is in the public domain. */ #include #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,25 +32,24 @@ int maxRuns = 10; // max number of times the Yahoo WeatherByAddress Choreo shou void setup() { Serial.begin(9600); - + // for debugging, wait until a serial console is connected delay(4000); - while(!Serial); + while (!Serial); Bridge.begin(); } -void loop() -{ +void loop() { // while we haven't reached the max number of runs... if (numRuns <= maxRuns) { - + // print status Serial.println("Running GetWeatherByAddress - Run #" + String(numRuns++) + "..."); // create a TembooChoreo object to send a Choreo request to Temboo TembooChoreo GetWeatherByAddressChoreo; - + // invoke the Temboo client GetWeatherByAddressChoreo.begin(); @@ -58,30 +57,30 @@ void loop() GetWeatherByAddressChoreo.setAccountName(TEMBOO_ACCOUNT); GetWeatherByAddressChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); GetWeatherByAddressChoreo.setAppKey(TEMBOO_APP_KEY); - + // set the name of the choreo we want to run GetWeatherByAddressChoreo.setChoreo("/Library/Yahoo/Weather/GetWeatherByAddress"); - + // set choreo inputs; in this case, the address for which to retrieve weather data // the Temboo client provides standardized calls to 100+ cloud APIs GetWeatherByAddressChoreo.addInput("Address", ADDRESS_FOR_FORECAST); // add an output filter to extract the name of the city. GetWeatherByAddressChoreo.addOutputFilter("city", "/rss/channel/yweather:location/@city", "Response"); - + // add an output filter to extract the current temperature GetWeatherByAddressChoreo.addOutputFilter("temperature", "/rss/channel/item/yweather:condition/@temp", "Response"); // add an output filter to extract the date and time of the last report. GetWeatherByAddressChoreo.addOutputFilter("date", "/rss/channel/item/yweather:condition/@date", "Response"); - // run the choreo + // run the choreo GetWeatherByAddressChoreo.run(); - + // when the choreo results are available, print them to the serial monitor - while(GetWeatherByAddressChoreo.available()) { - - char c = GetWeatherByAddressChoreo.read(); + while (GetWeatherByAddressChoreo.available()) { + + char c = GetWeatherByAddressChoreo.read(); Serial.print(c); } GetWeatherByAddressChoreo.close(); @@ -101,15 +100,15 @@ void loop() by inserting your own Temboo account name and app key information. The contents of the file should look like: - #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key - You can find your Temboo App Key information on the Temboo website, + You can find your Temboo App Key information on the Temboo website, under My Account > Application Keys The same TembooAccount.h file settings can be used for all Temboo SDK sketches. - Keeping your account information in a separate file means you can share the main .ino file without worrying + Keeping your account information in a separate file means you can share the main .ino file without worrying that you forgot to delete your credentials. */ diff --git a/libraries/Bridge/examples/Temboo/ReadATweet/ReadATweet.ino b/libraries/Bridge/examples/Temboo/ReadATweet/ReadATweet.ino index d9d67a621..59991238e 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 Yún. Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino - A Temboo account and application key are necessary to run all Temboo examples. - If you don't already have one, you can register for a free Temboo account at + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at http://www.temboo.com In order to run this sketch, you'll need to register an application using - the Twitter dev console at https://dev.twitter.com. After creating the - app, you'll find OAuth credentials for that application under the "OAuth Tool" tab. - Substitute these values for the placeholders below. + the Twitter dev console at https://dev.twitter.com. After creating the + app, you'll find OAuth credentials for that application under the "OAuth Tool" tab. + Substitute these values for the placeholders below. This example assumes basic familiarity with Arduino sketches, and that your Yún is connected to the Internet. Want to use another social API with your Arduino Yún? We've got Facebook, Google+, Instagram, Tumblr and more in our Library! - + This example code is in the public domain. */ #include #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,25 +43,24 @@ int maxRuns = 10; // the max number of times the Twitter HomeTimeline Choreo s void setup() { Serial.begin(9600); - + // For debugging, wait until a serial console is connected. delay(4000); - while(!Serial); + while (!Serial); Bridge.begin(); } -void loop() -{ +void loop() { // while we haven't reached the max number of runs... if (numRuns <= maxRuns) { Serial.println("Running ReadATweet - Run #" + String(numRuns++)); - + TembooChoreo HomeTimelineChoreo; // invoke the Temboo client. // NOTE that the client must be reinvoked, and repopulated with // appropriate arguments, each time its run() method is called. HomeTimelineChoreo.begin(); - + // set Temboo account credentials HomeTimelineChoreo.setAccountName(TEMBOO_ACCOUNT); HomeTimelineChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); @@ -69,8 +68,8 @@ void loop() // tell the Temboo client which Choreo to run (Twitter > Timelines > HomeTimeline) HomeTimelineChoreo.setChoreo("/Library/Twitter/Timelines/HomeTimeline"); - - + + // set the required choreo inputs // see https://www.temboo.com/library/Library/Twitter/Timelines/HomeTimeline/ // for complete details about the inputs for this Choreo @@ -78,44 +77,44 @@ void loop() HomeTimelineChoreo.addInput("Count", "1"); // the max number of Tweets to return from each request HomeTimelineChoreo.addInput("AccessToken", TWITTER_ACCESS_TOKEN); HomeTimelineChoreo.addInput("AccessTokenSecret", TWITTER_ACCESS_TOKEN_SECRET); - HomeTimelineChoreo.addInput("ConsumerKey", TWITTER_CONSUMER_KEY); + HomeTimelineChoreo.addInput("ConsumerKey", TWITTER_CONSUMER_KEY); HomeTimelineChoreo.addInput("ConsumerSecret", TWITTER_CONSUMER_SECRET); - // next, we'll define two output filters that let us specify the + // next, we'll define two output filters that let us specify the // elements of the response from Twitter that we want to receive. // see the examples at http://www.temboo.com/arduino // for more on using output filters - + // we want the text of the tweet HomeTimelineChoreo.addOutputFilter("tweet", "/[1]/text", "Response"); - + // and the name of the author HomeTimelineChoreo.addOutputFilter("author", "/[1]/user/screen_name", "Response"); - // tell the Process to run and wait for the results. The - // return code will tell us whether the Temboo client + // tell the Process to run and wait for the results. The + // return code will tell us whether the Temboo client // was able to send our request to the Temboo servers unsigned int returnCode = HomeTimelineChoreo.run(); - - // a response code of 0 means success; print the API response - if(returnCode == 0) { - + + // a response code of 0 means success; print the API response + if (returnCode == 0) { + String author; // a String to hold the tweet author's name String tweet; // a String to hold the text of the tweet - // choreo outputs are returned as key/value pairs, delimited with + // choreo outputs are returned as key/value pairs, delimited with // newlines and record/field terminator characters, for example: // Name1\n\x1F // Value1\n\x1E // Name2\n\x1F - // Value2\n\x1E - + // Value2\n\x1E + // see the examples at http://www.temboo.com/arduino for more details // we can read this format into separate variables, as follows: - - while(HomeTimelineChoreo.available()) { + + while (HomeTimelineChoreo.available()) { // read the name of the output item String name = HomeTimelineChoreo.readStringUntil('\x1F'); name.trim(); @@ -131,13 +130,13 @@ void loop() author = data; } } - + Serial.println("@" + author + " - " + tweet); - + } else { // there was an error // print the raw output from the choreo - while(HomeTimelineChoreo.available()) { + while (HomeTimelineChoreo.available()) { char c = HomeTimelineChoreo.read(); Serial.print(c); } @@ -159,15 +158,15 @@ void loop() by inserting your own Temboo account name and app key information. The contents of the file should look like: - #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key - You can find your Temboo App Key information on the Temboo website, + You can find your Temboo App Key information on the Temboo website, under My Account > Application Keys The same TembooAccount.h file settings can be used for all Temboo SDK sketches. - Keeping your account information in a separate file means you can share the main .ino file without worrying + Keeping your account information in a separate file means you can share the main .ino file without worrying that you forgot to delete your credentials. */ diff --git a/libraries/Bridge/examples/Temboo/SendATweet/SendATweet.ino b/libraries/Bridge/examples/Temboo/SendATweet/SendATweet.ino index bf47bc65c..275f3506e 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 Yún is connected to the Internet. Want to use another social API with your Arduino Yún? We've got Facebook, Google+, Instagram, Tumblr and more in our Library! - + This example code is in the public domain. */ #include #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,29 +48,28 @@ void setup() { // for debugging, wait until a serial console is connected delay(4000); - while(!Serial); + while (!Serial); Bridge.begin(); } -void loop() -{ +void loop() { // only try to send the tweet if we haven't already sent it successfully if (numRuns <= maxRuns) { Serial.println("Running SendATweet - Run #" + String(numRuns++) + "..."); - + // define the text of the tweet we want to send String tweetText("My Arduino Yun has been running for " + String(millis()) + " milliseconds."); - + TembooChoreo StatusesUpdateChoreo; // invoke the Temboo client // NOTE that the client must be reinvoked, and repopulated with // appropriate arguments, each time its run() method is called. StatusesUpdateChoreo.begin(); - + // set Temboo account credentials StatusesUpdateChoreo.setAccountName(TEMBOO_ACCOUNT); StatusesUpdateChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); @@ -80,26 +79,26 @@ void loop() StatusesUpdateChoreo.setChoreo("/Library/Twitter/Tweets/StatusesUpdate"); // set the required choreo inputs - // see https://www.temboo.com/library/Library/Twitter/Tweets/StatusesUpdate/ + // see https://www.temboo.com/library/Library/Twitter/Tweets/StatusesUpdate/ // for complete details about the inputs for this Choreo - + // add the Twitter account information StatusesUpdateChoreo.addInput("AccessToken", TWITTER_ACCESS_TOKEN); StatusesUpdateChoreo.addInput("AccessTokenSecret", TWITTER_ACCESS_TOKEN_SECRET); - StatusesUpdateChoreo.addInput("ConsumerKey", TWITTER_CONSUMER_KEY); + StatusesUpdateChoreo.addInput("ConsumerKey", TWITTER_CONSUMER_KEY); StatusesUpdateChoreo.addInput("ConsumerSecret", TWITTER_CONSUMER_SECRET); // and the tweet we want to send StatusesUpdateChoreo.addInput("StatusUpdate", tweetText); - // tell the Process to run and wait for the results. The - // return code (returnCode) will tell us whether the Temboo client + // tell the Process to run and wait for the results. The + // return code (returnCode) will tell us whether the Temboo client // was able to send our request to the Temboo servers unsigned int returnCode = StatusesUpdateChoreo.run(); // a return code of zero (0) means everything worked if (returnCode == 0) { - Serial.println("Success! Tweet sent!"); + Serial.println("Success! Tweet sent!"); } else { // a non-zero return code means there was an error // read and print the error message @@ -107,7 +106,7 @@ void loop() char c = StatusesUpdateChoreo.read(); Serial.print(c); } - } + } StatusesUpdateChoreo.close(); // do nothing for the next 90 seconds @@ -124,15 +123,15 @@ void loop() by inserting your own Temboo account name and app key information. The contents of the file should look like: - #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key - You can find your Temboo App Key information on the Temboo website, + You can find your Temboo App Key information on the Temboo website, under My Account > Application Keys The same TembooAccount.h file settings can be used for all Temboo SDK sketches. - Keeping your account information in a separate file means you can share the main .ino file without worrying + Keeping your account information in a separate file means you can share the main .ino file without worrying that you forgot to delete your credentials. */ diff --git a/libraries/Bridge/examples/Temboo/SendAnEmail/SendAnEmail.ino b/libraries/Bridge/examples/Temboo/SendAnEmail/SendAnEmail.ino index bb6b09b96..e494936d5 100644 --- a/libraries/Bridge/examples/Temboo/SendAnEmail/SendAnEmail.ino +++ b/libraries/Bridge/examples/Temboo/SendAnEmail/SendAnEmail.ino @@ -5,46 +5,46 @@ Check out the latest Arduino & Temboo examples and tutorials at http://www.temboo.com/arduino - A Temboo account and application key are necessary to run all Temboo examples. - If you don't already have one, you can register for a free Temboo account at + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at http://www.temboo.com Instructions: - + 1. Create a Temboo account: http://www.temboo.com - + 2. Retrieve your Temboo application details: http://www.temboo.com/account/applications - + 3. Replace the values in the TembooAccount.h tab with your Temboo application details - - 4. You'll also need a Gmail account. Update the placeholder Gmail address in the code + + 4. You'll also need a Gmail account. Update the placeholder Gmail address in the code below with your own details. - + https://www.gmail.com - - 5. Once you have a Gmail account, turn on 2-step authentication, and create an application-specific + + 5. Once you have a Gmail account, turn on 2-step authentication, and create an application-specific password to allow Temboo to access your Google account: https://www.google.com/landing/2step/. - + 6. After you've enabled 2-Step authentication, you'll need to create an App Password: https://security.google.com/settings/security/apppasswords - + 7. In the "Select app" dropdown menu, choose "Other", and give your app a name (e.g., TembooApp). - + 8. Click "Generate". You'll be given a 16-digit passcode that can be used to access your Google Account from Temboo. - + 9. Copy and paste this password into the code below, updating the GMAIL_APP_PASSWORD variable - + 10. Upload the sketch to your Arduino Yún and open the serial monitor - - NOTE: You can test this Choreo and find the latest instructions on our website: + + NOTE: You can test this Choreo and find the latest instructions on our website: https://temboo.com/library/Library/Google/Gmail/SendEmail - + You can also find an in-depth version of this example here: https://temboo.com/arduino/yun/send-an-email This example assumes basic familiarity with Arduino sketches, and that your Yún is connected to the Internet. - + Looking for another API to use with your Arduino Yún? We've got over 100 in our Library! This example code is in the public domain. @@ -53,7 +53,7 @@ #include #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: ***/ @@ -70,32 +70,31 @@ const String GMAIL_APP_PASSWORD = "xxxxxxxxxx"; const String TO_EMAIL_ADDRESS = "xxxxxxxxxx"; // a flag to indicate whether we've tried to send the email yet or not -boolean attempted = false; +boolean attempted = false; void setup() { Serial.begin(9600); // for debugging, wait until a serial console is connected delay(4000); - while(!Serial); + while (!Serial); Bridge.begin(); } -void loop() -{ +void loop() { // only try to send the email if we haven't already tried if (!attempted) { Serial.println("Running SendAnEmail..."); - + TembooChoreo SendEmailChoreo; // invoke the Temboo client // NOTE that the client must be reinvoked, and repopulated with // appropriate arguments, each time its run() method is called. SendEmailChoreo.begin(); - + // set Temboo account credentials SendEmailChoreo.setAccountName(TEMBOO_ACCOUNT); SendEmailChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); @@ -103,13 +102,13 @@ void loop() // identify the Temboo Library choreo to run (Google > Gmail > SendEmail) SendEmailChoreo.setChoreo("/Library/Google/Gmail/SendEmail"); - + // set the required choreo inputs - // see https://www.temboo.com/library/Library/Google/Gmail/SendEmail/ + // see https://www.temboo.com/library/Library/Google/Gmail/SendEmail/ // for complete details about the inputs for this Choreo - // the first input is your Gmail email address. + // the first input is your Gmail email address. SendEmailChoreo.addInput("Username", GMAIL_USER_NAME); // next is your application specific password SendEmailChoreo.addInput("Password", GMAIL_APP_PASSWORD); @@ -118,17 +117,17 @@ void loop() // then a subject line SendEmailChoreo.addInput("Subject", "ALERT: Greenhouse Temperature"); - // next comes the message body, the main content of the email + // next comes the message body, the main content of the email SendEmailChoreo.addInput("MessageBody", "Hey! The greenhouse is too cold!"); - // tell the Choreo to run and wait for the results. The - // return code (returnCode) will tell us whether the Temboo client + // tell the Choreo to run and wait for the results. The + // return code (returnCode) will tell us whether the Temboo client // was able to send our request to the Temboo servers unsigned int returnCode = SendEmailChoreo.run(); // a return code of zero (0) means everything worked if (returnCode == 0) { - Serial.println("Success! Email sent!"); + Serial.println("Success! Email sent!"); } else { // a non-zero return code means there was an error // read and print the error message @@ -136,9 +135,9 @@ void loop() char c = SendEmailChoreo.read(); Serial.print(c); } - } + } SendEmailChoreo.close(); - + // set the flag showing we've tried attempted = true; } @@ -152,15 +151,15 @@ void loop() by inserting your own Temboo account name and app key information. The contents of the file should look like: - #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key - You can find your Temboo App Key information on the Temboo website, + You can find your Temboo App Key information on the Temboo website, under My Account > Application Keys The same TembooAccount.h file settings can be used for all Temboo SDK sketches. - Keeping your account information in a separate file means you can share the main .ino file without worrying + Keeping your account information in a separate file means you can share the main .ino file without worrying that you forgot to delete your credentials. */ diff --git a/libraries/Bridge/examples/Temboo/SendAnSMS/SendAnSMS.ino b/libraries/Bridge/examples/Temboo/SendAnSMS/SendAnSMS.ino index a2da0469c..5bc838ec7 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 Yún is connected to the Internet. Looking for another API to use with your Arduino Yún? We've got over 100 in our Library! - + This example code is in the public domain. */ #include #include #include "TembooAccount.h" // contains Temboo account information - // as described in the footer comment below +// as described in the footer comment below @@ -55,25 +55,24 @@ const String TWILIO_NUMBER = "xxxxxxxxxx"; const String RECIPIENT_NUMBER = "xxxxxxxxxx"; // a flag to indicate whether we've attempted to send the SMS yet or not -boolean attempted = false; +boolean attempted = false; void setup() { Serial.begin(9600); // for debugging, wait until a serial console is connected delay(4000); - while(!Serial); + while (!Serial); Bridge.begin(); } -void loop() -{ +void loop() { // only try to send the SMS if we haven't already sent it successfully if (!attempted) { Serial.println("Running SendAnSMS..."); - + // we need a Process object to send a Choreo request to Temboo TembooChoreo SendSMSChoreo; @@ -81,7 +80,7 @@ void loop() // NOTE that the client must be reinvoked and repopulated with // appropriate arguments each time its run() method is called. SendSMSChoreo.begin(); - + // set Temboo account credentials SendSMSChoreo.setAccountName(TEMBOO_ACCOUNT); SendSMSChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); @@ -91,32 +90,32 @@ void loop() SendSMSChoreo.setChoreo("/Library/Twilio/SMSMessages/SendSMS"); // set the required choreo inputs - // see https://www.temboo.com/library/Library/Twilio/SMSMessages/SendSMS/ + // see https://www.temboo.com/library/Library/Twilio/SMSMessages/SendSMS/ // for complete details about the inputs for this Choreo // the first input is a your AccountSID SendSMSChoreo.addInput("AccountSID", TWILIO_ACCOUNT_SID); - + // next is your Auth Token SendSMSChoreo.addInput("AuthToken", TWILIO_AUTH_TOKEN); - + // next is your Twilio phone number SendSMSChoreo.addInput("From", TWILIO_NUMBER); - + // next, what number to send the SMS to SendSMSChoreo.addInput("To", RECIPIENT_NUMBER); // finally, the text of the message to send SendSMSChoreo.addInput("Body", "Hey, there! This is a message from your Arduino Yun!"); - - // tell the Process to run and wait for the results. The - // return code (returnCode) will tell us whether the Temboo client + + // tell the Process to run and wait for the results. The + // return code (returnCode) will tell us whether the Temboo client // was able to send our request to the Temboo servers unsigned int returnCode = SendSMSChoreo.run(); // a return code of zero (0) means everything worked if (returnCode == 0) { - Serial.println("Success! SMS sent!"); + Serial.println("Success! SMS sent!"); } else { // a non-zero return code means there was an error // read and print the error message @@ -124,11 +123,11 @@ void loop() char c = SendSMSChoreo.read(); Serial.print(c); } - } + } SendSMSChoreo.close(); - + // set the flag indicatine we've tried once. - attempted=true; + attempted = true; } } @@ -140,15 +139,15 @@ void loop() by inserting your own Temboo account name and app key information. The contents of the file should look like: - #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key - You can find your Temboo App Key information on the Temboo website, + You can find your Temboo App Key information on the Temboo website, under My Account > Application Keys The same TembooAccount.h file settings can be used for all Temboo SDK sketches. - Keeping your account information in a separate file means you can share the main .ino file without worrying + Keeping your account information in a separate file means you can share the main .ino file without worrying that you forgot to delete your credentials. */ diff --git a/libraries/Bridge/examples/Temboo/SendDataToGoogleSpreadsheet/SendDataToGoogleSpreadsheet.ino b/libraries/Bridge/examples/Temboo/SendDataToGoogleSpreadsheet/SendDataToGoogleSpreadsheet.ino index 6bae2796e..f07b09478 100644 --- a/libraries/Bridge/examples/Temboo/SendDataToGoogleSpreadsheet/SendDataToGoogleSpreadsheet.ino +++ b/libraries/Bridge/examples/Temboo/SendDataToGoogleSpreadsheet/SendDataToGoogleSpreadsheet.ino @@ -5,48 +5,48 @@ Check out the latest Arduino & Temboo examples and tutorials at http://www.temboo.com/arduino - A Temboo account and application key are necessary to run all Temboo examples. - If you don't already have one, you can register for a free Temboo account at + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at http://www.temboo.com Instructions: - + 1. Create a Temboo account: http://www.temboo.com - + 2. Retrieve your Temboo application details: http://www.temboo.com/account/applications - + 3. Replace the values in the TembooAccount.h tab with your Temboo application details - - 4. You'll also need a Google Spreadsheet that includes a title in the first row - of each column that data will be written to. This example assumes there are two columns. - The first column is the time (in milliseconds) that the row was appended, and the second + + 4. You'll also need a Google Spreadsheet that includes a title in the first row + of each column that data will be written to. This example assumes there are two columns. + The first column is the time (in milliseconds) that the row was appended, and the second column is a sensor value. In other words, your spreadsheet should look like: - - Time | Sensor Value | + + Time | Sensor Value | ------+----------------- - | | - + | | + 5. Google Spreadsheets requires you to authenticate via OAuth. Follow the steps - in the link below to find your ClientID, ClientSecret, and RefreshToken, and then - use those values to overwrite the placeholders in the code below. - + in the link below to find your ClientID, ClientSecret, and RefreshToken, and then + use those values to overwrite the placeholders in the code below. + https://temboo.com/library/Library/Google/OAuth/ - + For the scope field, you need to use: https://spreadsheets.google.com/feeds/ - - Here's a video outlines how Temboo helps with the OAuth process: - + + Here's a video outlines how Temboo helps with the OAuth process: + https://www.temboo.com/videos#oauthchoreos - - And here's a more in-depth version of this example on our website: - + + And here's a more in-depth version of this example on our website: + https://temboo.com/arduino/yun/update-google-spreadsheet - + 6. Next, upload the sketch to your Arduino Yún and open the serial monitor - + Note: you can test this Choreo and find the latest instructions on our website: https://temboo.com/library/Library/Google/Spreadsheets/AppendRow/ - + Looking for another API to use with your Arduino Yún? We've got over 100 in our Library! This example code is in the public domain. @@ -56,7 +56,7 @@ #include #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: ***/ @@ -81,25 +81,24 @@ const String SPREADSHEET_TITLE = "your-spreadsheet-title"; const unsigned long RUN_INTERVAL_MILLIS = 60000; // how often to run the Choreo (in milliseconds) -// the last time we ran the Choreo +// the last time we ran the Choreo // (initialized to 60 seconds ago so the // Choreo is run immediately when we start up) -unsigned long lastRun = (unsigned long)-60000; +unsigned long lastRun = (unsigned long) - 60000; void setup() { - + // for debugging, wait until a serial console is connected Serial.begin(9600); delay(4000); - while(!Serial); + while (!Serial); Serial.print("Initializing the bridge..."); Bridge.begin(); Serial.println("Done"); } -void loop() -{ +void loop() { // get the number of milliseconds this sketch has been running unsigned long now = millis(); @@ -108,7 +107,7 @@ void loop() // remember 'now' as the last time we ran the choreo lastRun = now; - + Serial.println("Getting sensor value..."); // get the value we want to append to our spreadsheet @@ -123,19 +122,19 @@ void loop() // NOTE that the client must be reinvoked and repopulated with // appropriate arguments each time its run() method is called. AppendRowChoreo.begin(); - + // set Temboo account credentials AppendRowChoreo.setAccountName(TEMBOO_ACCOUNT); AppendRowChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); AppendRowChoreo.setAppKey(TEMBOO_APP_KEY); - + // identify the Temboo Library choreo to run (Google > Spreadsheets > AppendRow) AppendRowChoreo.setChoreo("/Library/Google/Spreadsheets/AppendRow"); - + // set the required Choreo inputs - // see https://www.temboo.com/library/Library/Google/Spreadsheets/AppendRow/ + // see https://www.temboo.com/library/Library/Google/Spreadsheets/AppendRow/ // for complete details about the inputs for this Choreo - + // your Google application client ID AppendRowChoreo.addInput("ClientID", CLIENT_ID); // your Google application client secert @@ -156,7 +155,7 @@ void loop() AppendRowChoreo.addInput("RowData", rowData); // run the Choreo and wait for the results - // The return code (returnCode) will indicate success or failure + // The return code (returnCode) will indicate success or failure unsigned int returnCode = AppendRowChoreo.run(); // return code of zero (0) means success @@ -164,7 +163,7 @@ void loop() Serial.println("Success! Appended " + rowData); Serial.println(""); } else { - // return code of anything other than zero means failure + // return code of anything other than zero means failure // read and display any error messages while (AppendRowChoreo.available()) { char c = AppendRowChoreo.read(); @@ -176,7 +175,7 @@ void loop() } } -// this function simulates reading the value of a sensor +// this function simulates reading the value of a sensor unsigned long getSensorValue() { return analogRead(A0); } @@ -189,15 +188,15 @@ unsigned long getSensorValue() { by inserting your own Temboo account name and app key information. The contents of the file should look like: - #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key - You can find your Temboo App Key information on the Temboo website, + You can find your Temboo App Key information on the Temboo website, under My Account > Application Keys The same TembooAccount.h file settings can be used for all Temboo SDK sketches. - Keeping your account information in a separate file means you can share the main .ino file without worrying + Keeping your account information in a separate file means you can share the main .ino file without worrying that you forgot to delete your credentials. */ diff --git a/libraries/Bridge/examples/Temboo/ToxicFacilitiesSearch/ToxicFacilitiesSearch.ino b/libraries/Bridge/examples/Temboo/ToxicFacilitiesSearch/ToxicFacilitiesSearch.ino index 86d0be5c1..4708dac4d 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 Yún. - This example retrieves the names and addresses of EPA-regulated facilities in the + This example retrieves the names and addresses of EPA-regulated facilities in the Toxins Release Inventory (TRI) database within a given zip code. - + Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino - A Temboo account and application key are necessary to run all Temboo examples. - If you don't already have one, you can register for a free Temboo account at + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at http://www.temboo.com - + This example assumes basic familiarity with Arduino sketches, and that your Yún is connected to the Internet. Looking for another API to use with your Arduino Yún? We've got over 100 in our Library! - + This example code is in the public domain. */ #include #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,18 +32,17 @@ int maxRuns = 10; // max number of times the Envirofacts FacilitiesSearch Chore void setup() { Serial.begin(9600); - + // for debugging, wait until a serial console is connected delay(4000); - while(!Serial); + while (!Serial); Bridge.begin(); } -void loop() -{ +void loop() { // while we haven't reached the max number of runs... if (numRuns <= maxRuns) { - + // print status Serial.println("Running ToxicFacilitiesSearch - Run #" + String(numRuns++) + "..."); @@ -54,26 +53,26 @@ void loop() // NOTE that the client must be reinvoked and repopulated with // appropriate arguments each time its run() method is called. FacilitiesSearchByZipChoreo.begin(); - + // set Temboo account credentials FacilitiesSearchByZipChoreo.setAccountName(TEMBOO_ACCOUNT); FacilitiesSearchByZipChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); FacilitiesSearchByZipChoreo.setAppKey(TEMBOO_APP_KEY); - + // identify the Temboo Library choreo to run (EnviroFacts > Toxins > FacilitiesSearchByZip) FacilitiesSearchByZipChoreo.setChoreo("/Library/EnviroFacts/Toxins/FacilitiesSearchByZip"); - + // set choreo inputs; in this case, the US zip code for which to retrieve toxin release data // the Temboo client provides standardized calls to 100+ cloud APIs FacilitiesSearchByZipChoreo.addInput("Zip", US_ZIP_CODE); - + // specify two output filters, to help simplify the Envirofacts API results. // see the tutorials on using Temboo SDK output filters at http://www.temboo.com/arduino FacilitiesSearchByZipChoreo.addOutputFilter("fac", "FACILITY_NAME", "Response"); FacilitiesSearchByZipChoreo.addOutputFilter("addr", "STREET_ADDRESS", "Response"); - // run the choreo + // run the choreo unsigned int returnCode = FacilitiesSearchByZipChoreo.run(); if (returnCode == 0) { String facilities; @@ -83,7 +82,7 @@ void loop() // the output filters we specified will return comma delimited // lists containing the name and street address of the facilities // located in the specified zip code. - while(FacilitiesSearchByZipChoreo.available()) { + while (FacilitiesSearchByZipChoreo.available()) { String name = FacilitiesSearchByZipChoreo.readStringUntil('\x1F'); name.trim(); @@ -97,8 +96,8 @@ void loop() } } FacilitiesSearchByZipChoreo.close(); - - // parse the comma delimited lists of facilities to join the + + // parse the comma delimited lists of facilities to join the // name with the address and print it to the serial monitor if (facilities.length() > 0) { int i = -1; @@ -118,12 +117,12 @@ void loop() address = addresses.substring(addressStart, i); addressStart = i + 1; } - + if (i >= 0) { printResult(facility, address); } - }while (i >= 0); + } while (i >= 0); facility = facilities.substring(facilityStart); address = addresses.substring(addressStart); printResult(facility, address); @@ -131,7 +130,7 @@ void loop() Serial.println("No facilities found in zip code " + US_ZIP_CODE); } } else { - while(FacilitiesSearchByZipChoreo.available()) { + while (FacilitiesSearchByZipChoreo.available()) { char c = FacilitiesSearchByZipChoreo.read(); Serial.print(c); } @@ -157,15 +156,15 @@ void printResult(String facility, String address) { by inserting your own Temboo account name and app key information. The contents of the file should look like: - #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key - You can find your Temboo App Key information on the Temboo website, + You can find your Temboo App Key information on the Temboo website, under My Account > Application Keys The same TembooAccount.h file settings can be used for all Temboo SDK sketches. - Keeping your account information in a separate file means you can share the main .ino file without worrying + Keeping your account information in a separate file means you can share the main .ino file without worrying that you forgot to delete your credentials. */ diff --git a/libraries/Bridge/examples/Temboo/UpdateFacebookStatus/UpdateFacebookStatus.ino b/libraries/Bridge/examples/Temboo/UpdateFacebookStatus/UpdateFacebookStatus.ino index eec3620ae..8de806b46 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 Yún. Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino - - A Temboo account and application key are necessary to run all Temboo examples. - If you don't already have one, you can register for a free Temboo account at + + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at http://www.temboo.com In order to run this sketch, you'll need to register an application using @@ -17,17 +17,17 @@ This example assumes basic familiarity with Arduino sketches, and that your Yún is connected to the Internet. - + Want to use another social API with your Arduino Yún? We've got Twitter, Google+, Instagram, Tumblr and more in our Library! - This example code is in the public domain. + This example code is in the public domain. */ #include #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 1092e8e4d..7bc0fb0c8 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 Yún. - + Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino - A Temboo account and application key are necessary to run all Temboo examples. - If you don't already have one, you can register for a free Temboo account at + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at http://www.temboo.com - You'll also need a valid Dropbox app and accompanying OAuth credentials. - To create a Dropbox app, visit https://www.dropbox.com/developers/apps and + You'll also need a valid Dropbox app and accompanying OAuth credentials. + To create a Dropbox app, visit https://www.dropbox.com/developers/apps and do the following: - + 1. Create a "Dropbox API app" 2. Select "Files and datastores" 3. Select "Yes - my app only needs access to the files it creates." - - Once you've created your app, follow the instructions at + + Once you've created your app, follow the instructions at https://www.temboo.com/library/Library/Dropbox/OAuth/ to run the Initialize and Finalize OAuth Choreos. These Choreos complete the OAuth handshake and retrieve your Dropbox OAuth access tokens. @@ -25,14 +25,14 @@ to the Internet. Looking for another API to use with your Arduino Yún? We've got over 100 in our Library! - + This example code is in the public domain. */ #include #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,34 +57,33 @@ boolean success = false; // a flag to indicate whether we've uploaded the file y void setup() { Serial.begin(9600); - + // For debugging, wait until a serial console is connected. delay(4000); - while(!Serial); + while (!Serial); Bridge.begin(); } -void loop() -{ +void loop() { // only try to upload the file if we haven't already done so if (!success) { - + Serial.println("Base64 encoding data to upload..."); - + // base64 encode the data to upload String base64EncodedData = base64Encode("Hello, Arduino!"); Serial.println("Uploading data to Dropbox..."); - // we need a Process object to send a Choreo request to Temboo + // we need a Process object to send a Choreo request to Temboo TembooChoreo UploadFileChoreo; // invoke the Temboo client // NOTE that the client must be reinvoked and repopulated with // appropriate arguments each time its run() method is called. UploadFileChoreo.begin(); - + // set Temboo account credentials UploadFileChoreo.setAccountName(TEMBOO_ACCOUNT); UploadFileChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); @@ -92,7 +91,7 @@ void loop() // identify the Temboo Library choreo to run (Dropbox > FilesAndMetadata > UploadFile) UploadFileChoreo.setChoreo("/Library/Dropbox/FilesAndMetadata/UploadFile"); - + // set the required choreo inputs // see https://www.temboo.com/library/Library/Dropbox/FilesAndMetadata/UploadFile/ // for complete details about the inputs for this Choreo @@ -103,31 +102,31 @@ void loop() // next, the root folder on Dropbox relative to which the file path is specified. // to work with the Dropbox app you created earlier, this should be left as "sandbox" // if your Dropbox app has full access to your files, specify "dropbox" - UploadFileChoreo.addInput("Root","sandbox"); + UploadFileChoreo.addInput("Root", "sandbox"); // next, the Base64 encoded file data to upload UploadFileChoreo.addInput("FileContents", base64EncodedData); - + // finally, the Dropbox OAuth credentials defined above UploadFileChoreo.addInput("AppSecret", DROPBOX_APP_SECRET); UploadFileChoreo.addInput("AccessToken", DROPBOX_ACCESS_TOKEN); UploadFileChoreo.addInput("AccessTokenSecret", DROPBOX_ACCESS_TOKEN_SECRET); UploadFileChoreo.addInput("AppKey", DROPBOX_APP_KEY); - // tell the Process to run and wait for the results. The - // return code (returnCode) will tell us whether the Temboo client + // tell the Process to run and wait for the results. The + // return code (returnCode) will tell us whether the Temboo client // was able to send our request to the Temboo servers unsigned int returnCode = UploadFileChoreo.run(); // a return code of zero (0) means everything worked if (returnCode == 0) { - Serial.println("Success! File uploaded!"); - success = true; + Serial.println("Success! File uploaded!"); + success = true; } else { // a non-zero return code means there was an error Serial.println("Uh-oh! Something went wrong!"); } - + // print out the full response to the serial monitor in all // cases, just for debugging while (UploadFileChoreo.available()) { @@ -148,42 +147,42 @@ void loop() by calling a Temboo Utilities Choreo. */ String base64Encode(String toEncode) { - - // we need a Process object to send a Choreo request to Temboo - TembooChoreo Base64EncodeChoreo; - // invoke the Temboo client - Base64EncodeChoreo.begin(); - - // set Temboo account credentials - Base64EncodeChoreo.setAccountName(TEMBOO_ACCOUNT); - Base64EncodeChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); - Base64EncodeChoreo.setAppKey(TEMBOO_APP_KEY); + // we need a Process object to send a Choreo request to Temboo + TembooChoreo Base64EncodeChoreo; - // identify the Temboo Library choreo to run (Utilities > Encoding > Base64Encode) - Base64EncodeChoreo.setChoreo("/Library/Utilities/Encoding/Base64Encode"); - - // set choreo inputs - Base64EncodeChoreo.addInput("Text", toEncode); - - // run the choreo - Base64EncodeChoreo.run(); - - // read in the choreo results, and return the "Base64EncodedText" output value. - // see http://www.temboo.com/arduino for more details on using choreo outputs. - while(Base64EncodeChoreo.available()) { - // read the name of the output item - String name = Base64EncodeChoreo.readStringUntil('\x1F'); - name.trim(); + // invoke the Temboo client + Base64EncodeChoreo.begin(); - // read the value of the output item - String data = Base64EncodeChoreo.readStringUntil('\x1E'); - data.trim(); + // set Temboo account credentials + Base64EncodeChoreo.setAccountName(TEMBOO_ACCOUNT); + Base64EncodeChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); + Base64EncodeChoreo.setAppKey(TEMBOO_APP_KEY); - if(name == "Base64EncodedText") { - return data; - } + // identify the Temboo Library choreo to run (Utilities > Encoding > Base64Encode) + Base64EncodeChoreo.setChoreo("/Library/Utilities/Encoding/Base64Encode"); + + // set choreo inputs + Base64EncodeChoreo.addInput("Text", toEncode); + + // run the choreo + Base64EncodeChoreo.run(); + + // read in the choreo results, and return the "Base64EncodedText" output value. + // see http://www.temboo.com/arduino for more details on using choreo outputs. + while (Base64EncodeChoreo.available()) { + // read the name of the output item + String name = Base64EncodeChoreo.readStringUntil('\x1F'); + name.trim(); + + // read the value of the output item + String data = Base64EncodeChoreo.readStringUntil('\x1E'); + data.trim(); + + if (name == "Base64EncodedText") { + return data; } + } } /* @@ -194,15 +193,15 @@ String base64Encode(String toEncode) { by inserting your own Temboo account name and app key information. The contents of the file should look like: - #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key - You can find your Temboo App Key information on the Temboo website, + You can find your Temboo App Key information on the Temboo website, under My Account > Application Keys The same TembooAccount.h file settings can be used for all Temboo SDK sketches. - Keeping your account information in a separate file means you can share the main .ino file without worrying + Keeping your account information in a separate file means you can share the main .ino file without worrying that you forgot to delete your credentials. */ diff --git a/libraries/Bridge/examples/TimeCheck/TimeCheck.ino b/libraries/Bridge/examples/TimeCheck/TimeCheck.ino index f31b2b0d0..fcb2d50e4 100644 --- a/libraries/Bridge/examples/TimeCheck/TimeCheck.ino +++ b/libraries/Bridge/examples/TimeCheck/TimeCheck.ino @@ -41,13 +41,19 @@ void loop() { if (lastSecond != seconds) { // if a second has passed // print the time: - if (hours <= 9) Serial.print("0"); // adjust for 0-9 + if (hours <= 9) { + Serial.print("0"); // adjust for 0-9 + } Serial.print(hours); Serial.print(":"); - if (minutes <= 9) Serial.print("0"); // adjust for 0-9 + if (minutes <= 9) { + Serial.print("0"); // adjust for 0-9 + } Serial.print(minutes); Serial.print(":"); - if (seconds <= 9) Serial.print("0"); // adjust for 0-9 + if (seconds <= 9) { + Serial.print("0"); // adjust for 0-9 + } Serial.println(seconds); // restart the date process: diff --git a/libraries/Bridge/examples/YunSerialTerminal/YunSerialTerminal.ino b/libraries/Bridge/examples/YunSerialTerminal/YunSerialTerminal.ino index 91b911b65..ca427e192 100644 --- a/libraries/Bridge/examples/YunSerialTerminal/YunSerialTerminal.ino +++ b/libraries/Bridge/examples/YunSerialTerminal/YunSerialTerminal.ino @@ -1,35 +1,35 @@ /* Arduino Yún USB-to-Serial - Allows you to use the Yún's 32U4 processor as a - serial terminal for the Linux side on the Yún. + Allows you to use the Yún's 32U4 processor as a + serial terminal for the Linux side on the Yún. - Upload this to an Arduino Yún via serial (not WiFi) then open - the serial monitor at 115200 to see the boot process of Linux. - You can also use the serial monitor as a basic command line - interface for Linux using this sketch. + Upload this to an Arduino Yún via serial (not WiFi) then open + the serial monitor at 115200 to see the boot process of Linux. + You can also use the serial monitor as a basic command line + interface for Linux using this sketch. - From the serial monitor the following commands can be issued: + From the serial monitor the following commands can be issued: - '~' followed by '0' -> Set the UART speed to 57600 baud - '~' followed by '1' -> Set the UART speed to 115200 baud - '~' followed by '2' -> Set the UART speed to 250000 baud - '~' followed by '3' -> Set the UART speed to 500000 baud - '~' followed by '~' -> Sends the bridge's shutdown command to + '~' followed by '0' -> Set the UART speed to 57600 baud + '~' followed by '1' -> Set the UART speed to 115200 baud + '~' followed by '2' -> Set the UART speed to 250000 baud + '~' followed by '3' -> Set the UART speed to 500000 baud + '~' followed by '~' -> Sends the bridge's shutdown command to obtain the console. - The circuit: - * Arduino Yún + The circuit: + Arduino Yún - created March 2013 - by Massimo Banzi - modified by Cristian Maglie + created March 2013 + by Massimo Banzi + modified by Cristian Maglie - This example code is in the public domain. + This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/YunSerialTerminal + http://www.arduino.cc/en/Tutorial/YunSerialTerminal - */ +*/ long linuxBaud = 250000; @@ -65,8 +65,7 @@ void loop() { Serial1.begin(500000); // set speed to 500000 Serial.println("Speed set to 500000"); } else if (c == '~') { // '~` key pressed? - // send "bridge shutdown" command - Serial1.write((uint8_t *)"\xff\0\0\x05XXXXX\x7f\xf9", 11); + Serial1.write((uint8_t *)"\xff\0\0\x05XXXXX\x7f\xf9", 11); // send "bridge shutdown" command Serial.println("Sending bridge's shutdown command"); } else { // any other key pressed? Serial1.write('~'); // write '~' to UART diff --git a/libraries/Esplora/examples/Beginners/EsploraAccelerometer/EsploraAccelerometer.ino b/libraries/Esplora/examples/Beginners/EsploraAccelerometer/EsploraAccelerometer.ino index cb929af36..ffb24b5dc 100644 --- a/libraries/Esplora/examples/Beginners/EsploraAccelerometer/EsploraAccelerometer.ino +++ b/libraries/Esplora/examples/Beginners/EsploraAccelerometer/EsploraAccelerometer.ino @@ -14,13 +14,11 @@ #include -void setup() -{ +void setup() { Serial.begin(9600); // initialize serial communications with your computer } -void loop() -{ +void loop() { int xAxis = Esplora.readAccelerometer(X_AXIS); // read the X axis int yAxis = Esplora.readAccelerometer(Y_AXIS); // read the Y axis int zAxis = Esplora.readAccelerometer(Z_AXIS); // read the Z axis diff --git a/libraries/Esplora/examples/Beginners/EsploraJoystickMouse/EsploraJoystickMouse.ino b/libraries/Esplora/examples/Beginners/EsploraJoystickMouse/EsploraJoystickMouse.ino index 197f8fcad..626e1475f 100644 --- a/libraries/Esplora/examples/Beginners/EsploraJoystickMouse/EsploraJoystickMouse.ino +++ b/libraries/Esplora/examples/Beginners/EsploraJoystickMouse/EsploraJoystickMouse.ino @@ -19,7 +19,7 @@ by Tom Igoe Updated 8 March 2014 by Scott Fitzgerald - + http://www.arduino.cc/en/Reference/EsploraReadJoystickSwitch This example is in the public domain. @@ -27,14 +27,12 @@ #include -void setup() -{ +void setup() { Serial.begin(9600); // initialize serial communication with your computer Mouse.begin(); // take control of the mouse } -void loop() -{ +void loop() { int xValue = Esplora.readJoystickX(); // read the joystick's X position int yValue = Esplora.readJoystickY(); // read the joystick's Y position int button = Esplora.readJoystickSwitch(); // read the joystick pushbutton @@ -52,7 +50,7 @@ void loop() if (button == 0) { // if the joystick button is pressed Mouse.press(); // send a mouse click } else { - Mouse.release(); // if it's not pressed, release the mouse button + Mouse.release(); // if it's not pressed, release the mouse button } delay(10); // a short delay before moving again diff --git a/libraries/Esplora/examples/Beginners/EsploraMusic/EsploraMusic.ino b/libraries/Esplora/examples/Beginners/EsploraMusic/EsploraMusic.ino index 82d592a7d..464a85e76 100644 --- a/libraries/Esplora/examples/Beginners/EsploraMusic/EsploraMusic.ino +++ b/libraries/Esplora/examples/Beginners/EsploraMusic/EsploraMusic.ino @@ -45,8 +45,7 @@ void loop() { byte thisNote = map(slider, 0, 1023, 0, 13); // play the note corresponding to the slider's position: Esplora.tone(note[thisNote]); - } - else { + } else { // if the button isn't pressed, turn the note off: Esplora.noTone(); } diff --git a/libraries/Esplora/examples/Beginners/EsploraTemperatureSensor/EsploraTemperatureSensor.ino b/libraries/Esplora/examples/Beginners/EsploraTemperatureSensor/EsploraTemperatureSensor.ino index 68aef5173..1db67699a 100644 --- a/libraries/Esplora/examples/Beginners/EsploraTemperatureSensor/EsploraTemperatureSensor.ino +++ b/libraries/Esplora/examples/Beginners/EsploraTemperatureSensor/EsploraTemperatureSensor.ino @@ -11,13 +11,11 @@ */ #include -void setup() -{ +void setup() { Serial.begin(9600); // initialize serial communications with your computer } -void loop() -{ +void loop() { // read the temperature sensor in Celsius, then Fahrenheit: int celsius = Esplora.readTemperature(DEGREES_C); int fahrenheit = Esplora.readTemperature(DEGREES_F); diff --git a/libraries/Esplora/examples/Experts/EsploraKart/EsploraKart.ino b/libraries/Esplora/examples/Experts/EsploraKart/EsploraKart.ino index 38e99af26..106caedf3 100644 --- a/libraries/Esplora/examples/Experts/EsploraKart/EsploraKart.ino +++ b/libraries/Esplora/examples/Experts/EsploraKart/EsploraKart.ino @@ -103,8 +103,7 @@ void loop() { */ if (newState == PRESSED) { Keyboard.press(keystrokes[thisButton]); - } - else if (newState == RELEASED) { + } else if (newState == RELEASED) { Keyboard.release(keystrokes[thisButton]); } } diff --git a/libraries/Esplora/examples/Experts/EsploraRemote/EsploraRemote.ino b/libraries/Esplora/examples/Experts/EsploraRemote/EsploraRemote.ino index f70aec49a..991821463 100644 --- a/libraries/Esplora/examples/Experts/EsploraRemote/EsploraRemote.ino +++ b/libraries/Esplora/examples/Experts/EsploraRemote/EsploraRemote.ino @@ -37,8 +37,9 @@ void setup() { } void loop() { - if (Serial.available()) + if (Serial.available()) { parseCommand(); + } } /* diff --git a/libraries/Esplora/examples/Experts/EsploraTable/EsploraTable.ino b/libraries/Esplora/examples/Experts/EsploraTable/EsploraTable.ino index e2983ff5d..7ac1578e9 100644 --- a/libraries/Esplora/examples/Experts/EsploraTable/EsploraTable.ino +++ b/libraries/Esplora/examples/Experts/EsploraTable/EsploraTable.ino @@ -114,17 +114,19 @@ void loop() { // let the RGB led blink green once per second, for 200ms. unsigned int ms = millis() % 1000; - if (ms < 200) + if (ms < 200) { Esplora.writeGreen(50); - else + } else { Esplora.writeGreen(0); + } Esplora.writeBlue(0); - } - else + } else // while not active, keep a reassuring blue color coming // from the Esplora... + { Esplora.writeBlue(20); + } } @@ -203,8 +205,9 @@ void checkSwitchPress() { if (startBtn != lastStartBtn) { if (startBtn == HIGH) { // button released active = !active; - if (active) + if (active) { justActivated = true; + } } lastStartBtn = startBtn; diff --git a/libraries/Ethernet/examples/AdvancedChatServer/AdvancedChatServer.ino b/libraries/Ethernet/examples/AdvancedChatServer/AdvancedChatServer.ino index 6fa2787e0..1c7ec4cab 100644 --- a/libraries/Ethernet/examples/AdvancedChatServer/AdvancedChatServer.ino +++ b/libraries/Ethernet/examples/AdvancedChatServer/AdvancedChatServer.ino @@ -1,7 +1,7 @@ /* Advanced Chat Server - A more advanced server that distributes any incoming messages + A more advanced server that distributes any incoming messages to all connected clients but the client the message comes from. To use telnet to your device's IP address and type. You can see the client's input in the serial monitor as well. @@ -26,10 +26,11 @@ // Enter a MAC address and IP address for your controller below. // The IP address will be dependent on your local network. // gateway and subnet are optional: -byte mac[] = { - 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; -IPAddress ip(192,168,1, 177); -IPAddress gateway(192,168,1, 1); +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; +IPAddress ip(192, 168, 1, 177); +IPAddress gateway(192, 168, 1, 1); IPAddress subnet(255, 255, 0, 0); @@ -43,9 +44,9 @@ void setup() { Ethernet.begin(mac, ip, gateway, subnet); // start listening for clients server.begin(); - // Open serial communications and wait for port to open: + // Open serial communications and wait for port to open: Serial.begin(9600); - while (!Serial) { + while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } @@ -62,9 +63,9 @@ void loop() { if (client) { boolean newClient = true; - for (byte i=0;i<4;i++) { + for (byte i = 0; i < 4; i++) { //check whether this client refers to the same socket as one of the existing instances: - if (clients[i]==client) { + if (clients[i] == client) { newClient = false; break; } @@ -72,8 +73,8 @@ void loop() { if (newClient) { //check which of the existing clients can be overridden: - for (byte i=0;i<4;i++) { - if (!clients[i] && clients[i]!=client) { + for (byte i = 0; i < 4; i++) { + if (!clients[i] && clients[i] != client) { clients[i] = client; // clead out the input buffer: client.flush(); @@ -90,8 +91,8 @@ void loop() { // read the bytes incoming from the client: char thisChar = client.read(); // echo the bytes back to all other connected clients: - for (byte i=0;i<4;i++) { - if (clients[i] && (clients[i]!=client)) { + for (byte i = 0; i < 4; i++) { + if (clients[i] && (clients[i] != client)) { clients[i].write(thisChar); } } @@ -99,7 +100,7 @@ void loop() { Serial.write(thisChar); } } - for (byte i=0;i<4;i++) { + for (byte i = 0; i < 4; i++) { if (!(clients[i].connected())) { // client.stop() invalidates the internal socket-descriptor, so next use of == will allways return false; clients[i].stop(); diff --git a/libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino b/libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino index 2c85ddd78..f7439a039 100644 --- a/libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino +++ b/libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino @@ -156,8 +156,7 @@ void listenForEthernetClients() { if (c == '\n') { // you're starting a new line currentLineIsBlank = true; - } - else if (c != '\r') { + } else if (c != '\r') { // you've gotten a character on the current line currentLineIsBlank = false; } @@ -219,5 +218,5 @@ unsigned int readRegister(byte registerName, int numBytes) { // take the chip select high to de-select: digitalWrite(chipSelectPin, HIGH); // return the result: - return(result); + return (result); } diff --git a/libraries/Ethernet/examples/TelnetClient/TelnetClient.ino b/libraries/Ethernet/examples/TelnetClient/TelnetClient.ino index dcf3e8aa9..e663e01a8 100644 --- a/libraries/Ethernet/examples/TelnetClient/TelnetClient.ino +++ b/libraries/Ethernet/examples/TelnetClient/TelnetClient.ino @@ -54,15 +54,13 @@ void setup() { // if you get a connection, report back via serial: if (client.connect(server, 10002)) { Serial.println("connected"); - } - else { + } else { // if you didn't get a connection to the server: Serial.println("connection failed"); } } -void loop() -{ +void loop() { // if there are incoming bytes available // from the server, read them and print them: if (client.available()) { diff --git a/libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino b/libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino index 99de7650c..c38b05eb7 100644 --- a/libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino +++ b/libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino @@ -45,17 +45,14 @@ void setup() { void loop() { // if there's data available, read a packet int packetSize = Udp.parsePacket(); - if (packetSize) - { + if (packetSize) { Serial.print("Received packet of size "); Serial.println(packetSize); Serial.print("From "); IPAddress remote = Udp.remoteIP(); - for (int i = 0; i < 4; i++) - { + for (int i = 0; i < 4; i++) { Serial.print(remote[i], DEC); - if (i < 3) - { + if (i < 3) { Serial.print("."); } } diff --git a/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino b/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino index 25c71c402..641ebf02c 100644 --- a/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino +++ b/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino @@ -37,8 +37,7 @@ byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing pack // A UDP instance to let us send and receive packets over UDP EthernetUDP Udp; -void setup() -{ +void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { @@ -56,13 +55,12 @@ void setup() Udp.begin(localPort); } -void loop() -{ +void loop() { sendNTPpacket(timeServer); // send an NTP packet to a time server // wait to see if a reply is available delay(1000); - if ( Udp.parsePacket() ) { + if (Udp.parsePacket()) { // We've received a packet, read the data from it Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer @@ -74,7 +72,7 @@ void loop() // combine the four bytes (two words) into a long integer // this is NTP time (seconds since Jan 1 1900): unsigned long secsSince1900 = highWord << 16 | lowWord; - Serial.print("Seconds since Jan 1 1900 = " ); + Serial.print("Seconds since Jan 1 1900 = "); Serial.println(secsSince1900); // now convert NTP time into everyday time: @@ -91,13 +89,13 @@ void loop() Serial.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT) Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day) Serial.print(':'); - if ( ((epoch % 3600) / 60) < 10 ) { + if (((epoch % 3600) / 60) < 10) { // In the first 10 minutes of each hour, we'll want a leading '0' Serial.print('0'); } Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute) Serial.print(':'); - if ( (epoch % 60) < 10 ) { + if ((epoch % 60) < 10) { // In the first 10 seconds of each minute, we'll want a leading '0' Serial.print('0'); } @@ -108,8 +106,7 @@ void loop() } // send an NTP request to the time server at the given address -unsigned long sendNTPpacket(char* address) -{ +unsigned long sendNTPpacket(char* address) { // set all bytes in the buffer to 0 memset(packetBuffer, 0, NTP_PACKET_SIZE); // Initialize values needed to form NTP request diff --git a/libraries/Ethernet/examples/WebClient/WebClient.ino b/libraries/Ethernet/examples/WebClient/WebClient.ino index 9afd40eae..16c7ec42e 100644 --- a/libraries/Ethernet/examples/WebClient/WebClient.ino +++ b/libraries/Ethernet/examples/WebClient/WebClient.ino @@ -59,15 +59,13 @@ void setup() { client.println("Host: www.google.com"); client.println("Connection: close"); client.println(); - } - else { + } else { // kf you didn't get a connection to the server: Serial.println("connection failed"); } } -void loop() -{ +void loop() { // if there are incoming bytes available // from the server, read them and print them: if (client.available()) { diff --git a/libraries/Ethernet/examples/WebClientRepeating/WebClientRepeating.ino b/libraries/Ethernet/examples/WebClientRepeating/WebClientRepeating.ino index ad3f461c2..f4917d4b9 100644 --- a/libraries/Ethernet/examples/WebClientRepeating/WebClientRepeating.ino +++ b/libraries/Ethernet/examples/WebClientRepeating/WebClientRepeating.ino @@ -98,8 +98,7 @@ void httpRequest() { // note the time that the connection was made: lastConnectionTime = millis(); - } - else { + } else { // if you couldn't make a connection: Serial.println("connection failed"); } diff --git a/libraries/Ethernet/examples/WebServer/WebServer.ino b/libraries/Ethernet/examples/WebServer/WebServer.ino index d0c585d07..4a483af57 100644 --- a/libraries/Ethernet/examples/WebServer/WebServer.ino +++ b/libraries/Ethernet/examples/WebServer/WebServer.ino @@ -84,8 +84,7 @@ void loop() { if (c == '\n') { // you're starting a new line currentLineIsBlank = true; - } - else if (c != '\r') { + } else if (c != '\r') { // you've gotten a character on the current line currentLineIsBlank = false; } diff --git a/libraries/GSM/examples/GsmWebClient/GsmWebClient.ino b/libraries/GSM/examples/GsmWebClient/GsmWebClient.ino index 6deaba0e1..b471582e5 100644 --- a/libraries/GSM/examples/GsmWebClient/GsmWebClient.ino +++ b/libraries/GSM/examples/GsmWebClient/GsmWebClient.ino @@ -37,8 +37,7 @@ char server[] = "arduino.cc"; char path[] = "/asciilogo.txt"; int port = 80; // port 80 is the default for HTTP -void setup() -{ +void setup() { // initialize serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { @@ -51,13 +50,11 @@ void setup() // After starting the modem with GSM.begin() // attach the shield to the GPRS network with the APN, login and password - while (notConnected) - { + while (notConnected) { if ((gsmAccess.begin(PINNUMBER) == GSM_READY) & - (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) + (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { notConnected = false; - else - { + } else { Serial.println("Not connected"); delay(1000); } @@ -66,8 +63,7 @@ void setup() Serial.println("connecting..."); // if you get a connection, report back via serial: - if (client.connect(server, port)) - { + if (client.connect(server, port)) { Serial.println("connected"); // Make a HTTP request: client.print("GET "); @@ -77,27 +73,22 @@ void setup() client.println(server); client.println("Connection: close"); client.println(); - } - else - { + } else { // if you didn't get a connection to the server: Serial.println("connection failed"); } } -void loop() -{ +void loop() { // if there are incoming bytes available // from the server, read them and print them: - if (client.available()) - { + if (client.available()) { char c = client.read(); Serial.print(c); } // if the server's disconnected, stop the client: - if (!client.available() && !client.connected()) - { + if (!client.available() && !client.connected()) { Serial.println(); Serial.println("disconnecting."); client.stop(); diff --git a/libraries/GSM/examples/GsmWebServer/GsmWebServer.ino b/libraries/GSM/examples/GsmWebServer/GsmWebServer.ino index 326d55183..44e004ba7 100644 --- a/libraries/GSM/examples/GsmWebServer/GsmWebServer.ino +++ b/libraries/GSM/examples/GsmWebServer/GsmWebServer.ino @@ -32,8 +32,7 @@ GSMServer server(80); // port 80 (http default) // timeout const unsigned long __TIMEOUT__ = 10 * 1000; -void setup() -{ +void setup() { // initialize serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { @@ -45,13 +44,11 @@ void setup() // Start GSM shield // If your SIM has PIN, pass it as a parameter of begin() in quotes - while (notConnected) - { + while (notConnected) { if ((gsmAccess.begin(PINNUMBER) == GSM_READY) & - (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) + (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { notConnected = false; - else - { + } else { Serial.println("Not connected"); delay(1000); } @@ -76,22 +73,20 @@ void loop() { - if (client) - { - while (client.connected()) - { - if (client.available()) - { + if (client) { + while (client.connected()) { + if (client.available()) { Serial.println("Receiving request!"); bool sendResponse = false; while (char c = client.read()) { - if (c == '\n') sendResponse = true; + if (c == '\n') { + sendResponse = true; + } } // if you've gotten to the end of the line (received a newline // character) - if (sendResponse) - { + if (sendResponse) { // send a standard http response header client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); diff --git a/libraries/GSM/examples/MakeVoiceCall/MakeVoiceCall.ino b/libraries/GSM/examples/MakeVoiceCall/MakeVoiceCall.ino index 8cdb6d10b..364698cc0 100644 --- a/libraries/GSM/examples/MakeVoiceCall/MakeVoiceCall.ino +++ b/libraries/GSM/examples/MakeVoiceCall/MakeVoiceCall.ino @@ -32,8 +32,7 @@ GSMVoiceCall vcs; String remoteNumber = ""; // the number you will call char charbuffer[20]; -void setup() -{ +void setup() { // initialize serial communications and wait for port to open: Serial.begin(9600); @@ -48,12 +47,10 @@ void setup() // Start GSM shield // If your SIM has PIN, pass it as a parameter of begin() in quotes - while (notConnected) - { - if (gsmAccess.begin(PINNUMBER) == GSM_READY) + while (notConnected) { + if (gsmAccess.begin(PINNUMBER) == GSM_READY) { notConnected = false; - else - { + } else { Serial.println("Not connected"); delay(1000); } @@ -64,19 +61,15 @@ void setup() } -void loop() -{ +void loop() { // add any incoming characters to the String: - while (Serial.available() > 0) - { + while (Serial.available() > 0) { char inChar = Serial.read(); // if it's a newline, that means you should make the call: - if (inChar == '\n') - { + if (inChar == '\n') { // make sure the phone number is not too long: - if (remoteNumber.length() < 20) - { + if (remoteNumber.length() < 20) { // let the user know you're calling: Serial.print("Calling to : "); Serial.println(remoteNumber); @@ -87,8 +80,7 @@ void loop() // Check if the receiving end has picked up the call - if (vcs.voiceCall(charbuffer)) - { + if (vcs.voiceCall(charbuffer)) { Serial.println("Call Established. Enter line to end"); // Wait for some input from the line while (Serial.read() != '\n' && (vcs.getvoiceCallStatus() == TALKING)); @@ -98,18 +90,15 @@ void loop() Serial.println("Call Finished"); remoteNumber = ""; Serial.println("Enter phone number to call."); - } - else - { + } else { Serial.println("That's too long for a phone number. I'm forgetting it"); remoteNumber = ""; } - } - else - { + } else { // add the latest character to the message to send: - if (inChar != '\r') + if (inChar != '\r') { remoteNumber += inChar; + } } } } diff --git a/libraries/GSM/examples/ReceiveSMS/ReceiveSMS.ino b/libraries/GSM/examples/ReceiveSMS/ReceiveSMS.ino index fe24fbd64..c81709c3a 100644 --- a/libraries/GSM/examples/ReceiveSMS/ReceiveSMS.ino +++ b/libraries/GSM/examples/ReceiveSMS/ReceiveSMS.ino @@ -30,8 +30,7 @@ GSM_SMS sms; // Array to hold the number a SMS is retreived from char senderNumber[20]; -void setup() -{ +void setup() { // initialize serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { @@ -44,12 +43,10 @@ void setup() boolean notConnected = true; // Start GSM connection - while (notConnected) - { - if (gsmAccess.begin(PINNUMBER) == GSM_READY) + while (notConnected) { + if (gsmAccess.begin(PINNUMBER) == GSM_READY) { notConnected = false; - else - { + } else { Serial.println("Not connected"); delay(1000); } @@ -59,13 +56,11 @@ void setup() Serial.println("Waiting for messages"); } -void loop() -{ +void loop() { char c; // If there are any SMSs available() - if (sms.available()) - { + if (sms.available()) { Serial.println("Message received from:"); // Get remote number @@ -74,15 +69,15 @@ void loop() // An example of message disposal // Any messages starting with # should be discarded - if (sms.peek() == '#') - { + if (sms.peek() == '#') { Serial.println("Discarded SMS"); sms.flush(); } // Read message bytes and print them - while (c = sms.read()) + while (c = sms.read()) { Serial.print(c); + } Serial.println("\nEND OF MESSAGE"); diff --git a/libraries/GSM/examples/ReceiveVoiceCall/ReceiveVoiceCall.ino b/libraries/GSM/examples/ReceiveVoiceCall/ReceiveVoiceCall.ino index 1a386496a..fac94e674 100644 --- a/libraries/GSM/examples/ReceiveVoiceCall/ReceiveVoiceCall.ino +++ b/libraries/GSM/examples/ReceiveVoiceCall/ReceiveVoiceCall.ino @@ -34,8 +34,7 @@ GSMVoiceCall vcs; // Array to hold the number for the incoming call char numtel[20]; -void setup() -{ +void setup() { // initialize serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { @@ -49,12 +48,10 @@ void setup() // Start GSM shield // If your SIM has PIN, pass it as a parameter of begin() in quotes - while (notConnected) - { - if (gsmAccess.begin(PINNUMBER) == GSM_READY) + while (notConnected) { + if (gsmAccess.begin(PINNUMBER) == GSM_READY) { notConnected = false; - else - { + } else { Serial.println("Not connected"); delay(1000); } @@ -66,11 +63,9 @@ void setup() Serial.println("Waiting for a call"); } -void loop() -{ +void loop() { // Check the status of the voice call - switch (vcs.getvoiceCallStatus()) - { + switch (vcs.getvoiceCallStatus()) { case IDLE_CALL: // Nothing is happening break; @@ -93,8 +88,9 @@ void loop() case TALKING: // In this case the call would be established Serial.println("TALKING. Press enter to hang up."); - while (Serial.read() != '\n') + while (Serial.read() != '\n') { delay(100); + } vcs.hangCall(); Serial.println("Hanging up and waiting for the next call."); break; diff --git a/libraries/GSM/examples/SendSMS/SendSMS.ino b/libraries/GSM/examples/SendSMS/SendSMS.ino index 25db63342..b07d286ee 100644 --- a/libraries/GSM/examples/SendSMS/SendSMS.ino +++ b/libraries/GSM/examples/SendSMS/SendSMS.ino @@ -30,8 +30,7 @@ GSM gsmAccess; GSM_SMS sms; -void setup() -{ +void setup() { // initialize serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { @@ -45,12 +44,10 @@ void setup() // Start GSM shield // If your SIM has PIN, pass it as a parameter of begin() in quotes - while (notConnected) - { - if (gsmAccess.begin(PINNUMBER) == GSM_READY) + while (notConnected) { + if (gsmAccess.begin(PINNUMBER) == GSM_READY) { notConnected = false; - else - { + } else { Serial.println("Not connected"); delay(1000); } @@ -59,8 +56,7 @@ void setup() Serial.println("GSM initialized"); } -void loop() -{ +void loop() { Serial.print("Enter a mobile number: "); char remoteNum[20]; // telephone number to send sms @@ -86,22 +82,17 @@ void loop() /* Read input serial */ -int readSerial(char result[]) -{ +int readSerial(char result[]) { int i = 0; - while (1) - { - while (Serial.available() > 0) - { + while (1) { + while (Serial.available() > 0) { char inChar = Serial.read(); - if (inChar == '\n') - { + if (inChar == '\n') { result[i] = '\0'; Serial.flush(); return 0; } - if (inChar != '\r') - { + if (inChar != '\r') { result[i] = inChar; i++; } diff --git a/libraries/GSM/examples/Tools/BandManagement/BandManagement.ino b/libraries/GSM/examples/Tools/BandManagement/BandManagement.ino index a30b236d9..2ef088a7f 100644 --- a/libraries/GSM/examples/Tools/BandManagement/BandManagement.ino +++ b/libraries/GSM/examples/Tools/BandManagement/BandManagement.ino @@ -28,8 +28,7 @@ // initialize the library instance GSMBand band; -void setup() -{ +void setup() { // initialize serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { @@ -44,8 +43,7 @@ void setup() }; -void loop() -{ +void loop() { // Get current band String bandName = band.getBand(); // Get and print band name Serial.print("Current band:"); @@ -60,17 +58,13 @@ void loop() boolean operationSuccess; operationSuccess = band.setBand(newBandName); // Tell the user if the operation was OK - if (operationSuccess) - { + if (operationSuccess) { Serial.println("Success"); - } - else - { + } else { Serial.println("Error while changing band"); } - if (operationSuccess) - { + if (operationSuccess) { while (true); } } @@ -78,8 +72,7 @@ void loop() // This function offers the user different options // through the Serial interface // The user selects one -String askUser() -{ +String askUser() { String newBand; Serial.println("Select band:"); // Print the different options @@ -91,26 +84,28 @@ String askUser() Serial.println("6 : GSM(850)+E-GSM(900)+DCS(1800)+PCS(1900)"); // Empty the incoming buffer - while (Serial.available()) + while (Serial.available()) { Serial.read(); + } // Wait for an answer, just look at the first character while (!Serial.available()); char c = Serial.read(); - if (c == '1') + if (c == '1') { newBand = GSM_MODE_EGSM; - else if (c == '2') + } else if (c == '2') { newBand = GSM_MODE_DCS; - else if (c == '3') + } else if (c == '3') { newBand = GSM_MODE_PCS; - else if (c == '4') + } else if (c == '4') { newBand = GSM_MODE_EGSM_DCS; - else if (c == '5') + } else if (c == '5') { newBand = GSM_MODE_GSM850_PCS; - else if (c == '6') + } else if (c == '6') { newBand = GSM_MODE_GSM850_EGSM_DCS_PCS; - else + } else { newBand = "GSM_MODE_UNDEFINED"; + } return newBand; } diff --git a/libraries/GSM/examples/Tools/GsmScanNetworks/GsmScanNetworks.ino b/libraries/GSM/examples/Tools/GsmScanNetworks/GsmScanNetworks.ino index 00a7f54ea..233d11ae1 100644 --- a/libraries/GSM/examples/Tools/GsmScanNetworks/GsmScanNetworks.ino +++ b/libraries/GSM/examples/Tools/GsmScanNetworks/GsmScanNetworks.ino @@ -38,8 +38,7 @@ String IMEI = ""; // serial monitor result messages String errortext = "ERROR"; -void setup() -{ +void setup() { // initialize serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { @@ -54,12 +53,10 @@ void setup() // Start GSM shield // If your SIM has PIN, pass it as a parameter of begin() in quotes - while (notConnected) - { - if (gsmAccess.begin(PINNUMBER) == GSM_READY) + while (notConnected) { + if (gsmAccess.begin(PINNUMBER) == GSM_READY) { notConnected = false; - else - { + } else { Serial.println("Not connected"); delay(1000); } @@ -70,12 +67,12 @@ void setup() Serial.print("Modem IMEI: "); IMEI = modemTest.getIMEI(); IMEI.replace("\n", ""); - if (IMEI != NULL) + if (IMEI != NULL) { Serial.println(IMEI); + } } -void loop() -{ +void loop() { // scan for existing networks, displays a list of networks Serial.println("Scanning available networks. May take some seconds."); Serial.println(scannerNetworks.readNetworks()); diff --git a/libraries/GSM/examples/Tools/PinManagement/PinManagement.ino b/libraries/GSM/examples/Tools/PinManagement/PinManagement.ino index 0bfa4eb96..6dc37b33d 100644 --- a/libraries/GSM/examples/Tools/PinManagement/PinManagement.ino +++ b/libraries/GSM/examples/Tools/PinManagement/PinManagement.ino @@ -32,8 +32,7 @@ boolean auth = false; String oktext = "OK"; String errortext = "ERROR"; -void setup() -{ +void setup() { // initialize serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { @@ -46,52 +45,39 @@ void setup() // check if the SIM have pin lock while (!auth) { int pin_query = PINManager.isPIN(); - if (pin_query == 1) - { + if (pin_query == 1) { // if SIM is locked, enter PIN code Serial.print("Enter PIN code: "); user_input = readSerial(); // check PIN code - if (PINManager.checkPIN(user_input) == 0) - { + if (PINManager.checkPIN(user_input) == 0) { auth = true; PINManager.setPINUsed(true); Serial.println(oktext); - } - else - { + } else { // if PIN code was incorrected Serial.println("Incorrect PIN. Remember that you have 3 opportunities."); } - } - else if (pin_query == -1) - { + } else if (pin_query == -1) { // PIN code is locked, user must enter PUK code Serial.println("PIN locked. Enter PUK code: "); String puk = readSerial(); Serial.print("Now, enter a new PIN code: "); user_input = readSerial(); // check PUK code - if (PINManager.checkPUK(puk, user_input) == 0) - { + if (PINManager.checkPUK(puk, user_input) == 0) { auth = true; PINManager.setPINUsed(true); Serial.println(oktext); - } - else - { + } else { // if PUK o the new PIN are incorrect Serial.println("Incorrect PUK or invalid new PIN. Try again!."); } - } - else if (pin_query == -2) - { + } else if (pin_query == -2) { // the worst case, PIN and PUK are locked Serial.println("PIN & PUK locked. Use PIN2/PUK2 in a mobile phone."); while (true); - } - else - { + } else { // SIM does not requires authetication Serial.println("No pin necessary."); auth = true; @@ -100,47 +86,42 @@ void setup() // start GSM shield Serial.print("Checking register in GSM network..."); - if (PINManager.checkReg() == 0) + if (PINManager.checkReg() == 0) { Serial.println(oktext); + } // if you are connect by roaming - else if (PINManager.checkReg() == 1) + else if (PINManager.checkReg() == 1) { Serial.println("ROAMING " + oktext); - else - { + } else { // error connection Serial.println(errortext); while (true); } } -void loop() -{ +void loop() { // Function loop implements pin management user menu // Only if you SIM use pin lock, you can change PIN code // user_op variables save user option Serial.println("Choose an option:\n1 - On/Off PIN."); - if (PINManager.getPINUsed()) + if (PINManager.getPINUsed()) { Serial.println("2 - Change PIN."); + } String user_op = readSerial(); - if (user_op == "1") - { + if (user_op == "1") { Serial.println("Enter your PIN code:"); user_input = readSerial(); // activate/deactivate PIN lock PINManager.switchPIN(user_input); - } - else if (user_op == "2" & PINManager.getPINUsed()) - { + } else if (user_op == "2" & PINManager.getPINUsed()) { Serial.println("Enter your actual PIN code:"); String oldPIN = readSerial(); Serial.println("Now, enter your new PIN code:"); String newPIN = readSerial(); // change PIN PINManager.changePIN(oldPIN, newPIN); - } - else - { + } else { Serial.println("Incorrect option. Try again!."); } delay(1000); @@ -149,20 +130,17 @@ void loop() /* Read input serial */ -String readSerial() -{ +String readSerial() { String text = ""; - while (1) - { - while (Serial.available() > 0) - { + while (1) { + while (Serial.available() > 0) { char inChar = Serial.read(); - if (inChar == '\n') - { + if (inChar == '\n') { return text; } - if (inChar != '\r') + if (inChar != '\r') { text += inChar; + } } } } diff --git a/libraries/GSM/examples/Tools/TestGPRS/TestGPRS.ino b/libraries/GSM/examples/Tools/TestGPRS/TestGPRS.ino index 2c78bf78c..85a8bc8bc 100644 --- a/libraries/GSM/examples/Tools/TestGPRS/TestGPRS.ino +++ b/libraries/GSM/examples/Tools/TestGPRS/TestGPRS.ino @@ -43,8 +43,7 @@ String response = ""; // use a proxy boolean use_proxy = false; -void setup() -{ +void setup() { // initialize serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { @@ -52,15 +51,13 @@ void setup() } } -void loop() -{ +void loop() { use_proxy = false; // start GSM shield // if your SIM has PIN, pass it as a parameter of begin() in quotes Serial.print("Connecting GSM network..."); - if (gsmAccess.begin(PINNUMBER) != GSM_READY) - { + if (gsmAccess.begin(PINNUMBER) != GSM_READY) { Serial.println(errortext); while (true); } @@ -85,11 +82,9 @@ void loop() // attach GPRS Serial.println("Attaching to GPRS with your APN..."); - if (gprsAccess.attachGPRS(apn, login, password) != GPRS_READY) - { + if (gprsAccess.attachGPRS(apn, login, password) != GPRS_READY) { Serial.println(errortext); - } - else { + } else { Serial.println(oktext); @@ -117,40 +112,37 @@ void loop() int res_connect; // if use a proxy, connect with it - if (use_proxy) + if (use_proxy) { res_connect = client.connect(proxy, pport); - else + } else { res_connect = client.connect(url, 80); + } - if (res_connect) - { + if (res_connect) { // make a HTTP 1.0 GET request (client sends the request) client.print("GET "); // if use a proxy, the path is arduino.cc URL - if (use_proxy) + if (use_proxy) { client.print(urlproxy); - else + } else { client.print(path); + } client.println(" HTTP/1.0"); client.println(); Serial.println(oktext); - } - else - { + } else { // if you didn't get a connection to the server Serial.println(errortext); } Serial.print("Receiving response..."); boolean test = true; - while (test) - { + while (test) { // if there are incoming bytes available // from the server, read and check them - if (client.available()) - { + if (client.available()) { char c = client.read(); response += c; @@ -167,8 +159,7 @@ void loop() } // if the server's disconnected, stop the client: - if (!client.connected()) - { + if (!client.connected()) { Serial.println(); Serial.println("disconnecting."); client.stop(); @@ -181,21 +172,16 @@ void loop() /* Read input serial */ -int readSerial(char result[]) -{ +int readSerial(char result[]) { int i = 0; - while (1) - { - while (Serial.available() > 0) - { + while (1) { + while (Serial.available() > 0) { char inChar = Serial.read(); - if (inChar == '\n') - { + if (inChar == '\n') { result[i] = '\0'; return 0; } - if (inChar != '\r') - { + if (inChar != '\r') { result[i] = inChar; i++; } diff --git a/libraries/GSM/examples/Tools/TestModem/TestModem.ino b/libraries/GSM/examples/Tools/TestModem/TestModem.ino index f5e0e3268..5ee42219b 100644 --- a/libraries/GSM/examples/Tools/TestModem/TestModem.ino +++ b/libraries/GSM/examples/Tools/TestModem/TestModem.ino @@ -27,8 +27,7 @@ GSMModem modem; // IMEI variable String IMEI = ""; -void setup() -{ +void setup() { // initialize serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { @@ -37,38 +36,32 @@ void setup() // start modem test (reset and check response) Serial.print("Starting modem test..."); - if (modem.begin()) + if (modem.begin()) { Serial.println("modem.begin() succeeded"); - else + } else { Serial.println("ERROR, no modem answer."); + } } -void loop() -{ +void loop() { // get modem IMEI Serial.print("Checking IMEI..."); IMEI = modem.getIMEI(); // check IMEI response - if (IMEI != NULL) - { + if (IMEI != NULL) { // show IMEI in serial monitor Serial.println("Modem's IMEI: " + IMEI); // reset modem to check booting: Serial.print("Resetting modem..."); modem.begin(); // get and check IMEI one more time - if (modem.getIMEI() != NULL) - { + if (modem.getIMEI() != NULL) { Serial.println("Modem is functoning properly"); - } - else - { + } else { Serial.println("Error: getIMEI() failed after modem.begin()"); } - } - else - { + } else { Serial.println("Error: Could not get IMEI"); } // do nothing: diff --git a/libraries/GSM/examples/Tools/TestWebServer/TestWebServer.ino b/libraries/GSM/examples/Tools/TestWebServer/TestWebServer.ino index 3b24bb21f..d3939e11a 100644 --- a/libraries/GSM/examples/Tools/TestWebServer/TestWebServer.ino +++ b/libraries/GSM/examples/Tools/TestWebServer/TestWebServer.ino @@ -35,8 +35,7 @@ GSMServer server(80); // port 80 (http default) // timeout const unsigned long __TIMEOUT__ = 10 * 1000; -void setup() -{ +void setup() { // initialize serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { @@ -49,13 +48,11 @@ void setup() // Start GSM shield // If your SIM has PIN, pass it as a parameter of begin() in quotes - while (!connected) - { + while (!connected) { if ((gsmAccess.begin(PINNUMBER) == GSM_READY) & - (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) + (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { connected = true; - else - { + } else { Serial.println("Not connected"); delay(1000); } diff --git a/libraries/LiquidCrystal/examples/CustomCharacter/CustomCharacter.ino b/libraries/LiquidCrystal/examples/CustomCharacter/CustomCharacter.ino index e70a949e3..bdac95c62 100644 --- a/libraries/LiquidCrystal/examples/CustomCharacter/CustomCharacter.ino +++ b/libraries/LiquidCrystal/examples/CustomCharacter/CustomCharacter.ino @@ -21,12 +21,12 @@ * ends to +5V and ground * wiper to LCD VO pin (pin 3) * 10K poterntiometer on pin A0 - + created 21 Mar 2011 by Tom Igoe modified 11 Nov 2013 by Scott Fitzgerald - + Based on Adafruit's example at https://github.com/adafruit/SPI_VFD/blob/master/examples/createChar/createChar.pde @@ -101,9 +101,9 @@ byte armsUp[8] = { }; void setup() { - // initialize LCD and set up the number of columns and rows: + // initialize LCD and set up the number of columns and rows: lcd.begin(16, 2); - + // create a new character lcd.createChar(0, heart); // create a new character @@ -116,7 +116,7 @@ void setup() { lcd.createChar(4, armsUp); // Print a message to the lcd. - lcd.print("I "); + lcd.print("I "); lcd.write(byte(0)); // when calling lcd.write() '0' must be cast as a byte lcd.print(" Arduino! "); lcd.write((byte) 1); diff --git a/libraries/LiquidCrystal/examples/SerialDisplay/SerialDisplay.ino b/libraries/LiquidCrystal/examples/SerialDisplay/SerialDisplay.ino index ec46ff0fd..578e11e8c 100644 --- a/libraries/LiquidCrystal/examples/SerialDisplay/SerialDisplay.ino +++ b/libraries/LiquidCrystal/examples/SerialDisplay/SerialDisplay.ino @@ -48,8 +48,7 @@ void setup() { Serial.begin(9600); } -void loop() -{ +void loop() { // when characters arrive over the serial port... if (Serial.available()) { // wait a bit for the entire message to arrive 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 3fd50f629..251bffa9c 100644 --- a/libraries/Robot_Control/examples/explore/R01_Logo/R01_Logo.ino +++ b/libraries/Robot_Control/examples/explore/R01_Logo/R01_Logo.ino @@ -56,8 +56,9 @@ void loop() { // empty the commands array void iniCommands() { - for (int i = 0; i < 20; i++) + for (int i = 0; i < 20; i++) { commands[i] = -1; + } } // add commands to the array 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 b8780546c..fd25261f5 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 @@ -99,17 +99,19 @@ void runScript() { // 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 - currentScript = 0; // start again at the beginning + 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 + } else { return true; + } } // how long to wait 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 1c77153a7..2415a30d3 100644 --- a/libraries/Robot_Control/examples/explore/R04_Compass/R04_Compass.ino +++ b/libraries/Robot_Control/examples/explore/R04_Compass/R04_Compass.ino @@ -45,10 +45,11 @@ void loop() { int diff = compassValue - direc; // modify degress - if (diff > 180) + if (diff > 180) { diff = -360 + diff; - else if (diff < -180) + } else if (diff < -180) { diff = 360 + diff; + } // Make the robot turn to its proper orientation diff = map(diff, -180, 180, -255, 255); 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 de1cb49f4..9226d0242 100644 --- a/libraries/Robot_Control/examples/explore/R05_Inputs/R05_Inputs.ino +++ b/libraries/Robot_Control/examples/explore/R05_Inputs/R05_Inputs.ino @@ -85,7 +85,9 @@ void keyDown(int keyCode) { case BUTTON_LEFT: //left button pressed, reduces tempo tempo -= 5; - if (tempo < 20) tempo = 20; //lowest tempo 20 + if (tempo < 20) { + tempo = 20; //lowest tempo 20 + } Robot.fill(255, 190, 0); Robot.rect(53, 58, 13, 13); @@ -93,14 +95,18 @@ void keyDown(int keyCode) { case BUTTON_RIGHT: //right button pressed, increases tempo tempo += 5; - if (tempo > 100) tempo = 100; //highest tempo 100 + 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); 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 7d509f3fa..02939e1f2 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 @@ -93,11 +93,15 @@ void keyboardControl() { int keyPressed = Robot.keyboardRead(); // read the button values 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); @@ -118,11 +122,16 @@ void compassControl(int change) { //get the change of angle int diff = Robot.compassRead() - oldV; - if (diff > 180) diff -= 360; - else if (diff < -180) diff += 360; + if (diff > 180) { + diff -= 360; + } else if (diff < -180) { + diff += 360; + } if (abs(diff) > change) { - if (++i > NUM_PICS) i = 1; + if (++i > NUM_PICS) { + i = 1; + } return; } @@ -146,8 +155,9 @@ void changeMode(int changeDir) { mode += changeDir; if (mode < 0) { mode = 1; - } else if (mode > 1) + } else if (mode > 1) { mode = 0; + } // display the mode on screen Robot.fill(255, 255, 255); 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 0c67eb188..8024dda0d 100644 --- a/libraries/Robot_Control/examples/explore/R10_Rescue/R10_Rescue.ino +++ b/libraries/Robot_Control/examples/explore/R10_Rescue/R10_Rescue.ino @@ -65,10 +65,10 @@ void setup() { goToNext(); // run the rescue sequence a second time rescueSequence(); - + // here you could go on ... - - + + } void loop() { diff --git a/libraries/SD/examples/CardInfo/CardInfo.ino b/libraries/SD/examples/CardInfo/CardInfo.ino index 8d8a51ec9..7e4716d8e 100644 --- a/libraries/SD/examples/CardInfo/CardInfo.ino +++ b/libraries/SD/examples/CardInfo/CardInfo.ino @@ -34,8 +34,7 @@ SdFile root; // Sparkfun SD shield: pin 8 const int chipSelect = 4; -void setup() -{ +void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { diff --git a/libraries/SD/examples/Datalogger/Datalogger.ino b/libraries/SD/examples/Datalogger/Datalogger.ino index e071b5282..700e3c525 100644 --- a/libraries/SD/examples/Datalogger/Datalogger.ino +++ b/libraries/SD/examples/Datalogger/Datalogger.ino @@ -25,8 +25,7 @@ const int chipSelect = 4; -void setup() -{ +void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { @@ -45,8 +44,7 @@ void setup() Serial.println("card initialized."); } -void loop() -{ +void loop() { // make a string for assembling the data to log: String dataString = ""; diff --git a/libraries/SD/examples/DumpFile/DumpFile.ino b/libraries/SD/examples/DumpFile/DumpFile.ino index e2eaf1c59..d091081c9 100644 --- a/libraries/SD/examples/DumpFile/DumpFile.ino +++ b/libraries/SD/examples/DumpFile/DumpFile.ino @@ -25,8 +25,7 @@ const int chipSelect = 4; -void setup() -{ +void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { @@ -61,7 +60,6 @@ void setup() } } -void loop() -{ +void loop() { } diff --git a/libraries/SD/examples/Files/Files.ino b/libraries/SD/examples/Files/Files.ino index f01db3828..b51314c92 100644 --- a/libraries/SD/examples/Files/Files.ino +++ b/libraries/SD/examples/Files/Files.ino @@ -22,8 +22,7 @@ File myFile; -void setup() -{ +void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { @@ -41,8 +40,7 @@ void setup() if (SD.exists("example.txt")) { Serial.println("example.txt exists."); - } - else { + } else { Serial.println("example.txt doesn't exist."); } @@ -54,8 +52,7 @@ void setup() // Check to see if the file exists: if (SD.exists("example.txt")) { Serial.println("example.txt exists."); - } - else { + } else { Serial.println("example.txt doesn't exist."); } @@ -65,14 +62,12 @@ void setup() if (SD.exists("example.txt")) { Serial.println("example.txt exists."); - } - else { + } else { Serial.println("example.txt doesn't exist."); } } -void loop() -{ +void loop() { // nothing happens after setup finishes. } diff --git a/libraries/SD/examples/ReadWrite/ReadWrite.ino b/libraries/SD/examples/ReadWrite/ReadWrite.ino index 055a0166b..8357b81a6 100644 --- a/libraries/SD/examples/ReadWrite/ReadWrite.ino +++ b/libraries/SD/examples/ReadWrite/ReadWrite.ino @@ -23,8 +23,7 @@ File myFile; -void setup() -{ +void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { @@ -73,8 +72,7 @@ void setup() } } -void loop() -{ +void loop() { // nothing happens after setup } diff --git a/libraries/SD/examples/listfiles/listfiles.ino b/libraries/SD/examples/listfiles/listfiles.ino index 1500d74e0..a5abfc786 100644 --- a/libraries/SD/examples/listfiles/listfiles.ino +++ b/libraries/SD/examples/listfiles/listfiles.ino @@ -1,9 +1,9 @@ /* Listfiles - - This example shows how print out the files in a - directory on a SD card - + + This example shows how print out the files in a + directory on a SD card + The circuit: * SD card attached to SPI bus as follows: ** MOSI - pin 11 @@ -17,7 +17,7 @@ by Tom Igoe modified 2 Feb 2014 by Scott Fitzgerald - + This example code is in the public domain. */ @@ -26,8 +26,7 @@ File root; -void setup() -{ +void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { @@ -49,33 +48,32 @@ void setup() Serial.println("done!"); } -void loop() -{ +void loop() { // nothing happens after setup finishes. } void printDirectory(File dir, int numTabs) { - while(true) { - - File entry = dir.openNextFile(); - if (! entry) { - // no more files - break; - } - for (uint8_t i=0; i +/* + Controlling a servo position using a potentiometer (variable resistor) + by Michal Rinott modified on 8 Nov 2013 by Scott Fitzgerald @@ -14,16 +14,14 @@ 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() -{ +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, 180); // 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 -} +void loop() { + val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023) + val = map(val, 0, 1023, 0, 180); // 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 79ef30fc0..df904afb1 100644 --- a/libraries/Servo/examples/Sweep/Sweep.ino +++ b/libraries/Servo/examples/Sweep/Sweep.ino @@ -1,35 +1,32 @@ /* Sweep - by BARRAGAN + by BARRAGAN This example code is in the public domain. modified 8 Nov 2013 by Scott Fitzgerald http://www.arduino.cc/en/Tutorial/Sweep -*/ +*/ -#include - -Servo myservo; // create servo object to control a servo - // twelve servo objects can be created on most boards - -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>=0; 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 +// twelve servo objects can be created on most boards + +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 >= 0; 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/Stepper/examples/MotorKnob/MotorKnob.ino b/libraries/Stepper/examples/MotorKnob/MotorKnob.ino index d42818634..5cf12ec85 100644 --- a/libraries/Stepper/examples/MotorKnob/MotorKnob.ino +++ b/libraries/Stepper/examples/MotorKnob/MotorKnob.ino @@ -21,14 +21,12 @@ Stepper stepper(STEPS, 8, 9, 10, 11); // the previous reading from the analog input int previous = 0; -void setup() -{ +void setup() { // set the speed of the motor to 30 RPMs stepper.setSpeed(30); } -void loop() -{ +void loop() { // get the sensor value int val = analogRead(0); diff --git a/libraries/Stepper/examples/stepper_oneStepAtATime/stepper_oneStepAtATime.ino b/libraries/Stepper/examples/stepper_oneStepAtATime/stepper_oneStepAtATime.ino index c173e308a..e6c141f4d 100644 --- a/libraries/Stepper/examples/stepper_oneStepAtATime/stepper_oneStepAtATime.ino +++ b/libraries/Stepper/examples/stepper_oneStepAtATime/stepper_oneStepAtATime.ino @@ -36,7 +36,7 @@ void setup() { void loop() { // step one step: myStepper.step(1); - Serial.print("steps:" ); + Serial.print("steps:"); Serial.println(stepCount); stepCount++; delay(500); diff --git a/libraries/TFT/examples/Arduino/TFTEtchASketch/TFTEtchASketch.ino b/libraries/TFT/examples/Arduino/TFTEtchASketch/TFTEtchASketch.ino index 2a3d6e713..4eb75d1d4 100644 --- a/libraries/TFT/examples/Arduino/TFTEtchASketch/TFTEtchASketch.ino +++ b/libraries/TFT/examples/Arduino/TFTEtchASketch/TFTEtchASketch.ino @@ -45,8 +45,7 @@ void setup() { TFTscreen.background(0, 0, 0); } -void loop() -{ +void loop() { // read the potentiometers on A0 and A1 int xValue = analogRead(A0); int yValue = analogRead(A1); diff --git a/libraries/TFT/examples/Arduino/TFTGraph/TFTGraph.ino b/libraries/TFT/examples/Arduino/TFTGraph/TFTGraph.ino index 6c789593c..3b2f03b97 100644 --- a/libraries/TFT/examples/Arduino/TFTGraph/TFTGraph.ino +++ b/libraries/TFT/examples/Arduino/TFTGraph/TFTGraph.ino @@ -60,8 +60,7 @@ void loop() { if (xPos >= 160) { xPos = 0; TFTscreen.background(250, 16, 200); - } - else { + } else { // increment the horizontal position: xPos++; } diff --git a/libraries/TFT/examples/Esplora/EsploraTFTBitmapLogo/EsploraTFTBitmapLogo.ino b/libraries/TFT/examples/Esplora/EsploraTFTBitmapLogo/EsploraTFTBitmapLogo.ino index d6eba2e35..84585d469 100644 --- a/libraries/TFT/examples/Esplora/EsploraTFTBitmapLogo/EsploraTFTBitmapLogo.ino +++ b/libraries/TFT/examples/Esplora/EsploraTFTBitmapLogo/EsploraTFTBitmapLogo.ino @@ -73,9 +73,9 @@ void setup() { logo = EsploraTFT.loadImage("arduino.bmp"); if (logo.isValid()) { Esplora.writeGreen(255); - } - else + } else { Esplora.writeRed(255); + } } diff --git a/libraries/TFT/examples/Esplora/EsploraTFTEtchASketch/EsploraTFTEtchASketch.ino b/libraries/TFT/examples/Esplora/EsploraTFTEtchASketch/EsploraTFTEtchASketch.ino index 9a42ffa0c..7d5b567e1 100644 --- a/libraries/TFT/examples/Esplora/EsploraTFTEtchASketch/EsploraTFTEtchASketch.ino +++ b/libraries/TFT/examples/Esplora/EsploraTFTEtchASketch/EsploraTFTEtchASketch.ino @@ -31,8 +31,7 @@ void setup() { EsploraTFT.background(0, 0, 0); } -void loop() -{ +void loop() { int xAxis = Esplora.readJoystickX(); // read the X axis int yAxis = Esplora.readJoystickY(); // read the Y axis @@ -41,14 +40,12 @@ void loop() // depending on the position of the joystick if (xAxis < 10 && xAxis > -10) { xPos = xPos; - } - else { + } else { xPos = xPos + (map(xAxis, -512, 512, 2, -2)); } if (yAxis < 10 && yAxis > -10) { yAxis = yAxis; - } - else { + } else { yPos = yPos + (map(yAxis, -512, 512, -2, 2)); } diff --git a/libraries/TFT/examples/Esplora/EsploraTFTGraph/EsploraTFTGraph.ino b/libraries/TFT/examples/Esplora/EsploraTFTGraph/EsploraTFTGraph.ino index 06364c20e..24e0db6dd 100644 --- a/libraries/TFT/examples/Esplora/EsploraTFTGraph/EsploraTFTGraph.ino +++ b/libraries/TFT/examples/Esplora/EsploraTFTGraph/EsploraTFTGraph.ino @@ -46,8 +46,7 @@ void loop() { if (xPos >= 160) { xPos = 0; EsploraTFT.background(250, 16, 200); - } - else { + } 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 34abf29d2..9a5a454d0 100644 --- a/libraries/TFT/examples/Esplora/EsploraTFTHorizon/EsploraTFTHorizon.ino +++ b/libraries/TFT/examples/Esplora/EsploraTFTHorizon/EsploraTFTHorizon.ino @@ -33,8 +33,7 @@ void setup() { EsploraTFT.background(0, 0, 0); } -void loop() -{ +void loop() { // read the x-axis of te accelerometer int tilt = Esplora.readAccelerometer(X_AXIS); diff --git a/libraries/USBHost/examples/ADKTerminalTest/ADKTerminalTest.ino b/libraries/USBHost/examples/ADKTerminalTest/ADKTerminalTest.ino index 2d4f14e2b..027078676 100644 --- a/libraries/USBHost/examples/ADKTerminalTest/ADKTerminalTest.ino +++ b/libraries/USBHost/examples/ADKTerminalTest/ADKTerminalTest.ino @@ -31,8 +31,7 @@ char url[] = "http://labs.arduino.cc/uploads/ADK/ArduinoTerminal/ThibaultTermina USBHost Usb; ADK adk(&Usb, companyName, applicationName, accessoryName, versionNumber, url, serialNumber); -void setup() -{ +void setup() { cpu_irq_enable(); printf("\r\nADK demo start\r\n"); delay(200); @@ -40,16 +39,14 @@ void setup() #define RCVSIZE 128 -void loop() -{ +void loop() { uint8_t buf[RCVSIZE]; uint32_t nbread = 0; char helloworld[] = "Hello World!\r\n"; Usb.Task(); - if (adk.isReady()) - { + if (adk.isReady()) { /* Write hello string to ADK */ adk.write(strlen(helloworld), (uint8_t *)helloworld); @@ -57,11 +54,9 @@ void loop() /* Read data from ADK and print to UART */ adk.read(&nbread, RCVSIZE, buf); - if (nbread > 0) - { + if (nbread > 0) { printf("RCV: "); - for (uint32_t i = 0; i < nbread; ++i) - { + 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 0dc05ea8b..667f2d464 100644 --- a/libraries/USBHost/examples/KeyboardController/KeyboardController.ino +++ b/libraries/USBHost/examples/KeyboardController/KeyboardController.ino @@ -46,22 +46,30 @@ void printKey() { Serial.print(" => "); - if (mod & LeftCtrl) + if (mod & LeftCtrl) { Serial.print("L-Ctrl "); - if (mod & LeftShift) + } + if (mod & LeftShift) { Serial.print("L-Shift "); - if (mod & Alt) + } + if (mod & Alt) { Serial.print("Alt "); - if (mod & LeftCmd) + } + if (mod & LeftCmd) { Serial.print("L-Cmd "); - if (mod & RightCtrl) + } + if (mod & RightCtrl) { Serial.print("R-Ctrl "); - if (mod & RightShift) + } + if (mod & RightShift) { Serial.print("R-Shift "); - if (mod & AltGr) + } + if (mod & AltGr) { Serial.print("AltGr "); - if (mod & RightCmd) + } + if (mod & RightCmd) { Serial.print("R-Cmd "); + } // getKey() returns the ASCII translation of OEM key // combined with modifiers. @@ -69,15 +77,13 @@ void printKey() { Serial.println(); } -void setup() -{ +void setup() { Serial.begin(9600); Serial.println("Program started"); delay(200); } -void loop() -{ +void loop() { // Process USB tasks usb.Task(); } diff --git a/libraries/USBHost/examples/MouseController/MouseController.ino b/libraries/USBHost/examples/MouseController/MouseController.ino index bcd287f2b..5cd726a91 100644 --- a/libraries/USBHost/examples/MouseController/MouseController.ino +++ b/libraries/USBHost/examples/MouseController/MouseController.ino @@ -78,15 +78,13 @@ void mouseReleased() { Serial.println(); } -void setup() -{ +void setup() { Serial.begin(9600); Serial.println("Program started"); delay(200); } -void loop() -{ +void loop() { // Process USB tasks usb.Task(); } diff --git a/libraries/WiFi/examples/ConnectNoEncryption/ConnectNoEncryption.ino b/libraries/WiFi/examples/ConnectNoEncryption/ConnectNoEncryption.ino index 2d27392b8..cd26abb61 100644 --- a/libraries/WiFi/examples/ConnectNoEncryption/ConnectNoEncryption.ino +++ b/libraries/WiFi/examples/ConnectNoEncryption/ConnectNoEncryption.ino @@ -33,11 +33,12 @@ void setup() { } 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 open SSID: "); Serial.println(ssid); status = WiFi.begin(ssid); diff --git a/libraries/WiFi/examples/ConnectWithWEP/ConnectWithWEP.ino b/libraries/WiFi/examples/ConnectWithWEP/ConnectWithWEP.ino index 0f440ed69..fd3e9c213 100644 --- a/libraries/WiFi/examples/ConnectWithWEP/ConnectWithWEP.ino +++ b/libraries/WiFi/examples/ConnectWithWEP/ConnectWithWEP.ino @@ -45,11 +45,12 @@ void setup() { } 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); diff --git a/libraries/WiFi/examples/ConnectWithWPA/ConnectWithWPA.ino b/libraries/WiFi/examples/ConnectWithWPA/ConnectWithWPA.ino index aa1b42ca9..8bc5ab956 100644 --- a/libraries/WiFi/examples/ConnectWithWPA/ConnectWithWPA.ino +++ b/libraries/WiFi/examples/ConnectWithWPA/ConnectWithWPA.ino @@ -34,11 +34,12 @@ void setup() { } 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 WPA SSID: "); Serial.println(ssid); // Connect to WPA/WPA2 network: diff --git a/libraries/WiFi/examples/ScanNetworks/ScanNetworks.ino b/libraries/WiFi/examples/ScanNetworks/ScanNetworks.ino index 8658ef0cb..4c5f922cf 100644 --- a/libraries/WiFi/examples/ScanNetworks/ScanNetworks.ino +++ b/libraries/WiFi/examples/ScanNetworks/ScanNetworks.ino @@ -33,8 +33,9 @@ void setup() { } String fv = WiFi.firmwareVersion(); - if ( fv != "1.1.0" ) + if (fv != "1.1.0") { Serial.println("Please upgrade the firmware"); + } // Print WiFi MAC address: printMacAddress(); @@ -75,8 +76,7 @@ void listNetworks() { // scan for nearby networks: Serial.println("** Scan Networks **"); int numSsid = WiFi.scanNetworks(); - if (numSsid == -1) - { + if (numSsid == -1) { Serial.println("Couldn't get a wifi connection"); while (true); } diff --git a/libraries/WiFi/examples/SimpleWebServerWiFi/SimpleWebServerWiFi.ino b/libraries/WiFi/examples/SimpleWebServerWiFi/SimpleWebServerWiFi.ino index ac5733033..c9cc5a69f 100644 --- a/libraries/WiFi/examples/SimpleWebServerWiFi/SimpleWebServerWiFi.ino +++ b/libraries/WiFi/examples/SimpleWebServerWiFi/SimpleWebServerWiFi.ino @@ -41,11 +41,12 @@ void setup() { } 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); @@ -88,12 +89,10 @@ void loop() { client.println(); // break out of the while loop: break; - } - else { // if you got a newline, then clear currentLine: + } else { // if you got a newline, then clear currentLine: currentLine = ""; } - } - else if (c != '\r') { // if you got anything else but a carriage return character, + } 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 b50a38ae0..0847386f2 100644 --- a/libraries/WiFi/examples/WiFiChatServer/WiFiChatServer.ino +++ b/libraries/WiFi/examples/WiFiChatServer/WiFiChatServer.ino @@ -48,11 +48,12 @@ void setup() { } 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: diff --git a/libraries/WiFi/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino b/libraries/WiFi/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino index 059b2679d..f5f0f29cf 100644 --- a/libraries/WiFi/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino +++ b/libraries/WiFi/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino @@ -36,8 +36,7 @@ byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing pack // A UDP instance to let us send and receive packets over UDP WiFiUDP Udp; -void setup() -{ +void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { @@ -52,11 +51,12 @@ void setup() } 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: @@ -73,13 +73,12 @@ void setup() Udp.begin(localPort); } -void loop() -{ +void loop() { sendNTPpacket(timeServer); // send an NTP packet to a time server // wait to see if a reply is available delay(1000); - Serial.println( Udp.parsePacket() ); - if ( Udp.parsePacket() ) { + Serial.println(Udp.parsePacket()); + 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 @@ -92,7 +91,7 @@ void loop() // combine the four bytes (two words) into a long integer // this is NTP time (seconds since Jan 1 1900): unsigned long secsSince1900 = highWord << 16 | lowWord; - Serial.print("Seconds since Jan 1 1900 = " ); + Serial.print("Seconds since Jan 1 1900 = "); Serial.println(secsSince1900); // now convert NTP time into everyday time: @@ -109,13 +108,13 @@ void loop() Serial.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT) Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day) Serial.print(':'); - if ( ((epoch % 3600) / 60) < 10 ) { + if (((epoch % 3600) / 60) < 10) { // In the first 10 minutes of each hour, we'll want a leading '0' Serial.print('0'); } Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute) Serial.print(':'); - if ( (epoch % 60) < 10 ) { + if ((epoch % 60) < 10) { // In the first 10 seconds of each minute, we'll want a leading '0' Serial.print('0'); } @@ -126,8 +125,7 @@ void loop() } // send an NTP request to the time server at the given address -unsigned long sendNTPpacket(IPAddress& address) -{ +unsigned long sendNTPpacket(IPAddress& address) { //Serial.println("1"); // set all bytes in the buffer to 0 memset(packetBuffer, 0, NTP_PACKET_SIZE); diff --git a/libraries/WiFi/examples/WiFiUdpSendReceiveString/WiFiUdpSendReceiveString.ino b/libraries/WiFi/examples/WiFiUdpSendReceiveString/WiFiUdpSendReceiveString.ino index 90deef81e..1d38a7d5c 100644 --- a/libraries/WiFi/examples/WiFiUdpSendReceiveString/WiFiUdpSendReceiveString.ino +++ b/libraries/WiFi/examples/WiFiUdpSendReceiveString/WiFiUdpSendReceiveString.ino @@ -45,11 +45,12 @@ void setup() { } 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: @@ -70,8 +71,7 @@ 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 "); @@ -82,7 +82,9 @@ void loop() { // read the packet into packetBufffer int len = Udp.read(packetBuffer, 255); - if (len > 0) packetBuffer[len] = 0; + if (len > 0) { + packetBuffer[len] = 0; + } Serial.println("Contents:"); Serial.println(packetBuffer); diff --git a/libraries/WiFi/examples/WiFiWebClient/WiFiWebClient.ino b/libraries/WiFi/examples/WiFiWebClient/WiFiWebClient.ino index 017b3572a..77154219e 100644 --- a/libraries/WiFi/examples/WiFiWebClient/WiFiWebClient.ino +++ b/libraries/WiFi/examples/WiFiWebClient/WiFiWebClient.ino @@ -54,8 +54,9 @@ void setup() { } 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) { diff --git a/libraries/WiFi/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino b/libraries/WiFi/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino index 5143fe996..71ca57b50 100644 --- a/libraries/WiFi/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino +++ b/libraries/WiFi/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino @@ -19,7 +19,7 @@ #include #include - + 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) @@ -51,11 +51,12 @@ void setup() { } 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: @@ -103,8 +104,7 @@ void httpRequest() { // note the time that the connection was made: lastConnectionTime = millis(); - } - else { + } else { // if you couldn't make a connection: Serial.println("connection failed"); } diff --git a/libraries/WiFi/examples/WiFiWebServer/WiFiWebServer.ino b/libraries/WiFi/examples/WiFiWebServer/WiFiWebServer.ino index 4ea045683..cec2aaeb1 100644 --- a/libraries/WiFi/examples/WiFiWebServer/WiFiWebServer.ino +++ b/libraries/WiFi/examples/WiFiWebServer/WiFiWebServer.ino @@ -45,11 +45,12 @@ void setup() { } 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: @@ -102,8 +103,7 @@ void loop() { if (c == '\n') { // you're starting a new line currentLineIsBlank = true; - } - else if (c != '\r') { + } else if (c != '\r') { // you've gotten a character on the current line currentLineIsBlank = false; }