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

@ -12,13 +12,13 @@ int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by int fadeAmount = 5; // how many points to fade the LED by
// the setup routine runs once when you press reset: // the setup routine runs once when you press reset:
void setup() { void setup() {
// declare pin 9 to be an output: // declare pin 9 to be an output:
pinMode(led, OUTPUT); pinMode(led, OUTPUT);
} }
// the loop routine runs over and over again forever: // the loop routine runs over and over again forever:
void loop() { void loop() {
// set the brightness of pin 9: // set the brightness of pin 9:
analogWrite(led, brightness); analogWrite(led, brightness);

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

@ -79,7 +79,7 @@ void loop() {
if (buttonPushCounter % 4 == 0) { if (buttonPushCounter % 4 == 0) {
digitalWrite(ledPin, HIGH); digitalWrite(ledPin, HIGH);
} else { } else {
digitalWrite(ledPin, LOW); digitalWrite(ledPin, LOW);
} }
} }

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

@ -20,13 +20,13 @@
int ledPin = 9; // LED connected to digital pin 9 int ledPin = 9; // LED connected to digital pin 9
void setup() { void setup() {
// nothing happens in setup // nothing happens in 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

@ -20,7 +20,7 @@
*/ */
void setup() { void setup() {
//Initialize serial and wait for port to open: //Initialize serial and wait for port to open:
Serial.begin(9600); Serial.begin(9600);
while (!Serial) { while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only ; // wait for serial port to connect. Needed for Leonardo only
@ -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

@ -74,7 +74,7 @@ void loop() {
Serial port; Serial port;
void setup() { void setup() {
size(200, 200); size(200, 200);
boxX = width/2.0; boxX = width/2.0;
boxY = height/2.0; boxY = height/2.0;

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,13 +23,14 @@ 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() {
// the array elements are numbered from 0 to (pinCount - 1). // the array elements are numbered from 0 to (pinCount - 1).
// use a for loop to initialize each pin as an output: // use a for loop to initialize each pin as an output:
for (int thisPin = 0; thisPin < pinCount; thisPin++) { for (int thisPin = 0; thisPin < pinCount; thisPin++) {
pinMode(ledPins[thisPin], OUTPUT); pinMode(ledPins[thisPin], OUTPUT);
} }
} }

View File

@ -21,7 +21,7 @@ int timer = 100; // The higher the number, the slower the timing.
void setup() { void setup() {
// use a for loop to initialize each pin as an output: // use a for loop to initialize each pin as an output:
for (int thisPin = 2; thisPin < 8; thisPin++) { for (int thisPin = 2; thisPin < 8; thisPin++) {
pinMode(thisPin, OUTPUT); pinMode(thisPin, OUTPUT);
} }
} }

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

@ -41,18 +41,18 @@ void loop() {
// do something different depending on the // do something different depending on the
// range value: // range value:
switch (range) { switch (range) {
case 0: // your hand is on the sensor case 0: // your hand is on the sensor
Serial.println("dark"); Serial.println("dark");
break; break;
case 1: // your hand is close to the sensor case 1: // your hand is close to the sensor
Serial.println("dim"); Serial.println("dim");
break; break;
case 2: // your hand is a few inches from the sensor case 2: // your hand is a few inches from the sensor
Serial.println("medium"); Serial.println("medium");
break; break;
case 3: // your hand is nowhere near the sensor case 3: // your hand is nowhere near the sensor
Serial.println("bright"); Serial.println("bright");
break; break;
} }
delay(1); // delay in between reads for stability delay(1); // delay in between reads for stability
} }

View File

@ -23,10 +23,10 @@ This example code is in the public domain.
void setup() { void setup() {
// initialize serial communication: // initialize serial communication:
Serial.begin(9600); Serial.begin(9600);
// initialize the LED pins: // initialize the LED pins:
for (int thisPin = 2; thisPin < 7; thisPin++) { for (int thisPin = 2; thisPin < 7; thisPin++) {
pinMode(thisPin, OUTPUT); pinMode(thisPin, OUTPUT);
} }
} }
void loop() { void loop() {
@ -40,26 +40,26 @@ void loop() {
// example 'a' = 97, 'b' = 98, and so forth: // example 'a' = 97, 'b' = 98, and so forth:
switch (inByte) { switch (inByte) {
case 'a': case 'a':
digitalWrite(2, HIGH); digitalWrite(2, HIGH);
break; break;
case 'b': case 'b':
digitalWrite(3, HIGH); digitalWrite(3, HIGH);
break; break;
case 'c': case 'c':
digitalWrite(4, HIGH); digitalWrite(4, HIGH);
break; break;
case 'd': case 'd':
digitalWrite(5, HIGH); digitalWrite(5, HIGH);
break; break;
case 'e': case 'e':
digitalWrite(6, HIGH); digitalWrite(6, HIGH);
break; break;
default: default:
// turn all the LEDs off: // turn all the LEDs off:
for (int thisPin = 2; thisPin < 7; thisPin++) { for (int thisPin = 2; thisPin < 7; thisPin++) {
digitalWrite(thisPin, LOW); digitalWrite(thisPin, LOW);
} }
} }
} }
} }

View File

@ -33,8 +33,8 @@ int sensorReading = 0; // variable to store the value read from the sensor
int ledState = LOW; // variable used to store the last LED status, to toggle the light int ledState = LOW; // variable used to store the last LED status, to toggle the light
void setup() { void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT
Serial.begin(9600); // use the serial port Serial.begin(9600); // use the serial port
} }
void loop() { void loop() {

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

@ -63,16 +63,16 @@ void loop() {
if (inChar == ',') { if (inChar == ',') {
// do something different for each value of currentColor: // do something different for each value of currentColor:
switch (currentColor) { switch (currentColor) {
case 0: // 0 = red case 0: // 0 = red
red = inString.toInt(); red = inString.toInt();
// clear the string for new input: // clear the string for new input:
inString = ""; inString = "";
break; break;
case 1: // 1 = green: case 1: // 1 = green:
green = inString.toInt(); green = inString.toInt();
// clear the string for new input: // clear the string for new input:
inString = ""; inString = "";
break; break;
} }
currentColor++; currentColor++;
} }

View File

@ -48,43 +48,43 @@ void loop() {
delay(1000); delay(1000);
switch (platform) { switch (platform) {
case OSX: case OSX:
Keyboard.press(KEY_LEFT_GUI); Keyboard.press(KEY_LEFT_GUI);
// Shift-Q logs out: // Shift-Q logs out:
Keyboard.press(KEY_LEFT_SHIFT); Keyboard.press(KEY_LEFT_SHIFT);
Keyboard.press('Q'); Keyboard.press('Q');
delay(100); delay(100);
Keyboard.releaseAll(); Keyboard.releaseAll();
// enter: // enter:
Keyboard.write(KEY_RETURN); Keyboard.write(KEY_RETURN);
break; break;
case WINDOWS: case WINDOWS:
// CTRL-ALT-DEL: // CTRL-ALT-DEL:
Keyboard.press(KEY_LEFT_CTRL); Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_ALT); Keyboard.press(KEY_LEFT_ALT);
Keyboard.press(KEY_DELETE); Keyboard.press(KEY_DELETE);
delay(100); delay(100);
Keyboard.releaseAll(); Keyboard.releaseAll();
//ALT-s: //ALT-s:
delay(2000); delay(2000);
Keyboard.press(KEY_LEFT_ALT); Keyboard.press(KEY_LEFT_ALT);
Keyboard.press('l'); Keyboard.press('l');
Keyboard.releaseAll(); Keyboard.releaseAll();
break; break;
case UBUNTU: case UBUNTU:
// CTRL-ALT-DEL: // CTRL-ALT-DEL:
Keyboard.press(KEY_LEFT_CTRL); Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_ALT); Keyboard.press(KEY_LEFT_ALT);
Keyboard.press(KEY_DELETE); Keyboard.press(KEY_DELETE);
delay(1000); delay(1000);
Keyboard.releaseAll(); Keyboard.releaseAll();
// Enter to confirm logout: // Enter to confirm logout:
Keyboard.write(KEY_RETURN); Keyboard.write(KEY_RETURN);
break; break;
} }
// do nothing: // do nothing:
while(true); while (true);
} }

View File

@ -35,8 +35,8 @@ void loop() {
int buttonState = digitalRead(buttonPin); int buttonState = digitalRead(buttonPin);
// if the button state has changed, // if the button state has changed,
if ((buttonState != previousButtonState) if ((buttonState != previousButtonState)
// and it's currently pressed: // and it's currently pressed:
&& (buttonState == HIGH)) { && (buttonState == HIGH)) {
// increment the button counter // increment the button counter
counter++; counter++;
// type out a message // type out a message

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

@ -47,26 +47,26 @@ void loop() {
char inChar = Serial.read(); char inChar = Serial.read();
switch (inChar) { switch (inChar) {
case 'u': case 'u':
// move mouse up // move mouse up
Mouse.move(0, -40); Mouse.move(0, -40);
break; break;
case 'd': case 'd':
// move mouse down // move mouse down
Mouse.move(0, 40); Mouse.move(0, 40);
break; break;
case 'l': case 'l':
// move mouse left // move mouse left
Mouse.move(-40, 0); Mouse.move(-40, 0);
break; break;
case 'r': case 'r':
// move mouse right // move mouse right
Mouse.move(40, 0); Mouse.move(40, 0);
break; break;
case 'm': case 'm':
// perform mouse left click // perform mouse left click
Mouse.click(MOUSE_LEFT); Mouse.click(MOUSE_LEFT);
break; break;
} }
} }

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
@ -47,7 +47,7 @@ int lastSwitchState = LOW; // previous switch state
void setup() { void setup() {
pinMode(switchPin, INPUT); // the switch pin pinMode(switchPin, INPUT); // the switch pin
pinMode(ledPin, OUTPUT); // the LED pin pinMode(ledPin, OUTPUT); // the LED pin
// take control of the mouse: // take control of the mouse:
Mouse.begin(); Mouse.begin();
} }

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

@ -26,7 +26,7 @@
int notes[] = {262, 294, 330, 349}; int notes[] = {262, 294, 330, 349};
void setup() { void setup() {
//start serial communication //start serial communication
Serial.begin(9600); Serial.begin(9600);
} }
@ -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,38 +77,38 @@ 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;
case 1: case 1:
lcd.print("Most likely"); lcd.print("Most likely");
break; break;
case 2: case 2:
lcd.print("Certainly"); lcd.print("Certainly");
break; break;
case 3: case 3:
lcd.print("Outlook good"); lcd.print("Outlook good");
break; break;
case 4: case 4:
lcd.print("Unsure"); lcd.print("Unsure");
break; break;
case 5: case 5:
lcd.print("Ask again"); lcd.print("Ask again");
break; break;
case 6: case 6:
lcd.print("Doubtful"); lcd.print("Doubtful");
break; break;
case 7: case 7:
lcd.print("No"); lcd.print("No");
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,18 +20,18 @@
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
digitalWrite(optoPin, LOW); // pull pin 2 low until you're ready to activate again digitalWrite(optoPin, LOW); // pull pin 2 low until you're ready to activate again
delay(21000); // wait for 21 seconds delay(21000); // wait for 21 seconds
} }

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,21 +208,21 @@ 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;
case 0x81: case 0x81:
breply(SWMAJ); breply(SWMAJ);
break; break;
case 0x82: case 0x82:
breply(SWMIN); breply(SWMIN);
break; break;
case 0x93: case 0x93:
breply('S'); // serial programmer breply('S'); // serial programmer
break; break;
default: default:
breply(0); breply(0);
} }
} }
@ -245,9 +245,9 @@ void set_parameters() {
// 32 bits flashsize (big endian) // 32 bits flashsize (big endian)
param.flashsize = buff[16] * 0x01000000 param.flashsize = buff[16] * 0x01000000
+ buff[17] * 0x00010000 + buff[17] * 0x00010000
+ buff[18] * 0x00000100 + buff[18] * 0x00000100
+ buff[19]; + buff[19];
} }
@ -285,10 +285,10 @@ 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);
} }
void commit(int addr) { void commit(int addr) {
if (PROG_FLICKER) prog_lamp(LOW); if (PROG_FLICKER) prog_lamp(LOW);
@ -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);
@ -399,13 +399,13 @@ void program_page() {
uint8_t flash_read(uint8_t hilo, int addr) { uint8_t flash_read(uint8_t hilo, int addr) {
return spi_transaction(0x20 + hilo * 8, return spi_transaction(0x20 + hilo * 8,
(addr >> 8) & 0xFF, (addr >> 8) & 0xFF,
addr & 0xFF, addr & 0xFF,
0); 0);
} }
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);
@ -468,85 +468,85 @@ int avrisp() {
uint8_t data, low, high; uint8_t data, low, high;
uint8_t ch = getch(); uint8_t ch = getch();
switch (ch) { switch (ch) {
case '0': // signon case '0': // signon
error = 0; error = 0;
empty_reply(); empty_reply();
break; break;
case '1': case '1':
if (getch() == CRC_EOP) { if (getch() == CRC_EOP) {
Serial.print((char) STK_INSYNC); Serial.print((char) STK_INSYNC);
Serial.print("AVR ISP"); Serial.print("AVR ISP");
Serial.print((char) STK_OK); Serial.print((char) STK_OK);
} }
break; break;
case 'A': case 'A':
get_version(getch()); get_version(getch());
break; break;
case 'B': case 'B':
fill(20); fill(20);
set_parameters(); set_parameters();
empty_reply(); empty_reply();
break; break;
case 'E': // extended parameters - ignore for now case 'E': // extended parameters - ignore for now
fill(5); fill(5);
empty_reply(); empty_reply();
break; break;
case 'P': case 'P':
start_pmode(); start_pmode();
empty_reply(); empty_reply();
break; break;
case 'U': // set address (word) case 'U': // set address (word)
here = getch(); here = getch();
here += 256 * getch(); here += 256 * getch();
empty_reply(); empty_reply();
break; break;
case 0x60: //STK_PROG_FLASH case 0x60: //STK_PROG_FLASH
low = getch(); low = getch();
high = getch(); high = getch();
empty_reply(); empty_reply();
break; break;
case 0x61: //STK_PROG_DATA case 0x61: //STK_PROG_DATA
data = getch(); data = getch();
empty_reply(); empty_reply();
break; break;
case 0x64: //STK_PROG_PAGE case 0x64: //STK_PROG_PAGE
program_page(); program_page();
break; break;
case 0x74: //STK_READ_PAGE 't' case 0x74: //STK_READ_PAGE 't'
read_page(); read_page();
break; break;
case 'V': //0x56 case 'V': //0x56
universal(); universal();
break; break;
case 'Q': //0x51 case 'Q': //0x51
error=0; error = 0;
end_pmode(); end_pmode();
empty_reply(); empty_reply();
break; break;
case 0x75: //STK_READ_SIGN 'u' case 0x75: //STK_READ_SIGN 'u'
read_signature(); read_signature();
break; break;
// expecting a command, not CRC_EOP // expecting a command, not CRC_EOP
// this is how we can get back in sync // this is how we can get back in sync
case CRC_EOP: case CRC_EOP:
error++; error++;
Serial.print((char) STK_NOSYNC); Serial.print((char) STK_NOSYNC);
break; break;
// anything else we will return STK_UNKNOWN // anything else we will return STK_UNKNOWN
default: default:
error++; error++;
if (CRC_EOP == getch()) if (CRC_EOP == getch())
Serial.print((char)STK_UNKNOWN); Serial.print((char)STK_UNKNOWN);
else else
Serial.print((char)STK_NOSYNC); Serial.print((char)STK_NOSYNC);
} }
} }

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

@ -26,7 +26,7 @@
#include <Console.h> #include <Console.h>
void setup() { void setup() {
//Initialize Console and wait for port to open: //Initialize Console and wait for port to open:
Bridge.begin(); Bridge.begin();
Console.begin(); Console.begin();
@ -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");
} }
@ -87,13 +87,13 @@ String getTimeStamp() {
// in different formats depending on the additional parameter // in different formats depending on the additional parameter
time.begin("date"); time.begin("date");
time.addParameter("+%D-%T"); // parameters: D for the complete date mm/dd/yy time.addParameter("+%D-%T"); // parameters: D for the complete date mm/dd/yy
// T for the time hh:mm:ss // T for the time hh:mm:ss
time.run(); // run the command 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

@ -35,96 +35,98 @@ int counter = 0;
void setup() { void setup() {
// start the serial port // start the serial port
Serial.begin(57600); Serial.begin(57600);
// 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();
// configure the spacebrew object to print status messages to serial // configure the spacebrew object to print status messages to serial
sb.verbose(true); sb.verbose(true);
// configure the spacebrew publisher and subscriber // configure the spacebrew publisher and subscriber
sb.addPublish("string test", "string"); sb.addPublish("string test", "string");
sb.addPublish("range test", "range"); sb.addPublish("range test", "range");
sb.addPublish("boolean test", "boolean"); sb.addPublish("boolean test", "boolean");
sb.addPublish("custom test", "crazy"); sb.addPublish("custom test", "crazy");
sb.addSubscribe("string test", "string"); sb.addSubscribe("string test", "string");
sb.addSubscribe("range test", "range"); sb.addSubscribe("range test", "range");
sb.addSubscribe("boolean test", "boolean"); sb.addSubscribe("boolean test", "boolean");
sb.addSubscribe("custom test", "crazy"); sb.addSubscribe("custom test", "crazy");
// register the string message handler method // register the string message handler method
sb.onRangeMessage(handleRange); sb.onRangeMessage(handleRange);
sb.onStringMessage(handleString); sb.onStringMessage(handleString);
sb.onBooleanMessage(handleBoolean); sb.onBooleanMessage(handleBoolean);
sb.onCustomMessage(handleCustom); sb.onCustomMessage(handleCustom);
// connect to cloud spacebrew server at "sandbox.spacebrew.cc" // connect to cloud spacebrew server at "sandbox.spacebrew.cc"
sb.connect("sandbox.spacebrew.cc"); sb.connect("sandbox.spacebrew.cc");
} }
void loop() { void loop() {
// monitor spacebrew connection for new data // monitor spacebrew connection for new data
sb.monitor(); sb.monitor();
// connected to spacebrew then send a string every 2 seconds // connected to spacebrew then send a string every 2 seconds
if ( sb.connected() ) { if ( sb.connected() ) {
// check if it is time to send a new message // check if it is time to send a new message
if ( (millis() - last) > interval ) { if ( (millis() - last) > interval ) {
String test_str_msg = "testing, testing, "; String test_str_msg = "testing, testing, ";
test_str_msg += counter; test_str_msg += counter;
counter ++; counter ++;
sb.send("string test", test_str_msg); sb.send("string test", test_str_msg);
sb.send("range test", 500); sb.send("range test", 500);
sb.send("boolean test", true); sb.send("boolean test", true);
sb.send("custom test", "youre loco"); sb.send("custom test", "youre loco");
last = millis(); last = millis();
} }
} }
} }
// define handler methods, all standard data type handlers take two appropriate arguments // define handler methods, all standard data type handlers take two appropriate arguments
void handleRange (String route, int value) { void handleRange (String route, int value) {
Serial.print("Range msg "); Serial.print("Range msg ");
Serial.print(route); Serial.print(route);
Serial.print(", value "); Serial.print(", value ");
Serial.println(value); Serial.println(value);
} }
void handleString (String route, String value) { void handleString (String route, String value) {
Serial.print("String msg "); Serial.print("String msg ");
Serial.print(route); Serial.print(route);
Serial.print(", value "); Serial.print(", value ");
Serial.println(value); Serial.println(value);
} }
void handleBoolean (String route, boolean value) { void handleBoolean (String route, boolean value) {
Serial.print("Boolen msg "); Serial.print("Boolen msg ");
Serial.print(route); Serial.print(route);
Serial.print(", value "); Serial.print(", value ");
Serial.println(value ? "true" : "false"); Serial.println(value ? "true" : "false");
} }
// custom data type handlers takes three String arguments // custom data type handlers takes three String arguments
void handleCustom (String route, String value, String type) { void handleCustom (String route, String value, String type) {
Serial.print("Custom msg "); Serial.print("Custom msg ");
Serial.print(route); Serial.print(route);
Serial.print(" of type "); Serial.print(" of type ");
Serial.print(type); Serial.print(type);
Serial.print(", value "); Serial.print(", value ");
Serial.println(value); Serial.println(value);
} }

View File

@ -35,55 +35,57 @@ int last_value = 0;
// create variables to manage interval between each time we send a string // create variables to manage interval between each time we send a string
void setup() { void setup() {
// start the serial port // start the serial port
Serial.begin(57600); Serial.begin(57600);
// 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();
// configure the spacebrew object to print status messages to serial // configure the spacebrew object to print status messages to serial
sb.verbose(true); sb.verbose(true);
// configure the spacebrew publisher and subscriber // configure the spacebrew publisher and subscriber
sb.addPublish("physical button", "boolean"); sb.addPublish("physical button", "boolean");
sb.addSubscribe("virtual button", "boolean"); sb.addSubscribe("virtual button", "boolean");
// register the string message handler method // register the string message handler method
sb.onBooleanMessage(handleBoolean); sb.onBooleanMessage(handleBoolean);
// connect to cloud spacebrew server at "sandbox.spacebrew.cc" // connect to cloud spacebrew server at "sandbox.spacebrew.cc"
sb.connect("sandbox.spacebrew.cc"); sb.connect("sandbox.spacebrew.cc");
pinMode(3, INPUT); pinMode(3, INPUT);
digitalWrite(3, HIGH); digitalWrite(3, HIGH);
} }
void loop() { void loop() {
// monitor spacebrew connection for new data // monitor spacebrew connection for new data
sb.monitor(); sb.monitor();
// connected to spacebrew then send a new value whenever the pot value changes // connected to spacebrew then send a new value whenever the pot value changes
if ( sb.connected() ) { if ( sb.connected() ) {
int cur_value = digitalRead(3); int cur_value = digitalRead(3);
if ( last_value != cur_value ) { if ( last_value != cur_value ) {
if (cur_value == HIGH) sb.send("physical button", false); if (cur_value == HIGH) sb.send("physical button", false);
else sb.send("physical button", true); else sb.send("physical button", true);
last_value = cur_value; last_value = cur_value;
} }
} }
} }
// handler method that is called whenever a new string message is received // handler method that is called whenever a new string message is received
void handleBoolean (String route, boolean value) { void handleBoolean (String route, boolean value) {
// print the message that was received // print the message that was received
Serial.print("From "); Serial.print("From ");
Serial.print(route); Serial.print(route);
Serial.print(", received msg: "); Serial.print(", received msg: ");
Serial.println(value ? "true" : "false"); Serial.println(value ? "true" : "false");
} }

View File

@ -36,51 +36,53 @@ int last_value = 0;
// create variables to manage interval between each time we send a string // create variables to manage interval between each time we send a string
void setup() { void setup() {
// start the serial port // start the serial port
Serial.begin(57600); Serial.begin(57600);
// 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();
// configure the spacebrew object to print status messages to serial // configure the spacebrew object to print status messages to serial
sb.verbose(true); sb.verbose(true);
// configure the spacebrew publisher and subscriber // configure the spacebrew publisher and subscriber
sb.addPublish("physical pot", "range"); sb.addPublish("physical pot", "range");
sb.addSubscribe("virtual pot", "range"); sb.addSubscribe("virtual pot", "range");
// register the string message handler method // register the string message handler method
sb.onRangeMessage(handleRange); sb.onRangeMessage(handleRange);
// connect to cloud spacebrew server at "sandbox.spacebrew.cc" // connect to cloud spacebrew server at "sandbox.spacebrew.cc"
sb.connect("sandbox.spacebrew.cc"); sb.connect("sandbox.spacebrew.cc");
} }
void loop() { void loop() {
// monitor spacebrew connection for new data // monitor spacebrew connection for new data
sb.monitor(); sb.monitor();
// connected to spacebrew then send a new value whenever the pot value changes // connected to spacebrew then send a new value whenever the pot value changes
if ( sb.connected() ) { if ( sb.connected() ) {
int cur_value = analogRead(A0); int cur_value = analogRead(A0);
if ( last_value != cur_value ) { if ( last_value != cur_value ) {
sb.send("physical pot", cur_value); sb.send("physical pot", cur_value);
last_value = cur_value; last_value = cur_value;
} }
} }
} }
// handler method that is called whenever a new string message is received // handler method that is called whenever a new string message is received
void handleRange (String route, int value) { void handleRange (String route, int value) {
// print the message that was received // print the message that was received
Serial.print("From "); Serial.print("From ");
Serial.print(route); Serial.print(route);
Serial.print(", received msg: "); Serial.print(", received msg: ");
Serial.println(value); Serial.println(value);
} }

View File

@ -33,52 +33,54 @@ int interval = 2000;
void setup() { void setup() {
// start the serial port // start the serial port
Serial.begin(57600); Serial.begin(57600);
// 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();
// configure the spacebrew object to print status messages to serial // configure the spacebrew object to print status messages to serial
sb.verbose(true); sb.verbose(true);
// configure the spacebrew publisher and subscriber // configure the spacebrew publisher and subscriber
sb.addPublish("speak", "string"); sb.addPublish("speak", "string");
sb.addSubscribe("listen", "string"); sb.addSubscribe("listen", "string");
// register the string message handler method // register the string message handler method
sb.onStringMessage(handleString); sb.onStringMessage(handleString);
// connect to cloud spacebrew server at "sandbox.spacebrew.cc" // connect to cloud spacebrew server at "sandbox.spacebrew.cc"
sb.connect("sandbox.spacebrew.cc"); sb.connect("sandbox.spacebrew.cc");
} }
void loop() { void loop() {
// monitor spacebrew connection for new data // monitor spacebrew connection for new data
sb.monitor(); sb.monitor();
// connected to spacebrew then send a string every 2 seconds // connected to spacebrew then send a string every 2 seconds
if ( sb.connected() ) { if ( sb.connected() ) {
// check if it is time to send a new message // check if it is time to send a new message
if ( (millis() - last_time) > interval ) { if ( (millis() - last_time) > interval ) {
sb.send("speak", "is anybody out there?"); sb.send("speak", "is anybody out there?");
last_time = millis(); last_time = millis();
} }
} }
} }
// handler method that is called whenever a new string message is received // handler method that is called whenever a new string message is received
void handleString (String route, String value) { void handleString (String route, String value) {
// print the message that was received // print the message that was received
Serial.print("From "); Serial.print("From ");
Serial.print(route); Serial.print(route);
Serial.print(", received msg: "); Serial.print(", received msg: ");
Serial.println(value); Serial.println(value);
} }

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()
@ -98,8 +98,8 @@ void loop()
// was able to send our request to the Temboo servers // was able to send our request to the Temboo servers
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();
} }
@ -99,7 +99,7 @@ void loop()
// a return code of zero (0) means everything worked // a return code of zero (0) means everything worked
if (returnCode == 0) { if (returnCode == 0) {
Serial.println("Success! Tweet sent!"); Serial.println("Success! Tweet sent!");
} 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

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();
} }
@ -89,7 +89,7 @@ void loop()
// then a subject line // then a subject line
SendEmailChoreo.addInput("Subject", "ALERT: Greenhouse Temperature"); SendEmailChoreo.addInput("Subject", "ALERT: Greenhouse Temperature");
// next comes the message body, the main content of the email // next comes the message body, the main content of the email
SendEmailChoreo.addInput("MessageBody", "Hey! The greenhouse is too cold!"); SendEmailChoreo.addInput("MessageBody", "Hey! The greenhouse is too cold!");
// tell the Choreo to run and wait for the results. The // tell the Choreo to run and wait for the results. The
@ -99,7 +99,7 @@ void loop()
// a return code of zero (0) means everything worked // a return code of zero (0) means everything worked
if (returnCode == 0) { if (returnCode == 0) {
Serial.println("Success! Email sent!"); Serial.println("Success! Email sent!");
} 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

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();
} }
@ -116,7 +116,7 @@ void loop()
// a return code of zero (0) means everything worked // a return code of zero (0) means everything worked
if (returnCode == 0) { if (returnCode == 0) {
Serial.println("Success! SMS sent!"); Serial.println("Success! SMS sent!");
} 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
@ -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);
@ -121,8 +121,8 @@ void loop()
// a return code of zero (0) means everything worked // a return code of zero (0) means everything worked
if (returnCode == 0) { if (returnCode == 0) {
Serial.println("Success! File uploaded!"); Serial.println("Success! File uploaded!");
success = true; success = true;
} else { } else {
// a non-zero return code means there was an error // a non-zero return code means there was an error
Serial.println("Uh-oh! Something went wrong!"); Serial.println("Uh-oh! Something went wrong!");
@ -149,41 +149,41 @@ void loop()
*/ */
String base64Encode(String toEncode) { String base64Encode(String toEncode) {
// we need a Process object to send a Choreo request to Temboo // we need a Process object to send a Choreo request to Temboo
TembooChoreo Base64EncodeChoreo; TembooChoreo Base64EncodeChoreo;
// invoke the Temboo client // invoke the Temboo client
Base64EncodeChoreo.begin(); Base64EncodeChoreo.begin();
// set Temboo account credentials // set Temboo account credentials
Base64EncodeChoreo.setAccountName(TEMBOO_ACCOUNT); Base64EncodeChoreo.setAccountName(TEMBOO_ACCOUNT);
Base64EncodeChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); Base64EncodeChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
Base64EncodeChoreo.setAppKey(TEMBOO_APP_KEY); Base64EncodeChoreo.setAppKey(TEMBOO_APP_KEY);
// identify the Temboo Library choreo to run (Utilities > Encoding > Base64Encode) // identify the Temboo Library choreo to run (Utilities > Encoding > Base64Encode)
Base64EncodeChoreo.setChoreo("/Library/Utilities/Encoding/Base64Encode"); Base64EncodeChoreo.setChoreo("/Library/Utilities/Encoding/Base64Encode");
// set choreo inputs // set choreo inputs
Base64EncodeChoreo.addInput("Text", toEncode); Base64EncodeChoreo.addInput("Text", toEncode);
// run the choreo // run the choreo
Base64EncodeChoreo.run(); Base64EncodeChoreo.run();
// 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();
// read the value of the output item // read the value of the output item
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,12 +26,12 @@ 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:
// hh:mm:ss : // hh:mm:ss :
if (!date.running()) { if (!date.running()) {
date.begin("date"); date.begin("date");
date.addParameter("+%T"); date.addParameter("+%T");
date.run(); date.run();
@ -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);
@ -52,7 +52,7 @@ void loop() {
Serial.println(seconds); Serial.println(seconds);
// restart the date process: // restart the date process:
if (!date.running()) { if (!date.running()) {
date.begin("date"); date.begin("date");
date.addParameter("+%T"); date.addParameter("+%T");
date.run(); date.run();
@ -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

@ -35,9 +35,9 @@ void loop() {
// convert the sensor readings to light levels: // convert the sensor readings to light levels:
byte red = constrain(mic, 0, 255); byte red = constrain(mic, 0, 255);
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

@ -30,11 +30,11 @@ void loop() {
Esplora.writeGreen(brightness); Esplora.writeGreen(brightness);
// print the microphone levels and the LED levels (to see what's going on): // print the microphone levels and the LED levels (to see what's going on):
Serial.print("sound level: "); Serial.print("sound level: ");
Serial.print(loudness); Serial.print(loudness);
Serial.print(" Green brightness: "); Serial.print(" Green brightness: ");
Serial.println(brightness); Serial.println(brightness);
// add a delay to keep the LED from flickering: // add a delay to keep the LED from flickering:
delay(10); delay(10);
} }

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,22 +48,22 @@ 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;
case 'R': case 'R':
setRed(); setRed();
break; break;
case 'G': case 'G':
setGreen(); setGreen();
break; break;
case 'B': case 'B':
setBlue(); setBlue();
break; break;
case 'T': case 'T':
setTone(); setTone();
break; break;
} }
} }

View File

@ -135,7 +135,7 @@ void printHeaders() {
Keyboard.print("Time"); Keyboard.print("Time");
Keyboard.write(KEY_TAB); Keyboard.write(KEY_TAB);
activeDelay(300); // Some spreadsheets are slow, e.g. Google activeDelay(300); // Some spreadsheets are slow, e.g. Google
// Drive that wants to save every edit. // Drive that wants to save every edit.
Keyboard.print("Accel X"); Keyboard.print("Accel X");
Keyboard.write(KEY_TAB); Keyboard.write(KEY_TAB);
activeDelay(300); activeDelay(300);
@ -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);
@ -39,9 +40,9 @@ void setup() {
Ethernet.begin(mac, ip, gateway, subnet); Ethernet.begin(mac, ip, gateway, subnet);
// start listening for clients // start listening for clients
server.begin(); server.begin();
// Open serial communications and wait for port to open: // Open serial communications and wait for port to open:
Serial.begin(9600); Serial.begin(9600);
while (!Serial) { while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only ; // wait for serial port to connect. Needed for Leonardo only
} }

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,14 +52,14 @@ char server[] = "api.cosm.com"; // name address for cosm API
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds 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);
// start the Ethernet connection: // start the Ethernet connection:
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");
// DHCP failed, so use a fixed IP address: // DHCP failed, so use a fixed IP address:
@ -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
@ -134,7 +135,7 @@ void sendData(int thisData) {
Serial.println("disconnecting."); Serial.println("disconnecting.");
client.stop(); client.stop();
} }
// note the time that the connection was made or attempted: // note the time that the connection was made or attempted:
lastConnectionTime = millis(); lastConnectionTime = millis();
} }
@ -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
@ -28,10 +29,10 @@ byte mac[] = {
EthernetClient client; EthernetClient client;
void setup() { void setup() {
// Open serial communications and wait for port to open: // Open serial communications and wait for port to open:
Serial.begin(9600); Serial.begin(9600);
// this check is only needed on the Leonardo: // this check is only needed on the Leonardo:
while (!Serial) { while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only ; // wait for serial port to connect. Needed for Leonardo only
} }
@ -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
@ -38,7 +39,7 @@ void setup() {
// Open serial communications and wait for port to open: // Open serial communications and wait for port to open:
Serial.begin(9600); Serial.begin(9600);
// this check is only needed on the Leonardo: // this check is only needed on the Leonardo:
while (!Serial) { while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only ; // wait for serial port to connect. Needed for Leonardo only
} }

View File

@ -35,32 +35,33 @@ 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:
Serial.begin(9600); Serial.begin(9600);
while (!Serial) { while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only ; // wait for serial port to connect. Needed for Leonardo only
} }
// start the Ethernet connection: // start the Ethernet connection:
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");
// DHCP failed, so use a fixed IP address: // DHCP failed, so use a fixed IP address:
@ -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
@ -136,7 +137,7 @@ void sendData(int thisData) {
Serial.println("disconnecting."); Serial.println("disconnecting.");
client.stop(); client.stop();
} }
// note the time that the connection was made or attempted: // note the time that the connection was made or attempted:
lastConnectionTime = millis(); lastConnectionTime = millis();
} }
@ -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,27 +37,28 @@
// 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:
Serial.begin(9600); Serial.begin(9600);
while (!Serial) { while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only ; // wait for serial port to connect. Needed for Leonardo only
@ -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

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