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:
@ -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;
|
||||
|
||||
|
@ -39,7 +39,7 @@ void setup() {
|
||||
pinMode(buttonPin, INPUT);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
void loop() {
|
||||
// read the state of the pushbutton value:
|
||||
buttonState = digitalRead(buttonPin);
|
||||
|
||||
|
@ -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
|
||||
|
@ -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() {
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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);
|
||||
|
@ -26,7 +26,7 @@ void setup() {
|
||||
|
||||
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
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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:
|
||||
|
@ -23,7 +23,8 @@ 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() {
|
||||
|
@ -46,7 +46,7 @@ void loop() {
|
||||
digitalWrite(ledPin, HIGH);
|
||||
}
|
||||
else {
|
||||
digitalWrite(ledPin,LOW);
|
||||
digitalWrite(ledPin, LOW);
|
||||
}
|
||||
|
||||
// print the analog value:
|
||||
|
@ -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:
|
||||
|
@ -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];
|
||||
|
@ -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() {
|
||||
|
@ -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)) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -39,5 +39,5 @@ void loop() {
|
||||
|
||||
|
||||
// do nothing while true:
|
||||
while(true);
|
||||
while (true);
|
||||
}
|
||||
|
@ -41,6 +41,6 @@ void loop() {
|
||||
Serial.println(reportString);
|
||||
|
||||
// do nothing while true:
|
||||
while(true);
|
||||
while (true);
|
||||
}
|
||||
|
||||
|
@ -116,7 +116,7 @@ void loop() {
|
||||
|
||||
while (true) {
|
||||
stringOne = "Sensor: ";
|
||||
stringTwo= "Sensor: ";
|
||||
stringTwo = "Sensor: ";
|
||||
|
||||
stringOne += analogRead(A0);
|
||||
stringTwo += analogRead(A5);
|
||||
|
@ -67,6 +67,6 @@ void loop() {
|
||||
Serial.println(stringOne);
|
||||
|
||||
// do nothing while true:
|
||||
while(true);
|
||||
while (true);
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -38,5 +38,5 @@ void loop() {
|
||||
Serial.println(stringOne.length());
|
||||
|
||||
// do nothing while true:
|
||||
while(true);
|
||||
while (true);
|
||||
}
|
||||
|
@ -46,5 +46,5 @@ void loop() {
|
||||
Serial.println("l33tspeak: " + leetString);
|
||||
|
||||
// do nothing while true:
|
||||
while(true);
|
||||
while (true);
|
||||
}
|
||||
|
@ -51,5 +51,5 @@ void loop() {
|
||||
}
|
||||
|
||||
// do nothing while true:
|
||||
while(true);
|
||||
while (true);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ void loop() {
|
||||
}
|
||||
|
||||
// do nothing:
|
||||
while(true);
|
||||
while (true);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)) {
|
||||
|
@ -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
|
||||
|
@ -26,17 +26,17 @@
|
||||
// switchState, you’re 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
|
||||
|
@ -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);
|
||||
|
@ -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: ");
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ void setup() {
|
||||
pinMode(switchPin, INPUT);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
void loop() {
|
||||
// read the state of the switch value:
|
||||
switchState = digitalRead(switchPin);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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,7 +77,7 @@ void loop() {
|
||||
lcd.setCursor(0, 1);
|
||||
|
||||
// choose a saying to print baed on the value in reply
|
||||
switch(reply){
|
||||
switch (reply) {
|
||||
case 0:
|
||||
lcd.print("Yes");
|
||||
break;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -20,12 +20,12 @@
|
||||
|
||||
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(){
|
||||
void loop() {
|
||||
digitalWrite(optoPin, HIGH); // pull pin 2 HIGH, activating the optocoupler
|
||||
|
||||
delay(15); // give the optocoupler a moment to activate
|
||||
|
@ -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,7 +208,7 @@ void breply(uint8_t b) {
|
||||
}
|
||||
|
||||
void get_version(uint8_t c) {
|
||||
switch(c) {
|
||||
switch (c) {
|
||||
case 0x80:
|
||||
breply(HWVER);
|
||||
break;
|
||||
@ -285,8 +285,8 @@ void universal() {
|
||||
}
|
||||
|
||||
void flash(uint8_t hilo, int addr, uint8_t data) {
|
||||
spi_transaction(0x40+8*hilo,
|
||||
addr>>8 & 0xFF,
|
||||
spi_transaction(0x40 + 8 * hilo,
|
||||
addr >> 8 & 0xFF,
|
||||
addr & 0xFF,
|
||||
data);
|
||||
}
|
||||
@ -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);
|
||||
@ -405,7 +405,7 @@ uint8_t flash_read(uint8_t hilo, int addr) {
|
||||
}
|
||||
|
||||
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);
|
||||
@ -524,7 +524,7 @@ int avrisp() {
|
||||
universal();
|
||||
break;
|
||||
case 'Q': //0x51
|
||||
error=0;
|
||||
error = 0;
|
||||
end_pmode();
|
||||
empty_reply();
|
||||
break;
|
||||
|
@ -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");
|
||||
|
@ -32,7 +32,7 @@ YunServer server;
|
||||
|
||||
void setup() {
|
||||
// Bridge startup
|
||||
pinMode(13,OUTPUT);
|
||||
pinMode(13, OUTPUT);
|
||||
digitalWrite(13, LOW);
|
||||
Bridge.begin();
|
||||
digitalWrite(13, HIGH);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
@ -91,9 +91,9 @@ String getTimeStamp() {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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() {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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()) {
|
||||
|
@ -40,7 +40,9 @@ void setup() {
|
||||
|
||||
// for debugging, wait until a serial console is connected
|
||||
delay(4000);
|
||||
while (!Serial) { ; }
|
||||
while (!Serial) {
|
||||
;
|
||||
}
|
||||
|
||||
// start-up the bridge
|
||||
Bridge.begin();
|
||||
|
@ -40,7 +40,9 @@ void setup() {
|
||||
|
||||
// for debugging, wait until a serial console is connected
|
||||
delay(4000);
|
||||
while (!Serial) { ; }
|
||||
while (!Serial) {
|
||||
;
|
||||
}
|
||||
|
||||
// start-up the bridge
|
||||
Bridge.begin();
|
||||
|
@ -41,7 +41,9 @@ void setup() {
|
||||
|
||||
// for debugging, wait until a serial console is connected
|
||||
delay(4000);
|
||||
while (!Serial) { ; }
|
||||
while (!Serial) {
|
||||
;
|
||||
}
|
||||
|
||||
// start-up the bridge
|
||||
Bridge.begin();
|
||||
|
@ -38,7 +38,9 @@ void setup() {
|
||||
|
||||
// for debugging, wait until a serial console is connected
|
||||
delay(4000);
|
||||
while (!Serial) { ; }
|
||||
while (!Serial) {
|
||||
;
|
||||
}
|
||||
|
||||
// start-up the bridge
|
||||
Bridge.begin();
|
||||
|
@ -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.
|
||||
|
@ -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);
|
||||
|
@ -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()
|
||||
@ -99,7 +99,7 @@ void loop()
|
||||
unsigned int returnCode = HomeTimelineChoreo.run();
|
||||
|
||||
// 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 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);
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
@ -128,7 +128,7 @@ void loop()
|
||||
SendSMSChoreo.close();
|
||||
|
||||
// set the flag indicatine we've tried once.
|
||||
attempted=true;
|
||||
attempted = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
@ -171,7 +171,7 @@ String base64Encode(String toEncode) {
|
||||
|
||||
// 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()) {
|
||||
while (Base64EncodeChoreo.available()) {
|
||||
// read the name of the output item
|
||||
String name = Base64EncodeChoreo.readStringUntil('\x1F');
|
||||
name.trim();
|
||||
@ -180,7 +180,7 @@ String base64Encode(String toEncode) {
|
||||
String data = Base64EncodeChoreo.readStringUntil('\x1E');
|
||||
data.trim();
|
||||
|
||||
if(name == "Base64EncodedText") {
|
||||
if (name == "Base64EncodedText") {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -26,7 +26,7 @@ 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:
|
||||
@ -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);
|
||||
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -37,7 +37,7 @@ void loop() {
|
||||
byte green = constrain(
|
||||
map(light, lowLight, highLight, minGreen, maxGreen),
|
||||
0, 255);
|
||||
byte blue = slider/4;
|
||||
byte blue = slider / 4;
|
||||
|
||||
// print the light levels (to see what's going on):
|
||||
Serial.print(red);
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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() {
|
||||
|
@ -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!
|
||||
|
@ -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,7 +48,7 @@ void loop() {
|
||||
*/
|
||||
void parseCommand() {
|
||||
char cmd = Serial.read();
|
||||
switch(cmd) {
|
||||
switch (cmd) {
|
||||
case 'D':
|
||||
dumpInputs();
|
||||
break;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
||||
|
@ -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,8 +52,8 @@ char server[] = "api.cosm.com"; // name address for cosm API
|
||||
|
||||
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
|
||||
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() {
|
||||
@ -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
|
||||
@ -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:
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
@ -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:
|
||||
|
@ -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
|
||||
|
@ -35,22 +35,23 @@ 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:
|
||||
@ -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
|
||||
@ -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:
|
||||
|
@ -37,24 +37,25 @@
|
||||
|
||||
// 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:
|
||||
@ -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
|
||||
|
@ -24,11 +24,12 @@
|
||||
// Enter a MAC address and IP address for your controller below.
|
||||
// The IP address will be dependent on your local network:
|
||||
byte mac[] = {
|
||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
||||
IPAddress ip(192,168,1,177);
|
||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
|
||||
};
|
||||
IPAddress ip(192, 168, 1, 177);
|
||||
|
||||
// Enter the IP address of the server you're connecting to:
|
||||
IPAddress server(1,1,1,1);
|
||||
IPAddress server(1, 1, 1, 1);
|
||||
|
||||
// Initialize the Ethernet client library
|
||||
// with the IP address and port of the server
|
||||
@ -84,7 +85,7 @@ void loop()
|
||||
Serial.println("disconnecting.");
|
||||
client.stop();
|
||||
// do nothing:
|
||||
while(true);
|
||||
while (true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,8 @@
|
||||
// Enter a MAC address and IP address for your controller below.
|
||||
// The IP address will be dependent on your local network:
|
||||
byte mac[] = {
|
||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
|
||||
};
|
||||
IPAddress ip(192, 168, 1, 177);
|
||||
|
||||
unsigned int localPort = 8888; // local port to listen on
|
||||
@ -35,7 +36,7 @@ EthernetUDP Udp;
|
||||
|
||||
void setup() {
|
||||
// start the Ethernet and UDP:
|
||||
Ethernet.begin(mac,ip);
|
||||
Ethernet.begin(mac, ip);
|
||||
Udp.begin(localPort);
|
||||
|
||||
Serial.begin(9600);
|
||||
@ -44,13 +45,13 @@ void setup() {
|
||||
void loop() {
|
||||
// if there's data available, read a packet
|
||||
int packetSize = Udp.parsePacket();
|
||||
if(packetSize)
|
||||
if (packetSize)
|
||||
{
|
||||
Serial.print("Received packet of size ");
|
||||
Serial.println(packetSize);
|
||||
Serial.print("From ");
|
||||
IPAddress remote = Udp.remoteIP();
|
||||
for (int i =0; i < 4; i++)
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
Serial.print(remote[i], DEC);
|
||||
if (i < 3)
|
||||
@ -62,7 +63,7 @@ void loop() {
|
||||
Serial.println(Udp.remotePort());
|
||||
|
||||
// read the packet into packetBufffer
|
||||
Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
|
||||
Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
|
||||
Serial.println("Contents:");
|
||||
Serial.println(packetBuffer);
|
||||
|
||||
|
@ -23,13 +23,14 @@
|
||||
// Enter a MAC address for your controller below.
|
||||
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
|
||||
byte mac[] = {
|
||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
|
||||
};
|
||||
|
||||
unsigned int localPort = 8888; // local port to listen for UDP packets
|
||||
|
||||
IPAddress timeServer(192, 43, 244, 18); // time.nist.gov NTP server
|
||||
|
||||
const int NTP_PACKET_SIZE= 48; // NTP time stamp is in the first 48 bytes of the message
|
||||
const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message
|
||||
|
||||
byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets
|
||||
|
||||
@ -49,7 +50,7 @@ void setup()
|
||||
if (Ethernet.begin(mac) == 0) {
|
||||
Serial.println("Failed to configure Ethernet using DHCP");
|
||||
// no point in carrying on, so do nothing forevermore:
|
||||
for(;;)
|
||||
for (;;)
|
||||
;
|
||||
}
|
||||
Udp.begin(localPort);
|
||||
@ -63,7 +64,7 @@ void loop()
|
||||
delay(1000);
|
||||
if ( Udp.parsePacket() ) {
|
||||
// We've received a packet, read the data from it
|
||||
Udp.read(packetBuffer,NTP_PACKET_SIZE); // read the packet into the buffer
|
||||
Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer
|
||||
|
||||
//the timestamp starts at byte 40 of the received packet and is four bytes,
|
||||
// or two words, long. First, esxtract the two words:
|
||||
@ -100,7 +101,7 @@ void loop()
|
||||
// In the first 10 seconds of each minute, we'll want a leading '0'
|
||||
Serial.print('0');
|
||||
}
|
||||
Serial.println(epoch %60); // print the second
|
||||
Serial.println(epoch % 60); // print the second
|
||||
}
|
||||
// wait ten seconds before asking for the time again
|
||||
delay(10000);
|
||||
@ -126,7 +127,7 @@ unsigned long sendNTPpacket(IPAddress& address)
|
||||
// all NTP fields have been given values, now
|
||||
// you can send a packet requesting a timestamp:
|
||||
Udp.beginPacket(address, 123); //NTP requests are to port 123
|
||||
Udp.write(packetBuffer,NTP_PACKET_SIZE);
|
||||
Udp.write(packetBuffer, NTP_PACKET_SIZE);
|
||||
Udp.endPacket();
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
||||
char server[] = "www.google.com"; // name address for Google (using DNS)
|
||||
|
||||
// Set the static IP address to use if the DHCP fails to assign
|
||||
IPAddress ip(192,168,0,177);
|
||||
IPAddress ip(192, 168, 0, 177);
|
||||
|
||||
// Initialize the Ethernet client library
|
||||
// with the IP address and port of the server
|
||||
@ -82,7 +82,7 @@ void loop()
|
||||
client.stop();
|
||||
|
||||
// do nothing forevermore:
|
||||
while(true);
|
||||
while (true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,13 +26,14 @@
|
||||
// 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
|
||||
};
|
||||
// fill in an available IP address on your network here,
|
||||
// for manual configuration:
|
||||
IPAddress ip(10,0,0,20);
|
||||
IPAddress ip(10, 0, 0, 20);
|
||||
|
||||
// fill in your Domain Name Server address here:
|
||||
IPAddress myDns(1,1,1,1);
|
||||
IPAddress myDns(1, 1, 1, 1);
|
||||
|
||||
// initialize the library instance:
|
||||
EthernetClient client;
|
||||
@ -41,8 +42,8 @@ char server[] = "www.arduino.cc";
|
||||
|
||||
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
|
||||
boolean lastConnected = false; // state of the connection last time through the main loop
|
||||
const unsigned long postingInterval = 60L*1000L; // delay between updates, in milliseconds
|
||||
// the "L" is needed to use long type numbers
|
||||
const unsigned long postingInterval = 60L * 1000L; // delay between updates, in milliseconds
|
||||
// the "L" is needed to use long type numbers
|
||||
|
||||
void setup() {
|
||||
// start serial port:
|
||||
@ -75,7 +76,7 @@ void loop() {
|
||||
|
||||
// if you're not connected, and ten seconds have passed since
|
||||
// your last connection, then connect again and send data:
|
||||
if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
|
||||
if (!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
|
||||
httpRequest();
|
||||
}
|
||||
// store the state of the connection for next time through
|
||||
|
@ -21,8 +21,9 @@
|
||||
// Enter a MAC address and IP address for your controller below.
|
||||
// The IP address will be dependent on your local network:
|
||||
byte mac[] = {
|
||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
||||
IPAddress ip(192,168,1,177);
|
||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
|
||||
};
|
||||
IPAddress ip(192, 168, 1, 177);
|
||||
|
||||
// Initialize the Ethernet server library
|
||||
// with the IP address and port you want to use
|
||||
|
@ -35,7 +35,7 @@ int samplingInterval = 19; // how often to run the main loop (in ms)
|
||||
void sendPort(byte portNumber, byte portValue)
|
||||
{
|
||||
portValue = portValue & portStatus[portNumber];
|
||||
if(previousPINs[portNumber] != portValue) {
|
||||
if (previousPINs[portNumber] != portValue) {
|
||||
Firmata.sendDigitalPort(portNumber, portValue);
|
||||
previousPINs[portNumber] = portValue;
|
||||
}
|
||||
@ -47,13 +47,13 @@ void setup()
|
||||
|
||||
Firmata.setFirmwareVersion(0, 1);
|
||||
|
||||
for(pin = 0; pin < TOTAL_PINS; pin++) {
|
||||
for (pin = 0; pin < TOTAL_PINS; pin++) {
|
||||
if IS_PIN_DIGITAL(pin) pinMode(PIN_TO_DIGITAL(pin), INPUT);
|
||||
}
|
||||
|
||||
for (port=0; port<TOTAL_PORTS; port++) {
|
||||
for (port = 0; port < TOTAL_PORTS; port++) {
|
||||
status = 0;
|
||||
for (i=0; i<8; i++) {
|
||||
for (i = 0; i < 8; i++) {
|
||||
if (IS_PIN_DIGITAL(port * 8 + i)) status |= (1 << i);
|
||||
}
|
||||
portStatus[port] = status;
|
||||
@ -66,20 +66,20 @@ void loop()
|
||||
{
|
||||
byte i;
|
||||
|
||||
for (i=0; i<TOTAL_PORTS; i++) {
|
||||
for (i = 0; i < TOTAL_PORTS; i++) {
|
||||
sendPort(i, readPort(i, 0xff));
|
||||
}
|
||||
/* make sure that the FTDI buffer doesn't go over 60 bytes, otherwise you
|
||||
get long, random delays. So only read analogs every 20ms or so */
|
||||
currentMillis = millis();
|
||||
if(currentMillis - previousMillis > samplingInterval) {
|
||||
if (currentMillis - previousMillis > samplingInterval) {
|
||||
previousMillis += samplingInterval;
|
||||
while(Firmata.available()) {
|
||||
while (Firmata.available()) {
|
||||
Firmata.processInput();
|
||||
}
|
||||
for(pin = 0; pin < TOTAL_ANALOG_PINS; pin++) {
|
||||
for (pin = 0; pin < TOTAL_ANALOG_PINS; pin++) {
|
||||
analogValue = analogRead(pin);
|
||||
if(analogValue != previousAnalogValues[pin]) {
|
||||
if (analogValue != previousAnalogValues[pin]) {
|
||||
Firmata.sendAnalog(pin, analogValue);
|
||||
previousAnalogValues[pin] = analogValue;
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ unsigned long previousMillis; // for comparison with currentMillis
|
||||
|
||||
void analogWriteCallback(byte pin, int value)
|
||||
{
|
||||
switch(pin) {
|
||||
switch (pin) {
|
||||
case 9: servo9.write(value); break;
|
||||
case 10: servo10.write(value); break;
|
||||
case 3:
|
||||
@ -52,7 +52,7 @@ void analogWriteCallback(byte pin, int value)
|
||||
// sets bits in a bit array (int) to toggle the reporting of the analogIns
|
||||
void reportAnalogCallback(byte pin, int value)
|
||||
{
|
||||
if(value == 0) {
|
||||
if (value == 0) {
|
||||
analogInputsToReport = analogInputsToReport &~ (1 << pin);
|
||||
}
|
||||
else { // everything but 0 enables reporting of that pin
|
||||
@ -80,13 +80,13 @@ void setup()
|
||||
*============================================================================*/
|
||||
void loop()
|
||||
{
|
||||
while(Firmata.available())
|
||||
while (Firmata.available())
|
||||
Firmata.processInput();
|
||||
currentMillis = millis();
|
||||
if(currentMillis - previousMillis > 20) {
|
||||
if (currentMillis - previousMillis > 20) {
|
||||
previousMillis += 20; // run this every 20ms
|
||||
for(analogPin=0;analogPin<TOTAL_ANALOG_PINS;analogPin++) {
|
||||
if( analogInputsToReport & (1 << analogPin) )
|
||||
for (analogPin = 0; analogPin < TOTAL_ANALOG_PINS; analogPin++) {
|
||||
if ( analogInputsToReport & (1 << analogPin) )
|
||||
Firmata.sendAnalog(analogPin, analogRead(analogPin));
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ void setup()
|
||||
|
||||
void loop()
|
||||
{
|
||||
while(Firmata.available()) {
|
||||
while (Firmata.available()) {
|
||||
Firmata.processInput();
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ unsigned long previousMillis; // for comparison with currentMillis
|
||||
void outputPort(byte portNumber, byte portValue)
|
||||
{
|
||||
portValue = portValue &~ portStatus[portNumber];
|
||||
if(previousPINs[portNumber] != portValue) {
|
||||
if (previousPINs[portNumber] != portValue) {
|
||||
Firmata.sendDigitalPort(portNumber, portValue);
|
||||
previousPINs[portNumber] = portValue;
|
||||
Firmata.sendDigitalPort(portNumber, portValue);
|
||||
@ -69,9 +69,9 @@ void outputPort(byte portNumber, byte portValue)
|
||||
void checkDigitalInputs(void)
|
||||
{
|
||||
byte i, tmp;
|
||||
for(i=0; i < TOTAL_PORTS; i++) {
|
||||
if(reportPINs[i]) {
|
||||
switch(i) {
|
||||
for (i = 0; i < TOTAL_PORTS; i++) {
|
||||
if (reportPINs[i]) {
|
||||
switch (i) {
|
||||
case 0: outputPort(0, PIND &~ B00000011); break; // ignore Rx/Tx 0/1
|
||||
case 1: outputPort(1, PINB); break;
|
||||
case 2: outputPort(2, PINC); break;
|
||||
@ -99,9 +99,9 @@ void setPinModeCallback(byte pin, int mode) {
|
||||
offset = 14;
|
||||
}
|
||||
|
||||
if(pin > 1) { // ignore RxTx (pins 0 and 1)
|
||||
if (pin > 1) { // ignore RxTx (pins 0 and 1)
|
||||
pinStatus[pin] = mode;
|
||||
switch(mode) {
|
||||
switch (mode) {
|
||||
case INPUT:
|
||||
pinMode(pin, INPUT);
|
||||
portStatus[port] = portStatus[port] &~ (1 << (pin - offset));
|
||||
@ -122,13 +122,13 @@ void setPinModeCallback(byte pin, int mode) {
|
||||
|
||||
void analogWriteCallback(byte pin, int value)
|
||||
{
|
||||
setPinModeCallback(pin,PWM);
|
||||
setPinModeCallback(pin, PWM);
|
||||
analogWrite(pin, value);
|
||||
}
|
||||
|
||||
void digitalWriteCallback(byte port, int value)
|
||||
{
|
||||
switch(port) {
|
||||
switch (port) {
|
||||
case 0: // pins 2-7 (don't change Rx/Tx, pins 0 and 1)
|
||||
// 0xFF03 == B1111111100000011 0x03 == B00000011
|
||||
PORTD = (value &~ 0xFF03) | (PORTD & 0x03);
|
||||
@ -149,7 +149,7 @@ void digitalWriteCallback(byte port, int value)
|
||||
//}
|
||||
void reportAnalogCallback(byte pin, int value)
|
||||
{
|
||||
if(value == 0) {
|
||||
if (value == 0) {
|
||||
analogInputsToReport = analogInputsToReport &~ (1 << pin);
|
||||
}
|
||||
else { // everything but 0 enables reporting of that pin
|
||||
@ -161,7 +161,7 @@ void reportAnalogCallback(byte pin, int value)
|
||||
void reportDigitalCallback(byte port, int value)
|
||||
{
|
||||
reportPINs[port] = (byte)value;
|
||||
if(port == 2) // turn off analog reporting when used as digital
|
||||
if (port == 2) // turn off analog reporting when used as digital
|
||||
analogInputsToReport = 0;
|
||||
}
|
||||
|
||||
@ -184,9 +184,9 @@ void setup()
|
||||
portStatus[1] = B11000000; // ignore 14/15 pins
|
||||
portStatus[2] = B00000000;
|
||||
|
||||
// for(i=0; i<TOTAL_PINS; ++i) { // TODO make this work with analogs
|
||||
for(i=0; i<14; ++i) {
|
||||
setPinModeCallback(i,OUTPUT);
|
||||
// for(i=0; i<TOTAL_PINS; ++i) { // TODO make this work with analogs
|
||||
for (i = 0; i < 14; ++i) {
|
||||
setPinModeCallback(i, OUTPUT);
|
||||
}
|
||||
// set all outputs to 0 to make sure internal pull-up resistors are off
|
||||
PORTB = 0; // pins 8-15
|
||||
@ -194,7 +194,7 @@ void setup()
|
||||
PORTD = 0; // pins 0-7
|
||||
|
||||
// TODO rethink the init, perhaps it should report analog on default
|
||||
for(i=0; i<TOTAL_PORTS; ++i) {
|
||||
for (i = 0; i < TOTAL_PORTS; ++i) {
|
||||
reportPINs[i] = false;
|
||||
}
|
||||
// TODO: load state from EEPROM here
|
||||
@ -202,9 +202,9 @@ void setup()
|
||||
/* send digital inputs here, if enabled, to set the initial state on the
|
||||
* host computer, since once in the loop(), this firmware will only send
|
||||
* digital data on change. */
|
||||
if(reportPINs[0]) outputPort(0, PIND &~ B00000011); // ignore Rx/Tx 0/1
|
||||
if(reportPINs[1]) outputPort(1, PINB);
|
||||
if(reportPINs[2]) outputPort(2, PINC);
|
||||
if (reportPINs[0]) outputPort(0, PIND &~ B00000011); // ignore Rx/Tx 0/1
|
||||
if (reportPINs[1]) outputPort(1, PINB);
|
||||
if (reportPINs[2]) outputPort(2, PINC);
|
||||
|
||||
Firmata.begin(115200);
|
||||
}
|
||||
@ -214,15 +214,15 @@ void setup()
|
||||
*============================================================================*/
|
||||
void loop()
|
||||
{
|
||||
/* DIGITALREAD - as fast as possible, check for changes and output them to the
|
||||
/* DIGITALREAD - as fast as possible, check for changes and output them to the
|
||||
* FTDI buffer using Serial.print() */
|
||||
checkDigitalInputs();
|
||||
currentMillis = millis();
|
||||
if(currentMillis - previousMillis > 20) {
|
||||
if (currentMillis - previousMillis > 20) {
|
||||
previousMillis += 20; // run this every 20ms
|
||||
/* SERIALREAD - Serial.read() uses a 128 byte circular buffer, so handle
|
||||
* all serialReads at once, i.e. empty the buffer */
|
||||
while(Firmata.available())
|
||||
while (Firmata.available())
|
||||
Firmata.processInput();
|
||||
/* SEND FTDI WRITE BUFFER - make sure that the FTDI buffer doesn't go over
|
||||
* 60 bytes. use a timer to sending an event character every 4 ms to
|
||||
@ -230,8 +230,8 @@ void loop()
|
||||
|
||||
/* ANALOGREAD - right after the event character, do all of the
|
||||
* analogReads(). These only need to be done every 4ms. */
|
||||
for(analogPin=0;analogPin<TOTAL_ANALOG_PINS;analogPin++) {
|
||||
if( analogInputsToReport & (1 << analogPin) ) {
|
||||
for (analogPin = 0; analogPin < TOTAL_ANALOG_PINS; analogPin++) {
|
||||
if ( analogInputsToReport & (1 << analogPin) ) {
|
||||
Firmata.sendAnalog(analogPin, analogRead(analogPin));
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ void setup()
|
||||
Firmata.setFirmwareVersion(0, 2);
|
||||
Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
|
||||
|
||||
for (pin=0; pin < TOTAL_PINS; pin++) {
|
||||
for (pin = 0; pin < TOTAL_PINS; pin++) {
|
||||
if (IS_PIN_SERVO(pin)) {
|
||||
servos[PIN_TO_SERVO(pin)].attach(PIN_TO_DIGITAL(pin));
|
||||
}
|
||||
@ -47,7 +47,7 @@ void setup()
|
||||
|
||||
void loop()
|
||||
{
|
||||
while(Firmata.available())
|
||||
while (Firmata.available())
|
||||
Firmata.processInput();
|
||||
}
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user