1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-16 11:21:18 +03: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
// the setup routine runs once when you press reset:
void setup() {
void setup() {
// declare pin 9 to be an output:
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
void loop() {
// set the brightness of pin 9:
analogWrite(led, brightness);

View File

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

View File

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

View File

@ -21,7 +21,7 @@
*/
void setup(){
void setup() {
//start serial connection
Serial.begin(9600);
//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
int sensorVal = digitalRead(2);
//print out the value of the pushbutton

View File

@ -79,7 +79,7 @@ void loop() {
if (buttonPushCounter % 4 == 0) {
digitalWrite(ledPin, HIGH);
} 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:
int notes[] = {
NOTE_A4, NOTE_B4,NOTE_C3 };
NOTE_A4, NOTE_B4, NOTE_C3
};
void setup() {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -48,11 +48,11 @@ void loop()
// get incoming byte:
inByte = Serial.read();
// read first analog input, divide by 4 to make the range 0-255:
firstSensor = analogRead(A0)/4;
firstSensor = analogRead(A0) / 4;
// delay 10ms to let the ADC recover:
delay(10);
// read second analog input, divide by 4 to make the range 0-255:
secondSensor = analogRead(1)/4;
secondSensor = analogRead(1) / 4;
// read switch, map it to 0 or 255L
thirdSensor = map(digitalRead(2), 0, 1, 0, 255);
// 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 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)
void setup() {
// the array elements are numbered from 0 to (pinCount - 1).
// use a for loop to initialize each pin as an output:
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
pinMode(ledPins[thisPin], OUTPUT);
}
}

View File

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

View File

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

View File

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

View File

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

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
void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT
Serial.begin(9600); // use the serial port
pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT
Serial.begin(9600); // use the serial port
}
void loop() {

View File

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

View File

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

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
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() {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -67,6 +67,6 @@ void loop() {
Serial.println(stringOne);
// 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);
// do nothing while true:
while(true);
while (true);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -38,8 +38,8 @@ const int ledPin = 5; // Mouse control LED
// parameters for reading the joystick:
int range = 12; // output range of X or Y movement
int responseDelay = 5; // response delay of the mouse, in ms
int threshold = range/4; // resting threshold
int center = range/2; // resting position value
int threshold = range / 4; // resting threshold
int center = range / 2; // resting position value
boolean mouseIsActive = false; // whether or not to control the mouse
int lastSwitchState = LOW; // previous switch state
@ -47,7 +47,7 @@ int lastSwitchState = LOW; // previous switch state
void setup() {
pinMode(switchPin, INPUT); // the switch pin
pinMode(ledPin, OUTPUT); // the LED pin
// take control of the mouse:
// take control of the mouse:
Mouse.begin();
}

View File

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

View File

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

View File

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

View File

@ -26,7 +26,7 @@
int notes[] = {262, 294, 330, 349};
void setup() {
//start serial communication
//start serial communication
Serial.begin(9600);
}
@ -37,23 +37,23 @@ void loop() {
Serial.println(keyVal);
// play the note corresponding to each value on A0
if(keyVal == 1023){
if (keyVal == 1023) {
// play the first frequency in the array on pin 8
tone(8, notes[0]);
}
else if(keyVal >= 990 && keyVal <= 1010){
else if (keyVal >= 990 && keyVal <= 1010) {
// play the second frequency in the array on pin 8
tone(8, notes[1]);
}
else if(keyVal >= 505 && keyVal <= 515){
else if (keyVal >= 505 && keyVal <= 515) {
// play the third frequency in the array on pin 8
tone(8, notes[2]);
}
else if(keyVal >= 5 && keyVal <= 10){
else if (keyVal >= 5 && keyVal <= 10) {
// play the fourth frequency in the array on pin 8
tone(8, notes[3]);
}
else{
else {
// if the value is out of range, play no tone
noTone(8);
}

View File

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

View File

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

View File

@ -44,7 +44,7 @@ void setup() {
lcd.begin(16, 2);
// set up the switch pin as an input
pinMode(switchPin,INPUT);
pinMode(switchPin, INPUT);
// Print a message to the LCD.
lcd.print("Ask the");
@ -77,38 +77,38 @@ void loop() {
lcd.setCursor(0, 1);
// choose a saying to print baed on the value in reply
switch(reply){
case 0:
lcd.print("Yes");
break;
switch (reply) {
case 0:
lcd.print("Yes");
break;
case 1:
lcd.print("Most likely");
break;
case 1:
lcd.print("Most likely");
break;
case 2:
lcd.print("Certainly");
break;
case 2:
lcd.print("Certainly");
break;
case 3:
lcd.print("Outlook good");
break;
case 3:
lcd.print("Outlook good");
break;
case 4:
lcd.print("Unsure");
break;
case 4:
lcd.print("Unsure");
break;
case 5:
lcd.print("Ask again");
break;
case 5:
lcd.print("Ask again");
break;
case 6:
lcd.print("Doubtful");
break;
case 6:
lcd.print("Doubtful");
break;
case 7:
lcd.print("No");
break;
case 7:
lcd.print("No");
break;
}
}
}

View File

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

View File

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

View File

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

View File

@ -20,18 +20,18 @@
const int optoPin = 2; // the pin the optocoupler is connected to
void setup(){
void setup() {
// make the pin with the optocoupler an output
pinMode(optoPin, OUTPUT);
}
void loop(){
digitalWrite(optoPin, HIGH); // pull pin 2 HIGH, activating the optocoupler
void loop() {
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
delay(21000); // wait for 21 seconds
digitalWrite(optoPin, LOW); // pull pin 2 low until you're ready to activate again
delay(21000); // wait for 21 seconds
}

View File

@ -75,8 +75,8 @@ void setup() {
pulse(LED_HB, 2);
}
int error=0;
int pmode=0;
int error = 0;
int pmode = 0;
// address for reading and writing, set by 'U' command
int here;
uint8_t buff[256]; // global block storage
@ -102,8 +102,8 @@ parameter;
parameter param;
// this provides a heartbeat on pin 9, so you can tell the software is running.
uint8_t hbval=128;
int8_t hbdelta=8;
uint8_t hbval = 128;
int8_t hbdelta = 8;
void heartbeat() {
if (hbval > 192) hbdelta = -hbdelta;
if (hbval < 32) hbdelta = -hbdelta;
@ -129,7 +129,7 @@ void loop(void) {
}
uint8_t getch() {
while(!Serial.available());
while (!Serial.available());
return Serial.read();
}
void fill(int n) {
@ -157,8 +157,8 @@ void prog_lamp(int state) {
void spi_init() {
uint8_t x;
SPCR = 0x53;
x=SPSR;
x=SPDR;
x = SPSR;
x = SPDR;
}
void spi_wait() {
@ -169,7 +169,7 @@ void spi_wait() {
uint8_t spi_send(uint8_t b) {
uint8_t reply;
SPDR=b;
SPDR = b;
spi_wait();
reply = SPDR;
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 n;
spi_send(a);
n=spi_send(b);
n = spi_send(b);
//if (n != a) error = -1;
n=spi_send(c);
n = spi_send(c);
return spi_send(d);
}
@ -208,21 +208,21 @@ void breply(uint8_t b) {
}
void get_version(uint8_t c) {
switch(c) {
case 0x80:
breply(HWVER);
break;
case 0x81:
breply(SWMAJ);
break;
case 0x82:
breply(SWMIN);
break;
case 0x93:
breply('S'); // serial programmer
break;
default:
breply(0);
switch (c) {
case 0x80:
breply(HWVER);
break;
case 0x81:
breply(SWMAJ);
break;
case 0x82:
breply(SWMIN);
break;
case 0x93:
breply('S'); // serial programmer
break;
default:
breply(0);
}
}
@ -245,9 +245,9 @@ void set_parameters() {
// 32 bits flashsize (big endian)
param.flashsize = buff[16] * 0x01000000
+ buff[17] * 0x00010000
+ buff[18] * 0x00000100
+ buff[19];
+ buff[17] * 0x00010000
+ buff[18] * 0x00000100
+ buff[19];
}
@ -285,10 +285,10 @@ void universal() {
}
void flash(uint8_t hilo, int addr, uint8_t data) {
spi_transaction(0x40+8*hilo,
addr>>8 & 0xFF,
addr & 0xFF,
data);
spi_transaction(0x40 + 8 * hilo,
addr >> 8 & 0xFF,
addr & 0xFF,
data);
}
void commit(int addr) {
if (PROG_FLICKER) prog_lamp(LOW);
@ -363,8 +363,8 @@ uint8_t write_eeprom_chunk(int start, int length) {
fill(length);
prog_lamp(LOW);
for (int x = 0; x < length; x++) {
int addr = start+x;
spi_transaction(0xC0, (addr>>8) & 0xFF, addr & 0xFF, buff[x]);
int addr = start + x;
spi_transaction(0xC0, (addr >> 8) & 0xFF, addr & 0xFF, buff[x]);
delay(45);
}
prog_lamp(HIGH);
@ -399,13 +399,13 @@ void program_page() {
uint8_t flash_read(uint8_t hilo, int addr) {
return spi_transaction(0x20 + hilo * 8,
(addr >> 8) & 0xFF,
addr & 0xFF,
0);
(addr >> 8) & 0xFF,
addr & 0xFF,
0);
}
char flash_read_page(int length) {
for (int x = 0; x < length; x+=2) {
for (int x = 0; x < length; x += 2) {
uint8_t low = flash_read(LOW, here);
Serial.print((char) low);
uint8_t high = flash_read(HIGH, here);
@ -468,85 +468,85 @@ int avrisp() {
uint8_t data, low, high;
uint8_t ch = getch();
switch (ch) {
case '0': // signon
error = 0;
empty_reply();
break;
case '1':
if (getch() == CRC_EOP) {
Serial.print((char) STK_INSYNC);
Serial.print("AVR ISP");
Serial.print((char) STK_OK);
}
break;
case 'A':
get_version(getch());
break;
case 'B':
fill(20);
set_parameters();
empty_reply();
break;
case 'E': // extended parameters - ignore for now
fill(5);
empty_reply();
break;
case '0': // signon
error = 0;
empty_reply();
break;
case '1':
if (getch() == CRC_EOP) {
Serial.print((char) STK_INSYNC);
Serial.print("AVR ISP");
Serial.print((char) STK_OK);
}
break;
case 'A':
get_version(getch());
break;
case 'B':
fill(20);
set_parameters();
empty_reply();
break;
case 'E': // extended parameters - ignore for now
fill(5);
empty_reply();
break;
case 'P':
start_pmode();
empty_reply();
break;
case 'U': // set address (word)
here = getch();
here += 256 * getch();
empty_reply();
break;
case 'P':
start_pmode();
empty_reply();
break;
case 'U': // set address (word)
here = getch();
here += 256 * getch();
empty_reply();
break;
case 0x60: //STK_PROG_FLASH
low = getch();
high = getch();
empty_reply();
break;
case 0x61: //STK_PROG_DATA
data = getch();
empty_reply();
break;
case 0x60: //STK_PROG_FLASH
low = getch();
high = getch();
empty_reply();
break;
case 0x61: //STK_PROG_DATA
data = getch();
empty_reply();
break;
case 0x64: //STK_PROG_PAGE
program_page();
break;
case 0x64: //STK_PROG_PAGE
program_page();
break;
case 0x74: //STK_READ_PAGE 't'
read_page();
break;
case 0x74: //STK_READ_PAGE 't'
read_page();
break;
case 'V': //0x56
universal();
break;
case 'Q': //0x51
error=0;
end_pmode();
empty_reply();
break;
case 'V': //0x56
universal();
break;
case 'Q': //0x51
error = 0;
end_pmode();
empty_reply();
break;
case 0x75: //STK_READ_SIGN 'u'
read_signature();
break;
case 0x75: //STK_READ_SIGN 'u'
read_signature();
break;
// expecting a command, not CRC_EOP
// this is how we can get back in sync
case CRC_EOP:
error++;
Serial.print((char) STK_NOSYNC);
break;
// expecting a command, not CRC_EOP
// this is how we can get back in sync
case CRC_EOP:
error++;
Serial.print((char) STK_NOSYNC);
break;
// anything else we will return STK_UNKNOWN
default:
error++;
if (CRC_EOP == getch())
Serial.print((char)STK_UNKNOWN);
else
Serial.print((char)STK_NOSYNC);
// anything else we will return STK_UNKNOWN
default:
error++;
if (CRC_EOP == getch())
Serial.print((char)STK_UNKNOWN);
else
Serial.print((char)STK_NOSYNC);
}
}

View File

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

View File

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

View File

@ -26,7 +26,7 @@
#include <Console.h>
void setup() {
//Initialize Console and wait for port to open:
//Initialize Console and wait for port to open:
Bridge.begin();
Console.begin();
@ -81,12 +81,12 @@ void loop() {
Console.println(thisByte, BIN);
// 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
Console.flush();
// This loop loops forever and does nothing
while(true) {
while (true) {
continue;
}
}

View File

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

View File

@ -38,7 +38,7 @@ void setup() {
Serial.begin(9600);
FileSystem.begin();
while(!Serial); // wait for Serial port to connect.
while (!Serial); // wait for Serial port to connect.
Serial.println("Filesystem datalogger\n");
}
@ -87,13 +87,13 @@ String getTimeStamp() {
// in different formats depending on the additional parameter
time.begin("date");
time.addParameter("+%D-%T"); // parameters: D for the complete date mm/dd/yy
// T for the time hh:mm:ss
// T for the time hh:mm:ss
time.run(); // run the command
// read the output of the command
while(time.available()>0) {
while (time.available() > 0) {
char c = time.read();
if(c != '\n')
if (c != '\n')
result += c;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -20,7 +20,7 @@
#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information
// as described in the footer comment below
// as described in the footer comment below
// 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
delay(4000);
while(!Serial);
while (!Serial);
Bridge.begin();
}
@ -79,7 +79,7 @@ void loop()
GetWeatherByAddressChoreo.run();
// when the choreo results are available, print them to the serial monitor
while(GetWeatherByAddressChoreo.available()) {
while (GetWeatherByAddressChoreo.available()) {
char c = GetWeatherByAddressChoreo.read();
Serial.print(c);

View File

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

View File

@ -28,7 +28,7 @@
#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information
// as described in the footer comment below
// as described in the footer comment below
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
@ -48,7 +48,7 @@ void setup() {
// for debugging, wait until a serial console is connected
delay(4000);
while(!Serial);
while (!Serial);
Bridge.begin();
}
@ -99,7 +99,7 @@ void loop()
// a return code of zero (0) means everything worked
if (returnCode == 0) {
Serial.println("Success! Tweet sent!");
Serial.println("Success! Tweet sent!");
} else {
// a non-zero return code means there was an error
// read and print the error message

View File

@ -24,7 +24,7 @@
#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information
// as described in the footer comment below
// as described in the footer comment below
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
@ -48,7 +48,7 @@ void setup() {
// for debugging, wait until a serial console is connected
delay(4000);
while(!Serial);
while (!Serial);
Bridge.begin();
}
@ -89,7 +89,7 @@ void loop()
// then a subject line
SendEmailChoreo.addInput("Subject", "ALERT: Greenhouse Temperature");
// next comes the message body, the main content of the email
// next comes the message body, the main content of the email
SendEmailChoreo.addInput("MessageBody", "Hey! The greenhouse is too cold!");
// tell the Choreo to run and wait for the results. The
@ -99,7 +99,7 @@ void loop()
// a return code of zero (0) means everything worked
if (returnCode == 0) {
Serial.println("Success! Email sent!");
Serial.println("Success! Email sent!");
} else {
// a non-zero return code means there was an error
// read and print the error message

View File

@ -33,7 +33,7 @@
#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information
// as described in the footer comment below
// as described in the footer comment below
@ -62,7 +62,7 @@ void setup() {
// for debugging, wait until a serial console is connected
delay(4000);
while(!Serial);
while (!Serial);
Bridge.begin();
}
@ -116,7 +116,7 @@ void loop()
// a return code of zero (0) means everything worked
if (returnCode == 0) {
Serial.println("Success! SMS sent!");
Serial.println("Success! SMS sent!");
} else {
// a non-zero return code means there was an error
// read and print the error message
@ -128,7 +128,7 @@ void loop()
SendSMSChoreo.close();
// set the flag indicatine we've tried once.
attempted=true;
attempted = true;
}
}

View File

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

View File

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

View File

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

View File

@ -32,7 +32,7 @@
#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information
// as described in the footer comment below
// as described in the footer comment below
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
@ -60,7 +60,7 @@ void setup() {
// For debugging, wait until a serial console is connected.
delay(4000);
while(!Serial);
while (!Serial);
Bridge.begin();
}
@ -103,7 +103,7 @@ void loop()
// next, the root folder on Dropbox relative to which the file path is specified.
// to work with the Dropbox app you created earlier, this should be left as "sandbox"
// if your Dropbox app has full access to your files, specify "dropbox"
UploadFileChoreo.addInput("Root","sandbox");
UploadFileChoreo.addInput("Root", "sandbox");
// next, the Base64 encoded file data to upload
UploadFileChoreo.addInput("FileContents", base64EncodedData);
@ -121,8 +121,8 @@ void loop()
// a return code of zero (0) means everything worked
if (returnCode == 0) {
Serial.println("Success! File uploaded!");
success = true;
Serial.println("Success! File uploaded!");
success = true;
} else {
// a non-zero return code means there was an error
Serial.println("Uh-oh! Something went wrong!");
@ -149,41 +149,41 @@ void loop()
*/
String base64Encode(String toEncode) {
// we need a Process object to send a Choreo request to Temboo
TembooChoreo Base64EncodeChoreo;
// we need a Process object to send a Choreo request to Temboo
TembooChoreo Base64EncodeChoreo;
// invoke the Temboo client
Base64EncodeChoreo.begin();
// invoke the Temboo client
Base64EncodeChoreo.begin();
// set Temboo account credentials
Base64EncodeChoreo.setAccountName(TEMBOO_ACCOUNT);
Base64EncodeChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
Base64EncodeChoreo.setAppKey(TEMBOO_APP_KEY);
// set Temboo account credentials
Base64EncodeChoreo.setAccountName(TEMBOO_ACCOUNT);
Base64EncodeChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
Base64EncodeChoreo.setAppKey(TEMBOO_APP_KEY);
// identify the Temboo Library choreo to run (Utilities > Encoding > Base64Encode)
Base64EncodeChoreo.setChoreo("/Library/Utilities/Encoding/Base64Encode");
// identify the Temboo Library choreo to run (Utilities > Encoding > Base64Encode)
Base64EncodeChoreo.setChoreo("/Library/Utilities/Encoding/Base64Encode");
// set choreo inputs
Base64EncodeChoreo.addInput("Text", toEncode);
// set choreo inputs
Base64EncodeChoreo.addInput("Text", toEncode);
// run the choreo
Base64EncodeChoreo.run();
// run the choreo
Base64EncodeChoreo.run();
// read in the choreo results, and return the "Base64EncodedText" output value.
// see http://www.temboo.com/arduino for more details on using choreo outputs.
while(Base64EncodeChoreo.available()) {
// read the name of the output item
String name = Base64EncodeChoreo.readStringUntil('\x1F');
name.trim();
// read in the choreo results, and return the "Base64EncodedText" output value.
// see http://www.temboo.com/arduino for more details on using choreo outputs.
while (Base64EncodeChoreo.available()) {
// read the name of the output item
String name = Base64EncodeChoreo.readStringUntil('\x1F');
name.trim();
// read the value of the output item
String data = Base64EncodeChoreo.readStringUntil('\x1E');
data.trim();
// read the value of the output item
String data = Base64EncodeChoreo.readStringUntil('\x1E');
data.trim();
if(name == "Base64EncodedText") {
return data;
}
if (name == "Base64EncodedText") {
return data;
}
}
}
/*

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -135,7 +135,7 @@ void printHeaders() {
Keyboard.print("Time");
Keyboard.write(KEY_TAB);
activeDelay(300); // Some spreadsheets are slow, e.g. Google
// Drive that wants to save every edit.
// Drive that wants to save every edit.
Keyboard.print("Accel X");
Keyboard.write(KEY_TAB);
activeDelay(300);
@ -149,7 +149,7 @@ void printHeaders() {
void logAndPrint() {
// do all the samplings at once, because keystrokes have delays
unsigned long timeSecs = (millis() - startedAt) /1000;
unsigned long timeSecs = (millis() - startedAt) / 1000;
int xAxis = Esplora.readAccelerometer(X_AXIS);
int yAxis = Esplora.readAccelerometer(Y_AXIS);
int zAxis = Esplora.readAccelerometer(Z_AXIS);

View File

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

View File

@ -24,9 +24,10 @@
// The IP address will be dependent on your local network.
// gateway and subnet are optional:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1, 177);
IPAddress gateway(192,168,1, 1);
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 0, 0);
@ -39,9 +40,9 @@ void setup() {
Ethernet.begin(mac, ip, gateway, subnet);
// start listening for clients
server.begin();
// Open serial communications and wait for port to open:
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}

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
// fill in your address here:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
// fill in an available IP address on your network here,
// for manual configuration:
IPAddress ip(10,0,1,20);
IPAddress ip(10, 0, 1, 20);
// initialize the library instance:
EthernetClient client;
@ -51,14 +52,14 @@ char server[] = "api.cosm.com"; // name address for cosm API
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
boolean lastConnected = false; // state of the connection last time through the main loop
const unsigned long postingInterval = 10L*1000L; // delay between updates to cosm.com
// the "L" is needed to use long type numbers
const unsigned long postingInterval = 10L * 1000L; // delay between updates to cosm.com
// the "L" is needed to use long type numbers
void setup() {
// start serial port:
Serial.begin(9600);
// start the Ethernet connection:
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// DHCP failed, so use a fixed IP address:
@ -88,7 +89,7 @@ void loop() {
// if you're not connected, and ten seconds have passed since
// your last connection, then connect again and send data:
if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
if (!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
sendData(sensorReading);
}
// store the state of the connection for next time through
@ -134,7 +135,7 @@ void sendData(int thisData) {
Serial.println("disconnecting.");
client.stop();
}
// note the time that the connection was made or attempted:
// note the time that the connection was made or attempted:
lastConnectionTime = millis();
}
@ -150,9 +151,9 @@ int getLength(int someValue) {
// continually divide the value by ten,
// adding one to the digit count for each
// time you divide, until you're at 0:
int dividend = someValue /10;
int dividend = someValue / 10;
while (dividend > 0) {
dividend = dividend /10;
dividend = dividend / 10;
digits++;
}
// return the number of digits:

View File

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

View File

@ -20,7 +20,8 @@
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
};
// Initialize the Ethernet client library
// with the IP address and port of the server
@ -28,10 +29,10 @@ byte mac[] = {
EthernetClient client;
void setup() {
// Open serial communications and wait for port to open:
// Open serial communications and wait for port to open:
Serial.begin(9600);
// this check is only needed on the Leonardo:
while (!Serial) {
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
@ -39,7 +40,7 @@ void setup() {
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for(;;)
for (;;)
;
}
// print your local IP address:

View File

@ -25,9 +25,10 @@
// The IP address will be dependent on your local network.
// gateway and subnet are optional:
byte mac[] = {
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
IPAddress ip(192,168,1, 177);
IPAddress gateway(192,168,1, 1);
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
};
IPAddress ip(192, 168, 1, 177);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 0, 0);
// telnet defaults to port 23
@ -38,7 +39,7 @@ void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// this check is only needed on the Leonardo:
while (!Serial) {
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}

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
// fill in your address here:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
// fill in an available IP address on your network here,
// for manual configuration:
IPAddress ip(10,0,1,20);
IPAddress ip(10, 0, 1, 20);
// initialize the library instance:
EthernetClient client;
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
IPAddress server(216,52,233,122); // numeric IP for api.pachube.com
IPAddress server(216, 52, 233, 122); // numeric IP for api.pachube.com
//char server[] = "api.pachube.com"; // name address for pachube API
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
boolean lastConnected = false; // state of the connection last time through the main loop
const unsigned long postingInterval = 10*1000; //delay between updates to Pachube.com
const unsigned long postingInterval = 10 * 1000; //delay between updates to Pachube.com
void setup() {
// Open serial communications and wait for port to open:
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection:
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// DHCP failed, so use a fixed IP address:
@ -90,7 +91,7 @@ void loop() {
// if you're not connected, and ten seconds have passed since
// your last connection, then connect again and send data:
if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
if (!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
sendData(sensorReading);
}
// store the state of the connection for next time through
@ -136,7 +137,7 @@ void sendData(int thisData) {
Serial.println("disconnecting.");
client.stop();
}
// note the time that the connection was made or attempted:
// note the time that the connection was made or attempted:
lastConnectionTime = millis();
}
@ -152,9 +153,9 @@ int getLength(int someValue) {
// continually divide the value by ten,
// adding one to the digit count for each
// time you divide, until you're at 0:
int dividend = someValue /10;
int dividend = someValue / 10;
while (dividend > 0) {
dividend = dividend /10;
dividend = dividend / 10;
digits++;
}
// return the number of digits:

View File

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