1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-18 07:52:14 +01:00

Run new astyle formatter against all the examples

This commit is contained in:
Federico Fissore 2013-10-21 09:58:40 +02:00
parent 3c6ee46828
commit b4c68b3dff
259 changed files with 5160 additions and 5217 deletions

View File

@ -48,7 +48,7 @@ void loop()
// blink the LED. // blink the LED.
unsigned long currentMillis = millis(); unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) { if (currentMillis - previousMillis > interval) {
// save the last time you blinked the LED // save the last time you blinked the LED
previousMillis = currentMillis; previousMillis = currentMillis;

View File

@ -39,7 +39,7 @@ void setup() {
pinMode(buttonPin, INPUT); pinMode(buttonPin, INPUT);
} }
void loop(){ void loop() {
// read the state of the pushbutton value: // read the state of the pushbutton value:
buttonState = digitalRead(buttonPin); buttonState = digitalRead(buttonPin);

View File

@ -21,7 +21,7 @@
*/ */
void setup(){ void setup() {
//start serial connection //start serial connection
Serial.begin(9600); Serial.begin(9600);
//configure pin2 as an input and enable the internal pull-up resistor //configure pin2 as an input and enable the internal pull-up resistor
@ -30,7 +30,7 @@ void setup(){
} }
void loop(){ void loop() {
//read the pushbutton value into a variable //read the pushbutton value into a variable
int sensorVal = digitalRead(2); int sensorVal = digitalRead(2);
//print out the value of the pushbutton //print out the value of the pushbutton

View File

@ -24,7 +24,8 @@ const int threshold = 10; // minimum reading of the sensors that generates a
// notes to play, corresponding to the 3 sensors: // notes to play, corresponding to the 3 sensors:
int notes[] = { int notes[] = {
NOTE_A4, NOTE_B4,NOTE_C3 }; NOTE_A4, NOTE_B4, NOTE_C3
};
void setup() { void setup() {

View File

@ -15,15 +15,17 @@ This example code is in the public domain.
http://arduino.cc/en/Tutorial/Tone http://arduino.cc/en/Tutorial/Tone
*/ */
#include "pitches.h" #include "pitches.h"
// notes in the melody: // notes in the melody:
int melody[] = { int melody[] = {
NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4}; NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
};
// note durations: 4 = quarter note, 8 = eighth note, etc.: // note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = { int noteDurations[] = {
4, 8, 8, 4,4,4,4,4 }; 4, 8, 8, 4, 4, 4, 4, 4
};
void setup() { void setup() {
// iterate over the notes of the melody: // iterate over the notes of the melody:
@ -32,8 +34,8 @@ void setup() {
// to calculate the note duration, take one second // to calculate the note duration, take one second
// divided by the note type. // divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000/noteDurations[thisNote]; int noteDuration = 1000 / noteDurations[thisNote];
tone(8, melody[thisNote],noteDuration); tone(8, melody[thisNote], noteDuration);
// to distinguish the notes, set a minimum time between them. // to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well: // the note's duration + 30% seems to work well:

View File

@ -21,14 +21,14 @@ const int highestPin = 13;
void setup() { void setup() {
// set pins 2 through 13 as outputs: // set pins 2 through 13 as outputs:
for (int thisPin =lowestPin; thisPin <= highestPin; thisPin++) { for (int thisPin = lowestPin; thisPin <= highestPin; thisPin++) {
pinMode(thisPin, OUTPUT); pinMode(thisPin, OUTPUT);
} }
} }
void loop() { void loop() {
// iterate over the pins: // iterate over the pins:
for (int thisPin =lowestPin; thisPin <= highestPin; thisPin++) { for (int thisPin = lowestPin; thisPin <= highestPin; thisPin++) {
// fade the LED on thisPin from off to brightest: // fade the LED on thisPin from off to brightest:
for (int brightness = 0; brightness < 255; brightness++) { for (int brightness = 0; brightness < 255; brightness++) {
analogWrite(thisPin, brightness); analogWrite(thisPin, brightness);

View File

@ -26,7 +26,7 @@ void setup() {
void loop() { void loop() {
// fade in from min to max in increments of 5 points: // fade in from min to max in increments of 5 points:
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) { for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) {
// sets the value (range from 0 to 255): // sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue); analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect // wait for 30 milliseconds to see the dimming effect
@ -34,7 +34,7 @@ void loop() {
} }
// fade out from max to min in increments of 5 points: // fade out from max to min in increments of 5 points:
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) { for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {
// sets the value (range from 0 to 255): // sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue); analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect // wait for 30 milliseconds to see the dimming effect

View File

@ -45,11 +45,11 @@ void setup()
void loop() { void loop() {
// subtract the last reading: // subtract the last reading:
total= total - readings[index]; total = total - readings[index];
// read from the sensor: // read from the sensor:
readings[index] = analogRead(inputPin); readings[index] = analogRead(inputPin);
// add the reading to the total: // add the reading to the total:
total= total + readings[index]; total = total + readings[index];
// advance to the next position in the array: // advance to the next position in the array:
index = index + 1; index = index + 1;

View File

@ -67,9 +67,9 @@ void loop() {
Serial.println(thisByte, BIN); Serial.println(thisByte, BIN);
// if printed last visible character '~' or 126, stop: // if printed last visible character '~' or 126, stop:
if(thisByte == 126) { // you could also use if (thisByte == '~') { if (thisByte == 126) { // you could also use if (thisByte == '~') {
// This loop loops forever and does nothing // This loop loops forever and does nothing
while(true) { while (true) {
continue; continue;
} }
} }

View File

@ -48,11 +48,11 @@ void loop()
// get incoming byte: // get incoming byte:
inByte = Serial.read(); inByte = Serial.read();
// read first analog input, divide by 4 to make the range 0-255: // read first analog input, divide by 4 to make the range 0-255:
firstSensor = analogRead(A0)/4; firstSensor = analogRead(A0) / 4;
// delay 10ms to let the ADC recover: // delay 10ms to let the ADC recover:
delay(10); delay(10);
// read second analog input, divide by 4 to make the range 0-255: // read second analog input, divide by 4 to make the range 0-255:
secondSensor = analogRead(1)/4; secondSensor = analogRead(1) / 4;
// read switch, map it to 0 or 255L // read switch, map it to 0 or 255L
thirdSensor = map(digitalRead(2), 0, 1, 0, 255); thirdSensor = map(digitalRead(2), 0, 1, 0, 255);
// send sensor values: // send sensor values:

View File

@ -23,7 +23,8 @@ This example code is in the public domain.
int timer = 100; // The higher the number, the slower the timing. int timer = 100; // The higher the number, the slower the timing.
int ledPins[] = { int ledPins[] = {
2, 7, 4, 6, 5, 3 }; // an array of pin numbers to which LEDs are attached 2, 7, 4, 6, 5, 3
}; // an array of pin numbers to which LEDs are attached
int pinCount = 6; // the number of pins (i.e. the length of the array) int pinCount = 6; // the number of pins (i.e. the length of the array)
void setup() { void setup() {

View File

@ -46,7 +46,7 @@ void loop() {
digitalWrite(ledPin, HIGH); digitalWrite(ledPin, HIGH);
} }
else { else {
digitalWrite(ledPin,LOW); digitalWrite(ledPin, LOW);
} }
// print the analog value: // print the analog value:

View File

@ -43,8 +43,8 @@ void loop() {
int accelerationX, accelerationY; int accelerationX, accelerationY;
// read pulse from x- and y-axes: // read pulse from x- and y-axes:
pulseX = pulseIn(xPin,HIGH); pulseX = pulseIn(xPin, HIGH);
pulseY = pulseIn(yPin,HIGH); pulseY = pulseIn(yPin, HIGH);
// convert the pulse width into acceleration // convert the pulse width into acceleration
// accelerationX and accelerationY are in milli-g's: // accelerationX and accelerationY are in milli-g's:

View File

@ -36,11 +36,13 @@
// 2-dimensional array of row pin numbers: // 2-dimensional array of row pin numbers:
const int row[8] = { const int row[8] = {
2,7,19,5,13,18,12,16 }; 2, 7, 19, 5, 13, 18, 12, 16
};
// 2-dimensional array of column pin numbers: // 2-dimensional array of column pin numbers:
const int col[8] = { const int col[8] = {
6,11,10,3,17,4,8,9 }; 6, 11, 10, 3, 17, 4, 8, 9
};
// 2-dimensional array of pixels: // 2-dimensional array of pixels:
int pixels[8][8]; int pixels[8][8];

View File

@ -26,7 +26,8 @@ const int analogPin = A0; // the pin that the potentiometer is attached to
const int ledCount = 10; // the number of LEDs in the bar graph const int ledCount = 10; // the number of LEDs in the bar graph
int ledPins[] = { int ledPins[] = {
2, 3, 4, 5, 6, 7,8,9,10,11 }; // an array of pin numbers to which LEDs are attached 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
}; // an array of pin numbers to which LEDs are attached
void setup() { void setup() {

View File

@ -35,40 +35,40 @@ void loop() {
Serial.println(thisChar); Serial.println(thisChar);
// analyze what was sent: // analyze what was sent:
if(isAlphaNumeric(thisChar)) { if (isAlphaNumeric(thisChar)) {
Serial.println("it's alphanumeric"); Serial.println("it's alphanumeric");
} }
if(isAlpha(thisChar)) { if (isAlpha(thisChar)) {
Serial.println("it's alphabetic"); Serial.println("it's alphabetic");
} }
if(isAscii(thisChar)) { if (isAscii(thisChar)) {
Serial.println("it's ASCII"); Serial.println("it's ASCII");
} }
if(isWhitespace(thisChar)) { if (isWhitespace(thisChar)) {
Serial.println("it's whitespace"); Serial.println("it's whitespace");
} }
if(isControl(thisChar)) { if (isControl(thisChar)) {
Serial.println("it's a control character"); Serial.println("it's a control character");
} }
if(isDigit(thisChar)) { if (isDigit(thisChar)) {
Serial.println("it's a numeric digit"); Serial.println("it's a numeric digit");
} }
if(isGraph(thisChar)) { if (isGraph(thisChar)) {
Serial.println("it's a printable character that's not whitespace"); Serial.println("it's a printable character that's not whitespace");
} }
if(isLowerCase(thisChar)) { if (isLowerCase(thisChar)) {
Serial.println("it's lower case"); Serial.println("it's lower case");
} }
if(isPrintable(thisChar)) { if (isPrintable(thisChar)) {
Serial.println("it's printable"); Serial.println("it's printable");
} }
if(isPunct(thisChar)) { if (isPunct(thisChar)) {
Serial.println("it's punctuation"); Serial.println("it's punctuation");
} }
if(isSpace(thisChar)) { if (isSpace(thisChar)) {
Serial.println("it's a space character"); Serial.println("it's a space character");
} }
if(isUpperCase(thisChar)) { if (isUpperCase(thisChar)) {
Serial.println("it's upper case"); Serial.println("it's upper case");
} }
if (isHexadecimalDigit(thisChar)) { if (isHexadecimalDigit(thisChar)) {

View File

@ -59,10 +59,10 @@ void loop() {
// adding a variable long integer to a string: // adding a variable long integer to a string:
long currentTime = millis(); long currentTime = millis();
stringOne="millis() value: "; stringOne = "millis() value: ";
stringThree = stringOne + millis(); stringThree = stringOne + millis();
Serial.println(stringThree); // prints "The millis: 345345" or whatever value currentTime has Serial.println(stringThree); // prints "The millis: 345345" or whatever value currentTime has
// do nothing while true: // do nothing while true:
while(true); while (true);
} }

View File

@ -68,6 +68,6 @@ void loop() {
Serial.println(stringTwo); // prints "The millis(): 43534" or whatever the value of the millis() is Serial.println(stringTwo); // prints "The millis(): 43534" or whatever the value of the millis() is
// do nothing while true: // do nothing while true:
while(true); while (true);
} }

View File

@ -39,5 +39,5 @@ void loop() {
// do nothing while true: // do nothing while true:
while(true); while (true);
} }

View File

@ -41,6 +41,6 @@ void loop() {
Serial.println(reportString); Serial.println(reportString);
// do nothing while true: // do nothing while true:
while(true); while (true);
} }

View File

@ -116,7 +116,7 @@ void loop() {
while (true) { while (true) {
stringOne = "Sensor: "; stringOne = "Sensor: ";
stringTwo= "Sensor: "; stringTwo = "Sensor: ";
stringOne += analogRead(A0); stringOne += analogRead(A0);
stringTwo += analogRead(A5); stringTwo += analogRead(A5);

View File

@ -67,6 +67,6 @@ void loop() {
Serial.println(stringOne); Serial.println(stringOne);
// do nothing while true: // do nothing while true:
while(true); while (true);
} }

View File

@ -61,6 +61,6 @@ void loop() {
Serial.println("The index of the second last paragraph tag " + stringOne + " is " + secondLastGraf); Serial.println("The index of the second last paragraph tag " + stringOne + " is " + secondLastGraf);
// do nothing while true: // do nothing while true:
while(true); while (true);
} }

View File

@ -38,5 +38,5 @@ void loop() {
Serial.println(stringOne.length()); Serial.println(stringOne.length());
// do nothing while true: // do nothing while true:
while(true); while (true);
} }

View File

@ -46,5 +46,5 @@ void loop() {
Serial.println("l33tspeak: " + leetString); Serial.println("l33tspeak: " + leetString);
// do nothing while true: // do nothing while true:
while(true); while (true);
} }

View File

@ -51,5 +51,5 @@ void loop() {
} }
// do nothing while true: // do nothing while true:
while(true); while (true);
} }

View File

@ -34,10 +34,10 @@ void loop() {
Serial.println("It's an html file"); Serial.println("It's an html file");
} }
// you can also look for a substring in the middle of a string: // you can also look for a substring in the middle of a string:
if (stringOne.substring(14,18) == "text") { if (stringOne.substring(14, 18) == "text") {
Serial.println("It's a text-based file"); Serial.println("It's a text-based file");
} }
// do nothing while true: // do nothing while true:
while(true); while (true);
} }

View File

@ -84,7 +84,7 @@ void loop() {
} }
// do nothing: // do nothing:
while(true); while (true);
} }

View File

@ -65,7 +65,7 @@ void loop() {
Keyboard.println("digitalWrite(13, HIGH);"); Keyboard.println("digitalWrite(13, HIGH);");
Keyboard.print("delay(3000);"); Keyboard.print("delay(3000);");
// 3000 ms is too long. Delete it: // 3000 ms is too long. Delete it:
for (int keystrokes=0; keystrokes < 6; keystrokes++) { for (int keystrokes = 0; keystrokes < 6; keystrokes++) {
delay(500); delay(500);
Keyboard.write(KEY_BACKSPACE); Keyboard.write(KEY_BACKSPACE);
} }
@ -87,7 +87,7 @@ void loop() {
Keyboard.releaseAll(); Keyboard.releaseAll();
// wait for the sweet oblivion of reprogramming: // wait for the sweet oblivion of reprogramming:
while(true); while (true);
} }

View File

@ -32,7 +32,7 @@ void loop() {
// read incoming serial data: // read incoming serial data:
char inChar = Serial.read(); char inChar = Serial.read();
// Type the next ASCII value from what you received: // Type the next ASCII value from what you received:
Keyboard.write(inChar+1); Keyboard.write(inChar + 1);
} }
} }

View File

@ -55,8 +55,8 @@ void loop() {
int clickState = digitalRead(mouseButton); int clickState = digitalRead(mouseButton);
// calculate the movement distance based on the button states: // calculate the movement distance based on the button states:
int xDistance = (leftState - rightState)*range; int xDistance = (leftState - rightState) * range;
int yDistance = (upState - downState)*range; int yDistance = (upState - downState) * range;
// if X or Y is non-zero, move: // if X or Y is non-zero, move:
if ((xDistance != 0) || (yDistance != 0)) { if ((xDistance != 0) || (yDistance != 0)) {

View File

@ -38,8 +38,8 @@ const int ledPin = 5; // Mouse control LED
// parameters for reading the joystick: // parameters for reading the joystick:
int range = 12; // output range of X or Y movement int range = 12; // output range of X or Y movement
int responseDelay = 5; // response delay of the mouse, in ms int responseDelay = 5; // response delay of the mouse, in ms
int threshold = range/4; // resting threshold int threshold = range / 4; // resting threshold
int center = range/2; // resting position value int center = range / 2; // resting position value
boolean mouseIsActive = false; // whether or not to control the mouse boolean mouseIsActive = false; // whether or not to control the mouse
int lastSwitchState = LOW; // previous switch state int lastSwitchState = LOW; // previous switch state

View File

@ -26,17 +26,17 @@
// switchState, youre talking about the number it holds // switchState, youre talking about the number it holds
int switchstate = 0; int switchstate = 0;
void setup(){ void setup() {
// declare the LED pins as outputs // declare the LED pins as outputs
pinMode(3,OUTPUT); pinMode(3, OUTPUT);
pinMode(4,OUTPUT); pinMode(4, OUTPUT);
pinMode(5,OUTPUT); pinMode(5, OUTPUT);
// declare the switch pin as an input // declare the switch pin as an input
pinMode(2,INPUT); pinMode(2, INPUT);
} }
void loop(){ void loop() {
// read the value of the switch // read the value of the switch
// digitalRead() checks to see if there is voltage // digitalRead() checks to see if there is voltage

View File

@ -23,18 +23,18 @@ const int sensorPin = A0;
// room temperature in Celcius // room temperature in Celcius
const float baselineTemp = 20.0; const float baselineTemp = 20.0;
void setup(){ void setup() {
// open a serial connection to display values // open a serial connection to display values
Serial.begin(9600); Serial.begin(9600);
// set the LED pins as outputs // set the LED pins as outputs
// the for() loop saves some extra coding // the for() loop saves some extra coding
for(int pinNumber = 2; pinNumber<5; pinNumber++){ for (int pinNumber = 2; pinNumber < 5; pinNumber++) {
pinMode(pinNumber,OUTPUT); pinMode(pinNumber, OUTPUT);
digitalWrite(pinNumber, LOW); digitalWrite(pinNumber, LOW);
} }
} }
void loop(){ void loop() {
// read the value on AnalogIn pin 0 // read the value on AnalogIn pin 0
// and store it in a variable // and store it in a variable
int sensorVal = analogRead(sensorPin); int sensorVal = analogRead(sensorPin);
@ -44,7 +44,7 @@ void loop(){
Serial.print(sensorVal); Serial.print(sensorVal);
// convert the ADC reading to voltage // convert the ADC reading to voltage
float voltage = (sensorVal/1024.0) * 5.0; float voltage = (sensorVal / 1024.0) * 5.0;
// Send the voltage level out the Serial port // Send the voltage level out the Serial port
Serial.print(", Volts: "); Serial.print(", Volts: ");
@ -60,22 +60,22 @@ void loop(){
// if the current temperature is lower than the baseline // if the current temperature is lower than the baseline
// turn off all LEDs // turn off all LEDs
if(temperature < baselineTemp){ if (temperature < baselineTemp) {
digitalWrite(2, LOW); digitalWrite(2, LOW);
digitalWrite(3, LOW); digitalWrite(3, LOW);
digitalWrite(4, LOW); digitalWrite(4, LOW);
} // if the temperature rises 2-4 degrees, turn an LED on } // if the temperature rises 2-4 degrees, turn an LED on
else if(temperature >= baselineTemp+2 && temperature < baselineTemp+4){ else if (temperature >= baselineTemp + 2 && temperature < baselineTemp + 4) {
digitalWrite(2, HIGH); digitalWrite(2, HIGH);
digitalWrite(3, LOW); digitalWrite(3, LOW);
digitalWrite(4, LOW); digitalWrite(4, LOW);
} // if the temperature rises 4-6 degrees, turn a second LED on } // if the temperature rises 4-6 degrees, turn a second LED on
else if(temperature >= baselineTemp+4 && temperature < baselineTemp+6){ else if (temperature >= baselineTemp + 4 && temperature < baselineTemp + 6) {
digitalWrite(2, HIGH); digitalWrite(2, HIGH);
digitalWrite(3, HIGH); digitalWrite(3, HIGH);
digitalWrite(4, LOW); digitalWrite(4, LOW);
} // if the temperature rises more than 6 degrees, turn all LEDs on } // if the temperature rises more than 6 degrees, turn all LEDs on
else if(temperature >= baselineTemp+6){ else if (temperature >= baselineTemp + 6) {
digitalWrite(2, HIGH); digitalWrite(2, HIGH);
digitalWrite(3, HIGH); digitalWrite(3, HIGH);
digitalWrite(4, HIGH); digitalWrite(4, HIGH);

View File

@ -43,9 +43,9 @@ void setup() {
Serial.begin(9600); Serial.begin(9600);
// set the digital pins as outputs // set the digital pins as outputs
pinMode(greenLEDPin,OUTPUT); pinMode(greenLEDPin, OUTPUT);
pinMode(redLEDPin,OUTPUT); pinMode(redLEDPin, OUTPUT);
pinMode(blueLEDPin,OUTPUT); pinMode(blueLEDPin, OUTPUT);
} }
void loop() { void loop() {
@ -76,9 +76,9 @@ void loop() {
but analogWrite() uses 8 bits. You'll want to divide your but analogWrite() uses 8 bits. You'll want to divide your
sensor readings by 4 to keep them in range of the output. sensor readings by 4 to keep them in range of the output.
*/ */
redValue = redSensorValue/4; redValue = redSensorValue / 4;
greenValue = greenSensorValue/4; greenValue = greenSensorValue / 4;
blueValue = blueSensorValue/4; blueValue = blueSensorValue / 4;
// print out the mapped values // print out the mapped values
Serial.print("Mapped sensor Values \t red: "); Serial.print("Mapped sensor Values \t red: ");

View File

@ -37,23 +37,23 @@ void loop() {
Serial.println(keyVal); Serial.println(keyVal);
// play the note corresponding to each value on A0 // play the note corresponding to each value on A0
if(keyVal == 1023){ if (keyVal == 1023) {
// play the first frequency in the array on pin 8 // play the first frequency in the array on pin 8
tone(8, notes[0]); 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 // play the second frequency in the array on pin 8
tone(8, notes[1]); 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 // play the third frequency in the array on pin 8
tone(8, notes[2]); 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 // play the fourth frequency in the array on pin 8
tone(8, notes[3]); tone(8, notes[3]);
} }
else{ else {
// if the value is out of range, play no tone // if the value is out of range, play no tone
noTone(8); noTone(8);
} }

View File

@ -32,20 +32,20 @@ long interval = 600000; // interval at which to light the next LED
void setup() { void setup() {
// set the LED pins as outputs // set the LED pins as outputs
for(int x = 2;x<8;x++){ for (int x = 2; x < 8; x++) {
pinMode(x, OUTPUT); pinMode(x, OUTPUT);
} }
// set the tilt switch pin as input // set the tilt switch pin as input
pinMode(switchPin, INPUT); pinMode(switchPin, INPUT);
} }
void loop(){ void loop() {
// store the time since the Arduino started running in a variable // store the time since the Arduino started running in a variable
unsigned long currentTime = millis(); unsigned long currentTime = millis();
// compare the current time to the previous time an LED turned on // compare the current time to the previous time an LED turned on
// if it is greater than your interval, run the if statement // if it is greater than your interval, run the if statement
if(currentTime - previousTime > interval) { if (currentTime - previousTime > interval) {
// save the current time as the last time you changed an LED // save the current time as the last time you changed an LED
previousTime = currentTime; previousTime = currentTime;
// Turn the LED on // Turn the LED on
@ -54,7 +54,7 @@ void loop(){
// in 10 minutes the next LED will light up // in 10 minutes the next LED will light up
led++; led++;
if(led == 7){ if (led == 7) {
// the hour is up // the hour is up
} }
} }
@ -63,9 +63,9 @@ void loop(){
switchState = digitalRead(switchPin); switchState = digitalRead(switchPin);
// if the switch has changed // if the switch has changed
if(switchState != prevSwitchState){ if (switchState != prevSwitchState) {
// turn all the LEDs low // turn all the LEDs low
for(int x = 2;x<8;x++){ for (int x = 2; x < 8; x++) {
digitalWrite(x, LOW); digitalWrite(x, LOW);
} }

View File

@ -34,7 +34,7 @@ void setup() {
pinMode(switchPin, INPUT); pinMode(switchPin, INPUT);
} }
void loop(){ void loop() {
// read the state of the switch value: // read the state of the switch value:
switchState = digitalRead(switchPin); switchState = digitalRead(switchPin);

View File

@ -39,7 +39,7 @@ int motorEnabled = 0; // Turns the motor on/off
int motorSpeed = 0; // speed of the motor int motorSpeed = 0; // speed of the motor
int motorDirection = 1; // current direction of the motor int motorDirection = 1; // current direction of the motor
void setup(){ void setup() {
// intialize the inputs and outputs // intialize the inputs and outputs
pinMode(directionSwitchPin, INPUT); pinMode(directionSwitchPin, INPUT);
pinMode(onOffSwitchStateSwitchPin, INPUT); pinMode(onOffSwitchStateSwitchPin, INPUT);
@ -51,7 +51,7 @@ void setup(){
digitalWrite(enablePin, LOW); digitalWrite(enablePin, LOW);
} }
void loop(){ void loop() {
// read the value of the on/off switch // read the value of the on/off switch
onOffSwitchState = digitalRead(onOffSwitchStateSwitchPin); onOffSwitchState = digitalRead(onOffSwitchStateSwitchPin);
delay(1); delay(1);
@ -61,12 +61,12 @@ void loop(){
// read the value of the pot and divide by 4 to get // read the value of the pot and divide by 4 to get
// a value that can be used for PWM // a value that can be used for PWM
motorSpeed = analogRead(potPin)/4; motorSpeed = analogRead(potPin) / 4;
// if the on/off button changed state since the last loop() // if the on/off button changed state since the last loop()
if(onOffSwitchState != previousOnOffSwitchState){ if (onOffSwitchState != previousOnOffSwitchState) {
// change the value of motorEnabled if pressed // change the value of motorEnabled if pressed
if(onOffSwitchState == HIGH){ if (onOffSwitchState == HIGH) {
motorEnabled = !motorEnabled; motorEnabled = !motorEnabled;
} }
} }

View File

@ -44,7 +44,7 @@ void setup() {
lcd.begin(16, 2); lcd.begin(16, 2);
// set up the switch pin as an input // set up the switch pin as an input
pinMode(switchPin,INPUT); pinMode(switchPin, INPUT);
// Print a message to the LCD. // Print a message to the LCD.
lcd.print("Ask the"); lcd.print("Ask the");
@ -77,7 +77,7 @@ void loop() {
lcd.setCursor(0, 1); lcd.setCursor(0, 1);
// choose a saying to print baed on the value in reply // choose a saying to print baed on the value in reply
switch(reply){ switch (reply) {
case 0: case 0:
lcd.print("Yes"); lcd.print("Yes");
break; break;

View File

@ -51,7 +51,7 @@ boolean locked = false;
// how many valid knocks you've received // how many valid knocks you've received
int numberOfKnocks = 0; int numberOfKnocks = 0;
void setup(){ void setup() {
// attach the servo to pin 9 // attach the servo to pin 9
myServo.attach(9); myServo.attach(9);
@ -76,22 +76,22 @@ void setup(){
Serial.println("the box is unlocked!"); Serial.println("the box is unlocked!");
} }
void loop(){ void loop() {
// if the box is unlocked // if the box is unlocked
if(locked == false){ if (locked == false) {
// read the value of the switch pin // read the value of the switch pin
switchVal = digitalRead(switchPin); switchVal = digitalRead(switchPin);
// if the button is pressed, lock the box // if the button is pressed, lock the box
if(switchVal == HIGH){ if (switchVal == HIGH) {
// set the locked variable to "true" // set the locked variable to "true"
locked = true; locked = true;
// change the status LEDs // change the status LEDs
digitalWrite(greenLed,LOW); digitalWrite(greenLed, LOW);
digitalWrite(redLed,HIGH); digitalWrite(redLed, HIGH);
// move the servo to the locked position // move the servo to the locked position
myServo.write(90); myServo.write(90);
@ -105,16 +105,16 @@ void loop(){
} }
// if the box is locked // if the box is locked
if(locked == true){ if (locked == true) {
// check the value of the piezo // check the value of the piezo
knockVal = analogRead(piezo); knockVal = analogRead(piezo);
// if there are not enough valid knocks // if there are not enough valid knocks
if(numberOfKnocks < 3 && knockVal > 0){ if (numberOfKnocks < 3 && knockVal > 0) {
// check to see if the knock is in range // check to see if the knock is in range
if(checkForKnock(knockVal) == true){ if (checkForKnock(knockVal) == true) {
// increment the number of valid knocks // increment the number of valid knocks
numberOfKnocks++; numberOfKnocks++;
@ -126,7 +126,7 @@ void loop(){
} }
// if there are three knocks // if there are three knocks
if(numberOfKnocks >= 3){ if (numberOfKnocks >= 3) {
// unlock the box // unlock the box
locked = false; locked = false;
@ -137,8 +137,8 @@ void loop(){
delay(20); delay(20);
// change status LEDs // change status LEDs
digitalWrite(greenLed,HIGH); digitalWrite(greenLed, HIGH);
digitalWrite(redLed,LOW); digitalWrite(redLed, LOW);
Serial.println("the box is unlocked!"); Serial.println("the box is unlocked!");
} }
} }
@ -146,10 +146,10 @@ void loop(){
// this function checks to see if a // this function checks to see if a
// detected knock is within max and min range // detected knock is within max and min range
boolean checkForKnock(int value){ boolean checkForKnock(int value) {
// if the value of the knock is greater than // if the value of the knock is greater than
// the minimum, and larger than the maximum // the minimum, and larger than the maximum
if(value > quietKnock && value < loudKnock){ if (value > quietKnock && value < loudKnock) {
// turn the status LED on // turn the status LED on
digitalWrite(yellowLed, HIGH); digitalWrite(yellowLed, HIGH);
delay(50); delay(50);

View File

@ -30,7 +30,7 @@
// create an instance of the library // create an instance of the library
// pin 4 sends electrical energy // pin 4 sends electrical energy
// pin 2 senses senses a change // pin 2 senses senses a change
CapacitiveSensor capSensor = CapacitiveSensor(4,2); CapacitiveSensor capSensor = CapacitiveSensor(4, 2);
// threshold for turning the lamp on // threshold for turning the lamp on
int threshold = 1000; int threshold = 1000;
@ -54,7 +54,7 @@ void loop() {
Serial.println(sensorValue); Serial.println(sensorValue);
// if the value is greater than the threshold // if the value is greater than the threshold
if(sensorValue > threshold) { if (sensorValue > threshold) {
// turn the LED on // turn the LED on
digitalWrite(ledPin, HIGH); digitalWrite(ledPin, HIGH);
} }

View File

@ -29,7 +29,7 @@ void setup() {
void loop() { void loop() {
// read the value of A0, divide by 4 and // read the value of A0, divide by 4 and
// send it as a byte over the serial connection // send it as a byte over the serial connection
Serial.write(analogRead(A0)/4); Serial.write(analogRead(A0) / 4);
delay(1); delay(1);
} }

View File

@ -20,12 +20,12 @@
const int optoPin = 2; // the pin the optocoupler is connected to const int optoPin = 2; // the pin the optocoupler is connected to
void setup(){ void setup() {
// make the pin with the optocoupler an output // make the pin with the optocoupler an output
pinMode(optoPin, OUTPUT); pinMode(optoPin, OUTPUT);
} }
void loop(){ void loop() {
digitalWrite(optoPin, HIGH); // pull pin 2 HIGH, activating the optocoupler digitalWrite(optoPin, HIGH); // pull pin 2 HIGH, activating the optocoupler
delay(15); // give the optocoupler a moment to activate delay(15); // give the optocoupler a moment to activate

View File

@ -75,8 +75,8 @@ void setup() {
pulse(LED_HB, 2); pulse(LED_HB, 2);
} }
int error=0; int error = 0;
int pmode=0; int pmode = 0;
// address for reading and writing, set by 'U' command // address for reading and writing, set by 'U' command
int here; int here;
uint8_t buff[256]; // global block storage uint8_t buff[256]; // global block storage
@ -102,8 +102,8 @@ parameter;
parameter param; parameter param;
// this provides a heartbeat on pin 9, so you can tell the software is running. // this provides a heartbeat on pin 9, so you can tell the software is running.
uint8_t hbval=128; uint8_t hbval = 128;
int8_t hbdelta=8; int8_t hbdelta = 8;
void heartbeat() { void heartbeat() {
if (hbval > 192) hbdelta = -hbdelta; if (hbval > 192) hbdelta = -hbdelta;
if (hbval < 32) hbdelta = -hbdelta; if (hbval < 32) hbdelta = -hbdelta;
@ -129,7 +129,7 @@ void loop(void) {
} }
uint8_t getch() { uint8_t getch() {
while(!Serial.available()); while (!Serial.available());
return Serial.read(); return Serial.read();
} }
void fill(int n) { void fill(int n) {
@ -157,8 +157,8 @@ void prog_lamp(int state) {
void spi_init() { void spi_init() {
uint8_t x; uint8_t x;
SPCR = 0x53; SPCR = 0x53;
x=SPSR; x = SPSR;
x=SPDR; x = SPDR;
} }
void spi_wait() { void spi_wait() {
@ -169,7 +169,7 @@ void spi_wait() {
uint8_t spi_send(uint8_t b) { uint8_t spi_send(uint8_t b) {
uint8_t reply; uint8_t reply;
SPDR=b; SPDR = b;
spi_wait(); spi_wait();
reply = SPDR; reply = SPDR;
return reply; return reply;
@ -178,9 +178,9 @@ uint8_t spi_send(uint8_t b) {
uint8_t spi_transaction(uint8_t a, uint8_t b, uint8_t c, uint8_t d) { uint8_t spi_transaction(uint8_t a, uint8_t b, uint8_t c, uint8_t d) {
uint8_t n; uint8_t n;
spi_send(a); spi_send(a);
n=spi_send(b); n = spi_send(b);
//if (n != a) error = -1; //if (n != a) error = -1;
n=spi_send(c); n = spi_send(c);
return spi_send(d); return spi_send(d);
} }
@ -208,7 +208,7 @@ void breply(uint8_t b) {
} }
void get_version(uint8_t c) { void get_version(uint8_t c) {
switch(c) { switch (c) {
case 0x80: case 0x80:
breply(HWVER); breply(HWVER);
break; break;
@ -285,8 +285,8 @@ void universal() {
} }
void flash(uint8_t hilo, int addr, uint8_t data) { void flash(uint8_t hilo, int addr, uint8_t data) {
spi_transaction(0x40+8*hilo, spi_transaction(0x40 + 8 * hilo,
addr>>8 & 0xFF, addr >> 8 & 0xFF,
addr & 0xFF, addr & 0xFF,
data); data);
} }
@ -363,8 +363,8 @@ uint8_t write_eeprom_chunk(int start, int length) {
fill(length); fill(length);
prog_lamp(LOW); prog_lamp(LOW);
for (int x = 0; x < length; x++) { for (int x = 0; x < length; x++) {
int addr = start+x; int addr = start + x;
spi_transaction(0xC0, (addr>>8) & 0xFF, addr & 0xFF, buff[x]); spi_transaction(0xC0, (addr >> 8) & 0xFF, addr & 0xFF, buff[x]);
delay(45); delay(45);
} }
prog_lamp(HIGH); prog_lamp(HIGH);
@ -405,7 +405,7 @@ uint8_t flash_read(uint8_t hilo, int addr) {
} }
char flash_read_page(int length) { char flash_read_page(int length) {
for (int x = 0; x < length; x+=2) { for (int x = 0; x < length; x += 2) {
uint8_t low = flash_read(LOW, here); uint8_t low = flash_read(LOW, here);
Serial.print((char) low); Serial.print((char) low);
uint8_t high = flash_read(HIGH, here); uint8_t high = flash_read(HIGH, here);
@ -524,7 +524,7 @@ int avrisp() {
universal(); universal();
break; break;
case 'Q': //0x51 case 'Q': //0x51
error=0; error = 0;
end_pmode(); end_pmode();
empty_reply(); empty_reply();
break; break;

View File

@ -44,7 +44,7 @@ void setup()
void loop() void loop()
{ {
int count=0; int count = 0;
// open wave file from sdcard // open wave file from sdcard
File myFile = SD.open("test.wav"); File myFile = SD.open("test.wav");
@ -54,7 +54,7 @@ void loop()
while (true); while (true);
} }
const int S=1024; // Number of samples to read in block const int S = 1024; // Number of samples to read in block
short buffer[S]; short buffer[S];
Serial.print("Playing"); Serial.print("Playing");

View File

@ -32,7 +32,7 @@ YunServer server;
void setup() { void setup() {
// Bridge startup // Bridge startup
pinMode(13,OUTPUT); pinMode(13, OUTPUT);
digitalWrite(13, LOW); digitalWrite(13, LOW);
Bridge.begin(); Bridge.begin();
digitalWrite(13, HIGH); digitalWrite(13, HIGH);

View File

@ -81,12 +81,12 @@ void loop() {
Console.println(thisByte, BIN); Console.println(thisByte, BIN);
// if printed last visible character '~' or 126, stop: // if printed last visible character '~' or 126, stop:
if(thisByte == 126) { // you could also use if (thisByte == '~') { if (thisByte == 126) { // you could also use if (thisByte == '~') {
// ensure the latest bit of data is sent // ensure the latest bit of data is sent
Console.flush(); Console.flush();
// This loop loops forever and does nothing // This loop loops forever and does nothing
while(true) { while (true) {
continue; continue;
} }
} }

View File

@ -37,7 +37,7 @@ void setup() {
Console.begin(); // Initialize Console Console.begin(); // Initialize Console
// Wait for the Console port to connect // Wait for the Console port to connect
while(!Console); while (!Console);
Console.println("type H or L to turn pin 13 on or off"); Console.println("type H or L to turn pin 13 on or off");

View File

@ -38,7 +38,7 @@ void setup() {
Serial.begin(9600); Serial.begin(9600);
FileSystem.begin(); FileSystem.begin();
while(!Serial); // wait for Serial port to connect. while (!Serial); // wait for Serial port to connect.
Serial.println("Filesystem datalogger\n"); Serial.println("Filesystem datalogger\n");
} }
@ -91,9 +91,9 @@ String getTimeStamp() {
time.run(); // run the command time.run(); // run the command
// read the output of the command // read the output of the command
while(time.available()>0) { while (time.available() > 0) {
char c = time.read(); char c = time.read();
if(c != '\n') if (c != '\n')
result += c; result += c;
} }

View File

@ -21,7 +21,7 @@ void setup() {
// Initialize the Serial // Initialize the Serial
Serial.begin(9600); Serial.begin(9600);
while(!Serial); // wait for Serial port to connect. while (!Serial); // wait for Serial port to connect.
Serial.println("File Write Script example\n\n"); Serial.println("File Write Script example\n\n");
// Setup File IO // Setup File IO

View File

@ -29,7 +29,7 @@ void setup() {
Serial.begin(9600); Serial.begin(9600);
while(!Serial); // wait for a serial connection while (!Serial); // wait for a serial connection
} }
void loop() { void loop() {

View File

@ -44,7 +44,7 @@ void runCurl() {
// Print arduino logo over the Serial // Print arduino logo over the Serial
// A process output can be read with the stream methods // A process output can be read with the stream methods
while (p.available()>0) { while (p.available() > 0) {
char c = p.read(); char c = p.read();
Serial.print(c); Serial.print(c);
} }
@ -62,7 +62,7 @@ void runCpuInfo() {
// Print command output on the Serial. // Print command output on the Serial.
// A process output can be read with the stream methods // A process output can be read with the stream methods
while (p.available()>0) { while (p.available() > 0) {
char c = p.read(); char c = p.read();
Serial.print(c); Serial.print(c);
} }

View File

@ -28,7 +28,7 @@ void setup() {
Serial.begin(9600); // Initialize the Serial Serial.begin(9600); // Initialize the Serial
// Wait until a Serial Monitor is connected. // Wait until a Serial Monitor is connected.
while(!Serial); while (!Serial);
} }
void loop() { void loop() {
@ -39,7 +39,7 @@ void loop() {
p.runShellCommand("/usr/bin/pretty-wifi-info.lua | grep Signal"); p.runShellCommand("/usr/bin/pretty-wifi-info.lua | grep Signal");
// do nothing until the process finishes, so you get the whole output: // do nothing until the process finishes, so you get the whole output:
while(p.running()); while (p.running());
// Read command output. runShellCommand() should have passed "Signal: xx&": // Read command output. runShellCommand() should have passed "Signal: xx&":
while (p.available()) { while (p.available()) {

View File

@ -40,7 +40,9 @@ void setup() {
// for debugging, wait until a serial console is connected // for debugging, wait until a serial console is connected
delay(4000); delay(4000);
while (!Serial) { ; } while (!Serial) {
;
}
// start-up the bridge // start-up the bridge
Bridge.begin(); Bridge.begin();

View File

@ -40,7 +40,9 @@ void setup() {
// for debugging, wait until a serial console is connected // for debugging, wait until a serial console is connected
delay(4000); delay(4000);
while (!Serial) { ; } while (!Serial) {
;
}
// start-up the bridge // start-up the bridge
Bridge.begin(); Bridge.begin();

View File

@ -41,7 +41,9 @@ void setup() {
// for debugging, wait until a serial console is connected // for debugging, wait until a serial console is connected
delay(4000); delay(4000);
while (!Serial) { ; } while (!Serial) {
;
}
// start-up the bridge // start-up the bridge
Bridge.begin(); Bridge.begin();

View File

@ -38,7 +38,9 @@ void setup() {
// for debugging, wait until a serial console is connected // for debugging, wait until a serial console is connected
delay(4000); delay(4000);
while (!Serial) { ; } while (!Serial) {
;
}
// start-up the bridge // start-up the bridge
Bridge.begin(); Bridge.begin();

View File

@ -55,7 +55,7 @@
#include <Bridge.h> #include <Bridge.h>
#include <Temboo.h> #include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information #include "TembooAccount.h" // contains Temboo account information
// as described in the footer comment below // as described in the footer comment below
@ -98,7 +98,7 @@ void setup() {
// for debugging, wait until a serial console is connected // for debugging, wait until a serial console is connected
delay(4000); delay(4000);
while(!Serial); while (!Serial);
// tell the board to treat the LED pin as an output. // tell the board to treat the LED pin as an output.
pinMode(LED_PIN, OUTPUT); pinMode(LED_PIN, OUTPUT);
@ -214,7 +214,7 @@ void checkForMessages(bool ignoreCommands) {
// lists containing the Sids and texts of the messages // lists containing the Sids and texts of the messages
// from our designated phone number. // from our designated phone number.
while(ListMessagesChoreo.available()) { while (ListMessagesChoreo.available()) {
// output names are terminated with '\x1F' characters. // output names are terminated with '\x1F' characters.
String name = ListMessagesChoreo.readStringUntil('\x1F'); String name = ListMessagesChoreo.readStringUntil('\x1F');
@ -243,7 +243,7 @@ void checkForMessages(bool ignoreCommands) {
} else { } else {
// a non-zero return code means there was an error // a non-zero return code means there was an error
// read and print the error message // read and print the error message
while(ListMessagesChoreo.available()) { while (ListMessagesChoreo.available()) {
char c = ListMessagesChoreo.read(); char c = ListMessagesChoreo.read();
Serial.print(c); Serial.print(c);
} }
@ -333,7 +333,7 @@ void processMessages(String messageTexts, String messageSids, bool ignoreCommand
// keep going until either we run out of list items // keep going until either we run out of list items
// or we run into a message we processed on a previous run. // or we run into a message we processed on a previous run.
} while ((i >=0) && (sid != lastSid)); } while ((i >= 0) && (sid != lastSid));
// print what we've found to the serial monitor, // print what we've found to the serial monitor,
// just so we can see what's going on. // just so we can see what's going on.

View File

@ -20,7 +20,7 @@
#include <Bridge.h> #include <Bridge.h>
#include <Temboo.h> #include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information #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 // the address for which a weather forecast will be retrieved
@ -35,7 +35,7 @@ void setup() {
// for debugging, wait until a serial console is connected // for debugging, wait until a serial console is connected
delay(4000); delay(4000);
while(!Serial); while (!Serial);
Bridge.begin(); Bridge.begin();
} }
@ -79,7 +79,7 @@ void loop()
GetWeatherByAddressChoreo.run(); GetWeatherByAddressChoreo.run();
// when the choreo results are available, print them to the serial monitor // when the choreo results are available, print them to the serial monitor
while(GetWeatherByAddressChoreo.available()) { while (GetWeatherByAddressChoreo.available()) {
char c = GetWeatherByAddressChoreo.read(); char c = GetWeatherByAddressChoreo.read();
Serial.print(c); Serial.print(c);

View File

@ -27,7 +27,7 @@
#include <Bridge.h> #include <Bridge.h>
#include <Temboo.h> #include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information #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: ***/ /*** SUBSTITUTE YOUR VALUES BELOW: ***/
@ -46,7 +46,7 @@ void setup() {
// For debugging, wait until a serial console is connected. // For debugging, wait until a serial console is connected.
delay(4000); delay(4000);
while(!Serial); while (!Serial);
Bridge.begin(); Bridge.begin();
} }
void loop() void loop()
@ -99,7 +99,7 @@ void loop()
unsigned int returnCode = HomeTimelineChoreo.run(); unsigned int returnCode = HomeTimelineChoreo.run();
// a response code of 0 means success; print the API response // a response code of 0 means success; print the API response
if(returnCode == 0) { if (returnCode == 0) {
String author; // a String to hold the tweet author's name String author; // a String to hold the tweet author's name
String tweet; // a String to hold the text of the tweet String tweet; // a String to hold the text of the tweet
@ -115,7 +115,7 @@ void loop()
// see the examples at http://www.temboo.com/arduino for more details // see the examples at http://www.temboo.com/arduino for more details
// we can read this format into separate variables, as follows: // we can read this format into separate variables, as follows:
while(HomeTimelineChoreo.available()) { while (HomeTimelineChoreo.available()) {
// read the name of the output item // read the name of the output item
String name = HomeTimelineChoreo.readStringUntil('\x1F'); String name = HomeTimelineChoreo.readStringUntil('\x1F');
name.trim(); name.trim();
@ -137,7 +137,7 @@ void loop()
} else { } else {
// there was an error // there was an error
// print the raw output from the choreo // print the raw output from the choreo
while(HomeTimelineChoreo.available()) { while (HomeTimelineChoreo.available()) {
char c = HomeTimelineChoreo.read(); char c = HomeTimelineChoreo.read();
Serial.print(c); Serial.print(c);
} }

View File

@ -28,7 +28,7 @@
#include <Bridge.h> #include <Bridge.h>
#include <Temboo.h> #include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information #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: ***/ /*** SUBSTITUTE YOUR VALUES BELOW: ***/
@ -48,7 +48,7 @@ void setup() {
// for debugging, wait until a serial console is connected // for debugging, wait until a serial console is connected
delay(4000); delay(4000);
while(!Serial); while (!Serial);
Bridge.begin(); Bridge.begin();
} }

View File

@ -24,7 +24,7 @@
#include <Bridge.h> #include <Bridge.h>
#include <Temboo.h> #include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information #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: ***/ /*** SUBSTITUTE YOUR VALUES BELOW: ***/
@ -48,7 +48,7 @@ void setup() {
// for debugging, wait until a serial console is connected // for debugging, wait until a serial console is connected
delay(4000); delay(4000);
while(!Serial); while (!Serial);
Bridge.begin(); Bridge.begin();
} }

View File

@ -33,7 +33,7 @@
#include <Bridge.h> #include <Bridge.h>
#include <Temboo.h> #include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information #include "TembooAccount.h" // contains Temboo account information
// as described in the footer comment below // as described in the footer comment below
@ -62,7 +62,7 @@ void setup() {
// for debugging, wait until a serial console is connected // for debugging, wait until a serial console is connected
delay(4000); delay(4000);
while(!Serial); while (!Serial);
Bridge.begin(); Bridge.begin();
} }
@ -128,7 +128,7 @@ void loop()
SendSMSChoreo.close(); SendSMSChoreo.close();
// set the flag indicatine we've tried once. // set the flag indicatine we've tried once.
attempted=true; attempted = true;
} }
} }

View File

@ -38,7 +38,7 @@
#include <Bridge.h> #include <Bridge.h>
#include <Temboo.h> #include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information, #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: ***/ /*** SUBSTITUTE YOUR VALUES BELOW: ***/
@ -60,14 +60,14 @@ const unsigned long RUN_INTERVAL_MILLIS = 60000; // how often to run the Choreo
// the last time we ran the Choreo // the last time we ran the Choreo
// (initialized to 60 seconds ago so the // (initialized to 60 seconds ago so the
// Choreo is run immediately when we start up) // Choreo is run immediately when we start up)
unsigned long lastRun = (unsigned long)-60000; unsigned long lastRun = (unsigned long) - 60000;
void setup() { void setup() {
// for debugging, wait until a serial console is connected // for debugging, wait until a serial console is connected
Serial.begin(9600); Serial.begin(9600);
delay(4000); delay(4000);
while(!Serial); while (!Serial);
Serial.print("Initializing the bridge..."); Serial.print("Initializing the bridge...");
Bridge.begin(); Bridge.begin();

View File

@ -22,7 +22,7 @@
#include <Bridge.h> #include <Bridge.h>
#include <Temboo.h> #include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information #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 // the zip code to search for toxin-emitting facilities
String US_ZIP_CODE = "11215"; String US_ZIP_CODE = "11215";
@ -35,7 +35,7 @@ void setup() {
// for debugging, wait until a serial console is connected // for debugging, wait until a serial console is connected
delay(4000); delay(4000);
while(!Serial); while (!Serial);
Bridge.begin(); Bridge.begin();
} }
@ -83,7 +83,7 @@ void loop()
// the output filters we specified will return comma delimited // the output filters we specified will return comma delimited
// lists containing the name and street address of the facilities // lists containing the name and street address of the facilities
// located in the specified zip code. // located in the specified zip code.
while(FacilitiesSearchByZipChoreo.available()) { while (FacilitiesSearchByZipChoreo.available()) {
String name = FacilitiesSearchByZipChoreo.readStringUntil('\x1F'); String name = FacilitiesSearchByZipChoreo.readStringUntil('\x1F');
name.trim(); name.trim();
@ -123,7 +123,7 @@ void loop()
printResult(facility, address); printResult(facility, address);
} }
}while (i >= 0); } while (i >= 0);
facility = facilities.substring(facilityStart); facility = facilities.substring(facilityStart);
address = addresses.substring(addressStart); address = addresses.substring(addressStart);
printResult(facility, address); printResult(facility, address);
@ -131,7 +131,7 @@ void loop()
Serial.println("No facilities found in zip code " + US_ZIP_CODE); Serial.println("No facilities found in zip code " + US_ZIP_CODE);
} }
} else { } else {
while(FacilitiesSearchByZipChoreo.available()) { while (FacilitiesSearchByZipChoreo.available()) {
char c = FacilitiesSearchByZipChoreo.read(); char c = FacilitiesSearchByZipChoreo.read();
Serial.print(c); Serial.print(c);
} }

View File

@ -27,7 +27,7 @@
#include <Bridge.h> #include <Bridge.h>
#include <Temboo.h> #include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information, #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: ***/ /*** SUBSTITUTE YOUR VALUES BELOW: ***/
@ -46,7 +46,7 @@ void setup() {
// For debugging, wait until a serial console is connected. // For debugging, wait until a serial console is connected.
delay(4000); delay(4000);
while(!Serial); while (!Serial);
Bridge.begin(); Bridge.begin();
} }
@ -96,7 +96,7 @@ void loop() {
// note that in this case, we're just printing the raw response from Facebook. // 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 // see the examples on using Temboo SDK output filters at http://www.temboo.com/arduino
// for information on how to filter this data // for information on how to filter this data
while(SetStatusChoreo.available()) { while (SetStatusChoreo.available()) {
char c = SetStatusChoreo.read(); char c = SetStatusChoreo.read();
Serial.print(c); Serial.print(c);
} }

View File

@ -32,7 +32,7 @@
#include <Bridge.h> #include <Bridge.h>
#include <Temboo.h> #include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information #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: ***/ /*** SUBSTITUTE YOUR VALUES BELOW: ***/
@ -60,7 +60,7 @@ void setup() {
// For debugging, wait until a serial console is connected. // For debugging, wait until a serial console is connected.
delay(4000); delay(4000);
while(!Serial); while (!Serial);
Bridge.begin(); Bridge.begin();
} }
@ -103,7 +103,7 @@ void loop()
// next, the root folder on Dropbox relative to which the file path is specified. // 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" // 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" // 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 // next, the Base64 encoded file data to upload
UploadFileChoreo.addInput("FileContents", base64EncodedData); UploadFileChoreo.addInput("FileContents", base64EncodedData);
@ -171,7 +171,7 @@ String base64Encode(String toEncode) {
// read in the choreo results, and return the "Base64EncodedText" output value. // read in the choreo results, and return the "Base64EncodedText" output value.
// see http://www.temboo.com/arduino for more details on using choreo outputs. // see http://www.temboo.com/arduino for more details on using choreo outputs.
while(Base64EncodeChoreo.available()) { while (Base64EncodeChoreo.available()) {
// read the name of the output item // read the name of the output item
String name = Base64EncodeChoreo.readStringUntil('\x1F'); String name = Base64EncodeChoreo.readStringUntil('\x1F');
name.trim(); name.trim();
@ -180,7 +180,7 @@ String base64Encode(String toEncode) {
String data = Base64EncodeChoreo.readStringUntil('\x1E'); String data = Base64EncodeChoreo.readStringUntil('\x1E');
data.trim(); data.trim();
if(name == "Base64EncodedText") { if (name == "Base64EncodedText") {
return data; return data;
} }
} }

View File

@ -47,7 +47,7 @@ void setup() {
Serial.begin(9600); Serial.begin(9600);
// Bridge startup // Bridge startup
pinMode(13,OUTPUT); pinMode(13, OUTPUT);
digitalWrite(13, LOW); digitalWrite(13, LOW);
Bridge.begin(); Bridge.begin();
digitalWrite(13, HIGH); digitalWrite(13, HIGH);
@ -66,7 +66,7 @@ void setup() {
// get the time that this sketch started: // get the time that this sketch started:
Process startTime; Process startTime;
startTime.runShellCommand("date"); startTime.runShellCommand("date");
while(startTime.available()) { while (startTime.available()) {
char c = startTime.read(); char c = startTime.read();
startString += c; startString += c;
} }
@ -89,16 +89,16 @@ void loop() {
Process time; Process time;
time.runShellCommand("date"); time.runShellCommand("date");
String timeString = ""; String timeString = "";
while(time.available()) { while (time.available()) {
char c = time.read(); char c = time.read();
timeString += c; timeString += c;
} }
Serial.println(timeString); Serial.println(timeString);
int sensorValue = analogRead(A1); int sensorValue = analogRead(A1);
// convert the reading to millivolts: // convert the reading to millivolts:
float voltage = sensorValue * (5000/ 1024); float voltage = sensorValue * (5000 / 1024);
// convert the millivolts to temperature celsius: // convert the millivolts to temperature celsius:
float temperature = (voltage - 500)/10; float temperature = (voltage - 500) / 10;
// print the temperature: // print the temperature:
client.print("Current time on the Yún: "); client.print("Current time on the Yún: ");
client.println(timeString); client.println(timeString);

View File

@ -26,7 +26,7 @@ void setup() {
Bridge.begin(); // initialize Bridge Bridge.begin(); // initialize Bridge
Serial.begin(9600); // initialize serial Serial.begin(9600); // initialize serial
while(!Serial); // wait for Serial Monitor to open while (!Serial); // wait for Serial Monitor to open
Serial.println("Time Check"); // Title of sketch Serial.println("Time Check"); // Title of sketch
// run an initial date process. Should return: // run an initial date process. Should return:
@ -40,7 +40,7 @@ void setup() {
void loop() { void loop() {
if(lastSecond != seconds) { // if a second has passed if (lastSecond != seconds) { // if a second has passed
// print the time: // 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(hours);
@ -60,18 +60,18 @@ void loop() {
} }
//if there's a result from the date process, parse it: //if there's a result from the date process, parse it:
while (date.available()>0) { while (date.available() > 0) {
// get the result of the date process (should be hh:mm:ss): // get the result of the date process (should be hh:mm:ss):
String timeString = date.readString(); String timeString = date.readString();
// find the colons: // find the colons:
int firstColon = timeString.indexOf(":"); int firstColon = timeString.indexOf(":");
int secondColon= timeString.lastIndexOf(":"); int secondColon = timeString.lastIndexOf(":");
// get the substrings for hour, minute second: // get the substrings for hour, minute second:
String hourString = timeString.substring(0, firstColon); String hourString = timeString.substring(0, firstColon);
String minString = timeString.substring(firstColon+1, secondColon); String minString = timeString.substring(firstColon + 1, secondColon);
String secString = timeString.substring(secondColon+1); String secString = timeString.substring(secondColon + 1);
// convert to ints,saving the previous second: // convert to ints,saving the previous second:
hours = hourString.toInt(); hours = hourString.toInt();

View File

@ -22,10 +22,10 @@
void setup() { void setup() {
Serial.begin(9600); // initialize serial communication Serial.begin(9600); // initialize serial communication
while(!Serial); // do nothing until the serial monitor is opened while (!Serial); // do nothing until the serial monitor is opened
Serial.println("Starting bridge...\n"); Serial.println("Starting bridge...\n");
pinMode(13,OUTPUT); pinMode(13, OUTPUT);
digitalWrite(13, LOW); digitalWrite(13, LOW);
Bridge.begin(); // make contact with the linux processor Bridge.begin(); // make contact with the linux processor
digitalWrite(13, HIGH); // Led on pin 13 turns on when the bridge is ready digitalWrite(13, HIGH); // Led on pin 13 turns on when the bridge is ready

View File

@ -38,7 +38,7 @@ void setup() {
Bridge.begin(); Bridge.begin();
Serial.begin(9600); Serial.begin(9600);
while(!Serial); // wait for Network Serial to open while (!Serial); // wait for Network Serial to open
Serial.println("Xively client"); Serial.println("Xively client");
// Do a first update immediately // Do a first update immediately
@ -101,7 +101,7 @@ void sendData() {
// If there's incoming data from the net connection, // If there's incoming data from the net connection,
// send it out the Serial: // send it out the Serial:
while (xively.available()>0) { while (xively.available() > 0) {
char c = xively.read(); char c = xively.read();
Serial.write(c); Serial.write(c);
} }

View File

@ -22,19 +22,19 @@ void setup() {
} }
void loop() { void loop() {
Esplora.writeRGB(255,0,0); // make the LED red Esplora.writeRGB(255, 0, 0); // make the LED red
delay(1000); // wait 1 second delay(1000); // wait 1 second
Esplora.writeRGB(0,255,0); // make the LED green Esplora.writeRGB(0, 255, 0); // make the LED green
delay(1000); // wait 1 second delay(1000); // wait 1 second
Esplora.writeRGB(0,0,255); // make the LED blue Esplora.writeRGB(0, 0, 255); // make the LED blue
delay(1000); // wait 1 second delay(1000); // wait 1 second
Esplora.writeRGB(255,255,0); // make the LED yellow Esplora.writeRGB(255, 255, 0); // make the LED yellow
delay(1000); // wait 1 second delay(1000); // wait 1 second
Esplora.writeRGB(0,255,255); // make the LED cyan Esplora.writeRGB(0, 255, 255); // make the LED cyan
delay(1000); // wait 1 second delay(1000); // wait 1 second
Esplora.writeRGB(255,0,255); // make the LED magenta Esplora.writeRGB(255, 0, 255); // make the LED magenta
delay(1000); // wait 1 second delay(1000); // wait 1 second
Esplora.writeRGB(255,255,255);// make the LED white Esplora.writeRGB(255, 255, 255); // make the LED white
delay(1000); // wait 1 second delay(1000); // wait 1 second
} }

View File

@ -41,8 +41,8 @@ void loop()
Serial.print("\tButton: "); // print a tab character and a label for the button Serial.print("\tButton: "); // print a tab character and a label for the button
Serial.print(button); // print the button value Serial.print(button); // print the button value
int mouseX = map( xValue,-512, 512, 10, -10); // map the X value to a range of movement for the mouse X int mouseX = map( xValue, -512, 512, 10, -10); // map the X value to a range of movement for the mouse X
int mouseY = map( yValue,-512, 512, -10, 10); // map the Y value to a range of movement for the mouse Y int mouseY = map( yValue, -512, 512, -10, 10); // map the Y value to a range of movement for the mouse Y
Mouse.move(mouseX, mouseY, 0); // move the mouse Mouse.move(mouseX, mouseY, 0); // move the mouse
delay(10); // a short delay before moving again delay(10); // a short delay before moving again

View File

@ -25,7 +25,7 @@ void loop() {
// convert the sensor readings to light levels: // convert the sensor readings to light levels:
byte red = map(xAxis, -512, 512, 0, 255); byte red = map(xAxis, -512, 512, 0, 255);
byte green = map(yAxis, -512, 512, 0, 255); byte green = map(yAxis, -512, 512, 0, 255);
byte blue = slider/4; byte blue = slider / 4;
// print the light levels: // print the light levels:
Serial.print(red); Serial.print(red);

View File

@ -37,7 +37,7 @@ void loop() {
byte green = constrain( byte green = constrain(
map(light, lowLight, highLight, minGreen, maxGreen), map(light, lowLight, highLight, minGreen, maxGreen),
0, 255); 0, 255);
byte blue = slider/4; byte blue = slider / 4;
// print the light levels (to see what's going on): // print the light levels (to see what's going on):
Serial.print(red); Serial.print(red);

View File

@ -64,7 +64,7 @@ void calibrate() {
Serial.println("While holding switch 1, shine a light on the light sensor, then cover it."); Serial.println("While holding switch 1, shine a light on the light sensor, then cover it.");
// calibrate while switch 1 is pressed: // calibrate while switch 1 is pressed:
while(Esplora.readButton(1) == LOW) { while (Esplora.readButton(1) == LOW) {
// read the sensor value: // read the sensor value:
int light = Esplora.readLightSensor(); int light = Esplora.readLightSensor();

View File

@ -16,19 +16,19 @@
// these are the frequencies for the notes from middle C // these are the frequencies for the notes from middle C
// to one octave above middle C: // to one octave above middle C:
const int note[] = { const int note[] = {
262, // C 262, // C
277, // C# 277, // C#
294, // D 294, // D
311, // D# 311, // D#
330, // E 330, // E
349, // F 349, // F
370, // F# 370, // F#
392, // G 392, // G
415, // G# 415, // G#
440, // A 440, // A
466, // A# 466, // A#
494, // B 494, // B
523 // C next octave 523 // C next octave
}; };
void setup() { void setup() {

View File

@ -92,7 +92,7 @@ void setup() {
void loop() { void loop() {
// Iterate through all the buttons: // Iterate through all the buttons:
for (byte thisButton=0; thisButton<8; thisButton++) { for (byte thisButton = 0; thisButton < 8; thisButton++) {
boolean lastState = buttonStates[thisButton]; boolean lastState = buttonStates[thisButton];
boolean newState = Esplora.readButton(buttons[thisButton]); boolean newState = Esplora.readButton(buttons[thisButton]);
if (lastState != newState) { // Something changed! if (lastState != newState) { // Something changed!

View File

@ -32,7 +32,7 @@
#include <Esplora.h> #include <Esplora.h>
void setup() { void setup() {
while(!Serial); // needed for Leonardo-based board like Esplora while (!Serial); // needed for Leonardo-based board like Esplora
Serial.begin(9600); Serial.begin(9600);
} }
@ -48,7 +48,7 @@ void loop() {
*/ */
void parseCommand() { void parseCommand() {
char cmd = Serial.read(); char cmd = Serial.read();
switch(cmd) { switch (cmd) {
case 'D': case 'D':
dumpInputs(); dumpInputs();
break; break;

View File

@ -149,7 +149,7 @@ void printHeaders() {
void logAndPrint() { void logAndPrint() {
// do all the samplings at once, because keystrokes have delays // do all the samplings at once, because keystrokes have delays
unsigned long timeSecs = (millis() - startedAt) /1000; unsigned long timeSecs = (millis() - startedAt) / 1000;
int xAxis = Esplora.readAccelerometer(X_AXIS); int xAxis = Esplora.readAccelerometer(X_AXIS);
int yAxis = Esplora.readAccelerometer(Y_AXIS); int yAxis = Esplora.readAccelerometer(Y_AXIS);
int zAxis = Esplora.readAccelerometer(Z_AXIS); int zAxis = Esplora.readAccelerometer(Z_AXIS);

View File

@ -29,10 +29,11 @@
// assign a MAC address for the ethernet controller. // assign a MAC address for the ethernet controller.
// fill in your address here: // fill in your address here:
byte mac[] = { byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
// assign an IP address for the controller: // assign an IP address for the controller:
IPAddress ip(192,168,1,20); IPAddress ip(192, 168, 1, 20);
IPAddress gateway(192,168,1,1); IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0); IPAddress subnet(255, 255, 255, 0);
@ -85,7 +86,7 @@ void setup() {
void loop() { void loop() {
// check for a reading no more than once a second. // check for a reading no more than once a second.
if (millis() - lastReadingTime > 1000){ if (millis() - lastReadingTime > 1000) {
// if there's a reading ready, read it: // if there's a reading ready, read it:
// don't do anything until the data ready pin is high: // don't do anything until the data ready pin is high:
if (digitalRead(dataReadyPin) == HIGH) { if (digitalRead(dataReadyPin) == HIGH) {
@ -115,7 +116,7 @@ void getData() {
//Read the pressure data lower 16 bits: //Read the pressure data lower 16 bits:
unsigned int pressureDataLow = readRegister(0x20, 2); unsigned int pressureDataLow = readRegister(0x20, 2);
//combine the two parts into one 19-bit number: //combine the two parts into one 19-bit number:
pressure = ((pressureDataHigh << 16) | pressureDataLow)/4; pressure = ((pressureDataHigh << 16) | pressureDataLow) / 4;
Serial.print("Temperature: "); Serial.print("Temperature: ");
Serial.print(temperature); Serial.print(temperature);
@ -210,10 +211,10 @@ unsigned int readRegister(byte registerName, int numBytes) {
result = inByte; result = inByte;
// if there's more than one byte returned, // if there's more than one byte returned,
// shift the first byte then get the second byte: // shift the first byte then get the second byte:
if (numBytes > 1){ if (numBytes > 1) {
result = inByte << 8; result = inByte << 8;
inByte = SPI.transfer(0x00); inByte = SPI.transfer(0x00);
result = result |inByte; result = result | inByte;
} }
// take the chip select high to de-select: // take the chip select high to de-select:
digitalWrite(chipSelectPin, HIGH); digitalWrite(chipSelectPin, HIGH);

View File

@ -24,9 +24,10 @@
// The IP address will be dependent on your local network. // The IP address will be dependent on your local network.
// gateway and subnet are optional: // gateway and subnet are optional:
byte mac[] = { byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
IPAddress ip(192,168,1, 177); };
IPAddress gateway(192,168,1, 1); IPAddress ip(192, 168, 1, 177);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 0, 0); IPAddress subnet(255, 255, 0, 0);

View File

@ -35,11 +35,12 @@ http://arduino.cc/en/Tutorial/CosmClient
// Newer Ethernet shields have a MAC address printed on a sticker on the shield // Newer Ethernet shields have a MAC address printed on a sticker on the shield
// fill in your address here: // fill in your address here:
byte mac[] = { byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
// fill in an available IP address on your network here, // fill in an available IP address on your network here,
// for manual configuration: // for manual configuration:
IPAddress ip(10,0,1,20); IPAddress ip(10, 0, 1, 20);
// initialize the library instance: // initialize the library instance:
EthernetClient client; EthernetClient client;
@ -51,8 +52,8 @@ char server[] = "api.cosm.com"; // name address for cosm API
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
boolean lastConnected = false; // state of the connection last time through the main loop boolean lastConnected = false; // state of the connection last time through the main loop
const unsigned long postingInterval = 10L*1000L; // delay between updates to cosm.com const unsigned long postingInterval = 10L * 1000L; // delay between updates to cosm.com
// the "L" is needed to use long type numbers // the "L" is needed to use long type numbers
void setup() { void setup() {
@ -88,7 +89,7 @@ void loop() {
// if you're not connected, and ten seconds have passed since // if you're not connected, and ten seconds have passed since
// your last connection, then connect again and send data: // your last connection, then connect again and send data:
if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) { if (!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
sendData(sensorReading); sendData(sensorReading);
} }
// store the state of the connection for next time through // store the state of the connection for next time through
@ -150,9 +151,9 @@ int getLength(int someValue) {
// continually divide the value by ten, // continually divide the value by ten,
// adding one to the digit count for each // adding one to the digit count for each
// time you divide, until you're at 0: // time you divide, until you're at 0:
int dividend = someValue /10; int dividend = someValue / 10;
while (dividend > 0) { while (dividend > 0) {
dividend = dividend /10; dividend = dividend / 10;
digits++; digits++;
} }
// return the number of digits: // return the number of digits:

View File

@ -36,12 +36,13 @@
// assign a MAC address for the ethernet controller. // assign a MAC address for the ethernet controller.
// fill in your address here: // fill in your address here:
byte mac[] = { byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
// fill in an available IP address on your network here, // fill in an available IP address on your network here,
// for manual configuration: // for manual configuration:
IPAddress ip(10,0,1,20); IPAddress ip(10, 0, 1, 20);
// initialize the library instance: // initialize the library instance:
EthernetClient client; EthernetClient client;
@ -53,8 +54,8 @@ char server[] = "api.cosm.com"; // name address for Cosm API
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
boolean lastConnected = false; // state of the connection last time through the main loop boolean lastConnected = false; // state of the connection last time through the main loop
const unsigned long postingInterval = 10L*1000L; // delay between updates to Cosm.com const unsigned long postingInterval = 10L * 1000L; // delay between updates to Cosm.com
// the "L" is needed to use long type numbers // the "L" is needed to use long type numbers
void setup() { void setup() {
// start serial port: // start serial port:
Serial.begin(9600); Serial.begin(9600);
@ -100,7 +101,7 @@ void loop() {
// if you're not connected, and ten seconds have passed since // if you're not connected, and ten seconds have passed since
// your last connection, then connect again and send data: // your last connection, then connect again and send data:
if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) { if (!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
sendData(dataString); sendData(dataString);
} }
// store the state of the connection for next time through // store the state of the connection for next time through

View File

@ -20,7 +20,8 @@
// Enter a MAC address for your controller below. // Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield // Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { byte mac[] = {
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 }; 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
};
// Initialize the Ethernet client library // Initialize the Ethernet client library
// with the IP address and port of the server // with the IP address and port of the server
@ -39,7 +40,7 @@ void setup() {
if (Ethernet.begin(mac) == 0) { if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP"); Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore: // no point in carrying on, so do nothing forevermore:
for(;;) for (;;)
; ;
} }
// print your local IP address: // print your local IP address:

View File

@ -25,9 +25,10 @@
// The IP address will be dependent on your local network. // The IP address will be dependent on your local network.
// gateway and subnet are optional: // gateway and subnet are optional:
byte mac[] = { byte mac[] = {
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 }; 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
IPAddress ip(192,168,1, 177); };
IPAddress gateway(192,168,1, 1); IPAddress ip(192, 168, 1, 177);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 0, 0); IPAddress subnet(255, 255, 0, 0);
// telnet defaults to port 23 // telnet defaults to port 23

View File

@ -35,22 +35,23 @@ http://arduino.cc/en/Tutorial/PachubeClient
// Newer Ethernet shields have a MAC address printed on a sticker on the shield // Newer Ethernet shields have a MAC address printed on a sticker on the shield
// fill in your address here: // fill in your address here:
byte mac[] = { byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
// fill in an available IP address on your network here, // fill in an available IP address on your network here,
// for manual configuration: // for manual configuration:
IPAddress ip(10,0,1,20); IPAddress ip(10, 0, 1, 20);
// initialize the library instance: // initialize the library instance:
EthernetClient client; EthernetClient client;
// if you don't want to use DNS (and reduce your sketch size) // if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server: // use the numeric IP instead of the name for the server:
IPAddress server(216,52,233,122); // numeric IP for api.pachube.com IPAddress server(216, 52, 233, 122); // numeric IP for api.pachube.com
//char server[] = "api.pachube.com"; // name address for pachube API //char server[] = "api.pachube.com"; // name address for pachube API
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
boolean lastConnected = false; // state of the connection last time through the main loop boolean lastConnected = false; // state of the connection last time through the main loop
const unsigned long postingInterval = 10*1000; //delay between updates to Pachube.com const unsigned long postingInterval = 10 * 1000; //delay between updates to Pachube.com
void setup() { void setup() {
// Open serial communications and wait for port to open: // Open serial communications and wait for port to open:
@ -90,7 +91,7 @@ void loop() {
// if you're not connected, and ten seconds have passed since // if you're not connected, and ten seconds have passed since
// your last connection, then connect again and send data: // your last connection, then connect again and send data:
if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) { if (!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
sendData(sensorReading); sendData(sensorReading);
} }
// store the state of the connection for next time through // store the state of the connection for next time through
@ -152,9 +153,9 @@ int getLength(int someValue) {
// continually divide the value by ten, // continually divide the value by ten,
// adding one to the digit count for each // adding one to the digit count for each
// time you divide, until you're at 0: // time you divide, until you're at 0:
int dividend = someValue /10; int dividend = someValue / 10;
while (dividend > 0) { while (dividend > 0) {
dividend = dividend /10; dividend = dividend / 10;
digits++; digits++;
} }
// return the number of digits: // return the number of digits:

View File

@ -37,24 +37,25 @@
// assign a MAC address for the ethernet controller. // assign a MAC address for the ethernet controller.
// fill in your address here: // fill in your address here:
byte mac[] = { byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
// fill in an available IP address on your network here, // fill in an available IP address on your network here,
// for manual configuration: // for manual configuration:
IPAddress ip(10,0,1,20); IPAddress ip(10, 0, 1, 20);
// initialize the library instance: // initialize the library instance:
EthernetClient client; EthernetClient client;
// if you don't want to use DNS (and reduce your sketch size) // if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server: // use the numeric IP instead of the name for the server:
IPAddress server(216,52,233,121); // numeric IP for api.cosm.com IPAddress server(216, 52, 233, 121); // numeric IP for api.cosm.com
//char server[] = "api.cosm.com"; // name address for Cosm API //char server[] = "api.cosm.com"; // name address for Cosm API
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
boolean lastConnected = false; // state of the connection last time through the main loop boolean lastConnected = false; // state of the connection last time through the main loop
const unsigned long postingInterval = 10*1000; //delay between updates to Cosm.com const unsigned long postingInterval = 10 * 1000; //delay between updates to Cosm.com
void setup() { void setup() {
// Open serial communications and wait for port to open: // Open serial communications and wait for port to open:
@ -106,7 +107,7 @@ void loop() {
// if you're not connected, and ten seconds have passed since // if you're not connected, and ten seconds have passed since
// your last connection, then connect again and send data: // your last connection, then connect again and send data:
if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) { if (!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
sendData(dataString); sendData(dataString);
} }
// store the state of the connection for next time through // store the state of the connection for next time through

View File

@ -24,11 +24,12 @@
// Enter a MAC address and IP address for your controller below. // Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network: // The IP address will be dependent on your local network:
byte mac[] = { byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
IPAddress ip(192,168,1,177); };
IPAddress ip(192, 168, 1, 177);
// Enter the IP address of the server you're connecting to: // Enter the IP address of the server you're connecting to:
IPAddress server(1,1,1,1); IPAddress server(1, 1, 1, 1);
// Initialize the Ethernet client library // Initialize the Ethernet client library
// with the IP address and port of the server // with the IP address and port of the server
@ -84,7 +85,7 @@ void loop()
Serial.println("disconnecting."); Serial.println("disconnecting.");
client.stop(); client.stop();
// do nothing: // do nothing:
while(true); while (true);
} }
} }

View File

@ -21,7 +21,8 @@
// Enter a MAC address and IP address for your controller below. // Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network: // The IP address will be dependent on your local network:
byte mac[] = { byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177); IPAddress ip(192, 168, 1, 177);
unsigned int localPort = 8888; // local port to listen on unsigned int localPort = 8888; // local port to listen on
@ -35,7 +36,7 @@ EthernetUDP Udp;
void setup() { void setup() {
// start the Ethernet and UDP: // start the Ethernet and UDP:
Ethernet.begin(mac,ip); Ethernet.begin(mac, ip);
Udp.begin(localPort); Udp.begin(localPort);
Serial.begin(9600); Serial.begin(9600);
@ -44,13 +45,13 @@ void setup() {
void loop() { void loop() {
// if there's data available, read a packet // if there's data available, read a packet
int packetSize = Udp.parsePacket(); int packetSize = Udp.parsePacket();
if(packetSize) if (packetSize)
{ {
Serial.print("Received packet of size "); Serial.print("Received packet of size ");
Serial.println(packetSize); Serial.println(packetSize);
Serial.print("From "); Serial.print("From ");
IPAddress remote = Udp.remoteIP(); IPAddress remote = Udp.remoteIP();
for (int i =0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
Serial.print(remote[i], DEC); Serial.print(remote[i], DEC);
if (i < 3) if (i < 3)
@ -62,7 +63,7 @@ void loop() {
Serial.println(Udp.remotePort()); Serial.println(Udp.remotePort());
// read the packet into packetBufffer // read the packet into packetBufffer
Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE); Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
Serial.println("Contents:"); Serial.println("Contents:");
Serial.println(packetBuffer); Serial.println(packetBuffer);

View File

@ -23,13 +23,14 @@
// Enter a MAC address for your controller below. // Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield // Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
unsigned int localPort = 8888; // local port to listen for UDP packets unsigned int localPort = 8888; // local port to listen for UDP packets
IPAddress timeServer(192, 43, 244, 18); // time.nist.gov NTP server IPAddress timeServer(192, 43, 244, 18); // time.nist.gov NTP server
const int NTP_PACKET_SIZE= 48; // NTP time stamp is in the first 48 bytes of the message const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message
byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets
@ -49,7 +50,7 @@ void setup()
if (Ethernet.begin(mac) == 0) { if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP"); Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore: // no point in carrying on, so do nothing forevermore:
for(;;) for (;;)
; ;
} }
Udp.begin(localPort); Udp.begin(localPort);
@ -63,7 +64,7 @@ void loop()
delay(1000); delay(1000);
if ( Udp.parsePacket() ) { if ( Udp.parsePacket() ) {
// We've received a packet, read the data from it // We've received a packet, read the data from it
Udp.read(packetBuffer,NTP_PACKET_SIZE); // read the packet into the buffer Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer
//the timestamp starts at byte 40 of the received packet and is four bytes, //the timestamp starts at byte 40 of the received packet and is four bytes,
// or two words, long. First, esxtract the two words: // or two words, long. First, esxtract the two words:
@ -100,7 +101,7 @@ void loop()
// In the first 10 seconds of each minute, we'll want a leading '0' // In the first 10 seconds of each minute, we'll want a leading '0'
Serial.print('0'); Serial.print('0');
} }
Serial.println(epoch %60); // print the second Serial.println(epoch % 60); // print the second
} }
// wait ten seconds before asking for the time again // wait ten seconds before asking for the time again
delay(10000); delay(10000);
@ -126,7 +127,7 @@ unsigned long sendNTPpacket(IPAddress& address)
// all NTP fields have been given values, now // all NTP fields have been given values, now
// you can send a packet requesting a timestamp: // you can send a packet requesting a timestamp:
Udp.beginPacket(address, 123); //NTP requests are to port 123 Udp.beginPacket(address, 123); //NTP requests are to port 123
Udp.write(packetBuffer,NTP_PACKET_SIZE); Udp.write(packetBuffer, NTP_PACKET_SIZE);
Udp.endPacket(); Udp.endPacket();
} }

View File

@ -26,7 +26,7 @@ byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char server[] = "www.google.com"; // name address for Google (using DNS) char server[] = "www.google.com"; // name address for Google (using DNS)
// Set the static IP address to use if the DHCP fails to assign // Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192,168,0,177); IPAddress ip(192, 168, 0, 177);
// Initialize the Ethernet client library // Initialize the Ethernet client library
// with the IP address and port of the server // with the IP address and port of the server
@ -82,7 +82,7 @@ void loop()
client.stop(); client.stop();
// do nothing forevermore: // do nothing forevermore:
while(true); while (true);
} }
} }

View File

@ -26,13 +26,14 @@
// assign a MAC address for the ethernet controller. // assign a MAC address for the ethernet controller.
// fill in your address here: // fill in your address here:
byte mac[] = { byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
// fill in an available IP address on your network here, // fill in an available IP address on your network here,
// for manual configuration: // for manual configuration:
IPAddress ip(10,0,0,20); IPAddress ip(10, 0, 0, 20);
// fill in your Domain Name Server address here: // fill in your Domain Name Server address here:
IPAddress myDns(1,1,1,1); IPAddress myDns(1, 1, 1, 1);
// initialize the library instance: // initialize the library instance:
EthernetClient client; EthernetClient client;
@ -41,8 +42,8 @@ char server[] = "www.arduino.cc";
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
boolean lastConnected = false; // state of the connection last time through the main loop boolean lastConnected = false; // state of the connection last time through the main loop
const unsigned long postingInterval = 60L*1000L; // delay between updates, in milliseconds const unsigned long postingInterval = 60L * 1000L; // delay between updates, in milliseconds
// the "L" is needed to use long type numbers // the "L" is needed to use long type numbers
void setup() { void setup() {
// start serial port: // start serial port:
@ -75,7 +76,7 @@ void loop() {
// if you're not connected, and ten seconds have passed since // if you're not connected, and ten seconds have passed since
// your last connection, then connect again and send data: // your last connection, then connect again and send data:
if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) { if (!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
httpRequest(); httpRequest();
} }
// store the state of the connection for next time through // store the state of the connection for next time through

View File

@ -21,8 +21,9 @@
// Enter a MAC address and IP address for your controller below. // Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network: // The IP address will be dependent on your local network:
byte mac[] = { byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
IPAddress ip(192,168,1,177); };
IPAddress ip(192, 168, 1, 177);
// Initialize the Ethernet server library // Initialize the Ethernet server library
// with the IP address and port you want to use // with the IP address and port you want to use

View File

@ -35,7 +35,7 @@ int samplingInterval = 19; // how often to run the main loop (in ms)
void sendPort(byte portNumber, byte portValue) void sendPort(byte portNumber, byte portValue)
{ {
portValue = portValue & portStatus[portNumber]; portValue = portValue & portStatus[portNumber];
if(previousPINs[portNumber] != portValue) { if (previousPINs[portNumber] != portValue) {
Firmata.sendDigitalPort(portNumber, portValue); Firmata.sendDigitalPort(portNumber, portValue);
previousPINs[portNumber] = portValue; previousPINs[portNumber] = portValue;
} }
@ -47,13 +47,13 @@ void setup()
Firmata.setFirmwareVersion(0, 1); Firmata.setFirmwareVersion(0, 1);
for(pin = 0; pin < TOTAL_PINS; pin++) { for (pin = 0; pin < TOTAL_PINS; pin++) {
if IS_PIN_DIGITAL(pin) pinMode(PIN_TO_DIGITAL(pin), INPUT); if IS_PIN_DIGITAL(pin) pinMode(PIN_TO_DIGITAL(pin), INPUT);
} }
for (port=0; port<TOTAL_PORTS; port++) { for (port = 0; port < TOTAL_PORTS; port++) {
status = 0; status = 0;
for (i=0; i<8; i++) { for (i = 0; i < 8; i++) {
if (IS_PIN_DIGITAL(port * 8 + i)) status |= (1 << i); if (IS_PIN_DIGITAL(port * 8 + i)) status |= (1 << i);
} }
portStatus[port] = status; portStatus[port] = status;
@ -66,20 +66,20 @@ void loop()
{ {
byte i; byte i;
for (i=0; i<TOTAL_PORTS; i++) { for (i = 0; i < TOTAL_PORTS; i++) {
sendPort(i, readPort(i, 0xff)); sendPort(i, readPort(i, 0xff));
} }
/* make sure that the FTDI buffer doesn't go over 60 bytes, otherwise you /* make sure that the FTDI buffer doesn't go over 60 bytes, otherwise you
get long, random delays. So only read analogs every 20ms or so */ get long, random delays. So only read analogs every 20ms or so */
currentMillis = millis(); currentMillis = millis();
if(currentMillis - previousMillis > samplingInterval) { if (currentMillis - previousMillis > samplingInterval) {
previousMillis += samplingInterval; previousMillis += samplingInterval;
while(Firmata.available()) { while (Firmata.available()) {
Firmata.processInput(); Firmata.processInput();
} }
for(pin = 0; pin < TOTAL_ANALOG_PINS; pin++) { for (pin = 0; pin < TOTAL_ANALOG_PINS; pin++) {
analogValue = analogRead(pin); analogValue = analogRead(pin);
if(analogValue != previousAnalogValues[pin]) { if (analogValue != previousAnalogValues[pin]) {
Firmata.sendAnalog(pin, analogValue); Firmata.sendAnalog(pin, analogValue);
previousAnalogValues[pin] = analogValue; previousAnalogValues[pin] = analogValue;
} }

View File

@ -37,7 +37,7 @@ unsigned long previousMillis; // for comparison with currentMillis
void analogWriteCallback(byte pin, int value) void analogWriteCallback(byte pin, int value)
{ {
switch(pin) { switch (pin) {
case 9: servo9.write(value); break; case 9: servo9.write(value); break;
case 10: servo10.write(value); break; case 10: servo10.write(value); break;
case 3: case 3:
@ -52,7 +52,7 @@ void analogWriteCallback(byte pin, int value)
// sets bits in a bit array (int) to toggle the reporting of the analogIns // sets bits in a bit array (int) to toggle the reporting of the analogIns
void reportAnalogCallback(byte pin, int value) void reportAnalogCallback(byte pin, int value)
{ {
if(value == 0) { if (value == 0) {
analogInputsToReport = analogInputsToReport &~ (1 << pin); analogInputsToReport = analogInputsToReport &~ (1 << pin);
} }
else { // everything but 0 enables reporting of that pin else { // everything but 0 enables reporting of that pin
@ -80,13 +80,13 @@ void setup()
*============================================================================*/ *============================================================================*/
void loop() void loop()
{ {
while(Firmata.available()) while (Firmata.available())
Firmata.processInput(); Firmata.processInput();
currentMillis = millis(); currentMillis = millis();
if(currentMillis - previousMillis > 20) { if (currentMillis - previousMillis > 20) {
previousMillis += 20; // run this every 20ms previousMillis += 20; // run this every 20ms
for(analogPin=0;analogPin<TOTAL_ANALOG_PINS;analogPin++) { for (analogPin = 0; analogPin < TOTAL_ANALOG_PINS; analogPin++) {
if( analogInputsToReport & (1 << analogPin) ) if ( analogInputsToReport & (1 << analogPin) )
Firmata.sendAnalog(analogPin, analogRead(analogPin)); Firmata.sendAnalog(analogPin, analogRead(analogPin));
} }
} }

View File

@ -36,7 +36,7 @@ void setup()
void loop() void loop()
{ {
while(Firmata.available()) { while (Firmata.available()) {
Firmata.processInput(); Firmata.processInput();
} }
} }

View File

@ -56,7 +56,7 @@ unsigned long previousMillis; // for comparison with currentMillis
void outputPort(byte portNumber, byte portValue) void outputPort(byte portNumber, byte portValue)
{ {
portValue = portValue &~ portStatus[portNumber]; portValue = portValue &~ portStatus[portNumber];
if(previousPINs[portNumber] != portValue) { if (previousPINs[portNumber] != portValue) {
Firmata.sendDigitalPort(portNumber, portValue); Firmata.sendDigitalPort(portNumber, portValue);
previousPINs[portNumber] = portValue; previousPINs[portNumber] = portValue;
Firmata.sendDigitalPort(portNumber, portValue); Firmata.sendDigitalPort(portNumber, portValue);
@ -69,9 +69,9 @@ void outputPort(byte portNumber, byte portValue)
void checkDigitalInputs(void) void checkDigitalInputs(void)
{ {
byte i, tmp; byte i, tmp;
for(i=0; i < TOTAL_PORTS; i++) { for (i = 0; i < TOTAL_PORTS; i++) {
if(reportPINs[i]) { if (reportPINs[i]) {
switch(i) { switch (i) {
case 0: outputPort(0, PIND &~ B00000011); break; // ignore Rx/Tx 0/1 case 0: outputPort(0, PIND &~ B00000011); break; // ignore Rx/Tx 0/1
case 1: outputPort(1, PINB); break; case 1: outputPort(1, PINB); break;
case 2: outputPort(2, PINC); break; case 2: outputPort(2, PINC); break;
@ -99,9 +99,9 @@ void setPinModeCallback(byte pin, int mode) {
offset = 14; offset = 14;
} }
if(pin > 1) { // ignore RxTx (pins 0 and 1) if (pin > 1) { // ignore RxTx (pins 0 and 1)
pinStatus[pin] = mode; pinStatus[pin] = mode;
switch(mode) { switch (mode) {
case INPUT: case INPUT:
pinMode(pin, INPUT); pinMode(pin, INPUT);
portStatus[port] = portStatus[port] &~ (1 << (pin - offset)); portStatus[port] = portStatus[port] &~ (1 << (pin - offset));
@ -122,13 +122,13 @@ void setPinModeCallback(byte pin, int mode) {
void analogWriteCallback(byte pin, int value) void analogWriteCallback(byte pin, int value)
{ {
setPinModeCallback(pin,PWM); setPinModeCallback(pin, PWM);
analogWrite(pin, value); analogWrite(pin, value);
} }
void digitalWriteCallback(byte port, int value) void digitalWriteCallback(byte port, int value)
{ {
switch(port) { switch (port) {
case 0: // pins 2-7 (don't change Rx/Tx, pins 0 and 1) case 0: // pins 2-7 (don't change Rx/Tx, pins 0 and 1)
// 0xFF03 == B1111111100000011 0x03 == B00000011 // 0xFF03 == B1111111100000011 0x03 == B00000011
PORTD = (value &~ 0xFF03) | (PORTD & 0x03); PORTD = (value &~ 0xFF03) | (PORTD & 0x03);
@ -149,7 +149,7 @@ void digitalWriteCallback(byte port, int value)
//} //}
void reportAnalogCallback(byte pin, int value) void reportAnalogCallback(byte pin, int value)
{ {
if(value == 0) { if (value == 0) {
analogInputsToReport = analogInputsToReport &~ (1 << pin); analogInputsToReport = analogInputsToReport &~ (1 << pin);
} }
else { // everything but 0 enables reporting of that pin else { // everything but 0 enables reporting of that pin
@ -161,7 +161,7 @@ void reportAnalogCallback(byte pin, int value)
void reportDigitalCallback(byte port, int value) void reportDigitalCallback(byte port, int value)
{ {
reportPINs[port] = (byte)value; reportPINs[port] = (byte)value;
if(port == 2) // turn off analog reporting when used as digital if (port == 2) // turn off analog reporting when used as digital
analogInputsToReport = 0; analogInputsToReport = 0;
} }
@ -184,9 +184,9 @@ void setup()
portStatus[1] = B11000000; // ignore 14/15 pins portStatus[1] = B11000000; // ignore 14/15 pins
portStatus[2] = B00000000; portStatus[2] = B00000000;
// for(i=0; i<TOTAL_PINS; ++i) { // TODO make this work with analogs // for(i=0; i<TOTAL_PINS; ++i) { // TODO make this work with analogs
for(i=0; i<14; ++i) { for (i = 0; i < 14; ++i) {
setPinModeCallback(i,OUTPUT); setPinModeCallback(i, OUTPUT);
} }
// set all outputs to 0 to make sure internal pull-up resistors are off // set all outputs to 0 to make sure internal pull-up resistors are off
PORTB = 0; // pins 8-15 PORTB = 0; // pins 8-15
@ -194,7 +194,7 @@ void setup()
PORTD = 0; // pins 0-7 PORTD = 0; // pins 0-7
// TODO rethink the init, perhaps it should report analog on default // TODO rethink the init, perhaps it should report analog on default
for(i=0; i<TOTAL_PORTS; ++i) { for (i = 0; i < TOTAL_PORTS; ++i) {
reportPINs[i] = false; reportPINs[i] = false;
} }
// TODO: load state from EEPROM here // TODO: load state from EEPROM here
@ -202,9 +202,9 @@ void setup()
/* send digital inputs here, if enabled, to set the initial state on the /* send digital inputs here, if enabled, to set the initial state on the
* host computer, since once in the loop(), this firmware will only send * host computer, since once in the loop(), this firmware will only send
* digital data on change. */ * digital data on change. */
if(reportPINs[0]) outputPort(0, PIND &~ B00000011); // ignore Rx/Tx 0/1 if (reportPINs[0]) outputPort(0, PIND &~ B00000011); // ignore Rx/Tx 0/1
if(reportPINs[1]) outputPort(1, PINB); if (reportPINs[1]) outputPort(1, PINB);
if(reportPINs[2]) outputPort(2, PINC); if (reportPINs[2]) outputPort(2, PINC);
Firmata.begin(115200); Firmata.begin(115200);
} }
@ -214,15 +214,15 @@ void setup()
*============================================================================*/ *============================================================================*/
void loop() void loop()
{ {
/* DIGITALREAD - as fast as possible, check for changes and output them to the /* DIGITALREAD - as fast as possible, check for changes and output them to the
* FTDI buffer using Serial.print() */ * FTDI buffer using Serial.print() */
checkDigitalInputs(); checkDigitalInputs();
currentMillis = millis(); currentMillis = millis();
if(currentMillis - previousMillis > 20) { if (currentMillis - previousMillis > 20) {
previousMillis += 20; // run this every 20ms previousMillis += 20; // run this every 20ms
/* SERIALREAD - Serial.read() uses a 128 byte circular buffer, so handle /* SERIALREAD - Serial.read() uses a 128 byte circular buffer, so handle
* all serialReads at once, i.e. empty the buffer */ * all serialReads at once, i.e. empty the buffer */
while(Firmata.available()) while (Firmata.available())
Firmata.processInput(); Firmata.processInput();
/* SEND FTDI WRITE BUFFER - make sure that the FTDI buffer doesn't go over /* SEND FTDI WRITE BUFFER - make sure that the FTDI buffer doesn't go over
* 60 bytes. use a timer to sending an event character every 4 ms to * 60 bytes. use a timer to sending an event character every 4 ms to
@ -230,8 +230,8 @@ void loop()
/* ANALOGREAD - right after the event character, do all of the /* ANALOGREAD - right after the event character, do all of the
* analogReads(). These only need to be done every 4ms. */ * analogReads(). These only need to be done every 4ms. */
for(analogPin=0;analogPin<TOTAL_ANALOG_PINS;analogPin++) { for (analogPin = 0; analogPin < TOTAL_ANALOG_PINS; analogPin++) {
if( analogInputsToReport & (1 << analogPin) ) { if ( analogInputsToReport & (1 << analogPin) ) {
Firmata.sendAnalog(analogPin, analogRead(analogPin)); Firmata.sendAnalog(analogPin, analogRead(analogPin));
} }
} }

View File

@ -36,7 +36,7 @@ void setup()
Firmata.setFirmwareVersion(0, 2); Firmata.setFirmwareVersion(0, 2);
Firmata.attach(ANALOG_MESSAGE, analogWriteCallback); Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
for (pin=0; pin < TOTAL_PINS; pin++) { for (pin = 0; pin < TOTAL_PINS; pin++) {
if (IS_PIN_SERVO(pin)) { if (IS_PIN_SERVO(pin)) {
servos[PIN_TO_SERVO(pin)].attach(PIN_TO_DIGITAL(pin)); servos[PIN_TO_SERVO(pin)].attach(PIN_TO_DIGITAL(pin));
} }
@ -47,7 +47,7 @@ void setup()
void loop() void loop()
{ {
while(Firmata.available()) while (Firmata.available())
Firmata.processInput(); Firmata.processInput();
} }

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