1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-30 16:24:09 +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

@ -1,14 +1,14 @@
/*
Esplora Accelerometer
Esplora Accelerometer
This sketch shows you how to read the values from the accelerometer.
To see it in action, open the serial monitor and tilt the board. You'll see
the accelerometer values for each axis change when you tilt the board
the accelerometer values for each axis change when you tilt the board
on that axis.
Created on 22 Dec 2012
by Tom Igoe
This example is in the public domain.
*/
@ -17,7 +17,7 @@
void setup()
{
Serial.begin(9600); // initialize serial communications with your computer
}
}
void loop()
{
@ -25,9 +25,9 @@ void loop()
int yAxis = Esplora.readAccelerometer(Y_AXIS); // read the Y axis
int zAxis = Esplora.readAccelerometer(Z_AXIS); // read the Z axis
Serial.print("x: "); // print the label for X
Serial.print("x: "); // print the label for X
Serial.print(xAxis); // print the value for the X axis
Serial.print("\ty: "); // print a tab character, then the label for Y
Serial.print("\ty: "); // print a tab character, then the label for Y
Serial.print(yAxis); // print the value for the Y axis
Serial.print("\tz: "); // print a tab character, then the label for Z
Serial.println(zAxis); // print the value for the Z axis

View File

@ -1,16 +1,16 @@
/*
Esplora Blink
This sketch blinks the Esplora's RGB LED. It goes through
all three primary colors (red, green, blue), then it
all three primary colors (red, green, blue), then it
combines them for secondary colors(yellow, cyan, magenta), then
it turns on all the colors for white.
it turns on all the colors for white.
For best results cover the LED with a piece of white paper to see the colors.
Created on 22 Dec 2012
by Tom Igoe
This example is in the public domain.
*/
@ -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

@ -1,9 +1,9 @@
/*
Esplora Joystick Mouse
This sketch shows you how to read the joystick and use it to control the movement
of the cursor on your computer. You're making your Esplora into a mouse!
WARNING: this sketch will take over your mouse movement. If you lose control
of your mouse do the following:
1) unplug the Esplora.
@ -11,13 +11,13 @@
3) hold the reset button down while plugging your Esplora back in
4) while holding reset, click "Upload"
5) when you see the message "Done compiling", release the reset button.
This will stop your Esplora from controlling your mouse while you upload a sketch
that doesn't take control of the mouse.
Created on 22 Dec 2012
by Tom Igoe
This example is in the public domain.
*/
@ -27,7 +27,7 @@ void setup()
{
Serial.begin(9600); // initialize serial communication with your computer
Mouse.begin(); // take control of the mouse
}
}
void loop()
{
@ -41,10 +41,10 @@ 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

@ -3,7 +3,7 @@
Makes the RGB LED bright and glow as the joystick or the
slider are moved.
Created on 22 november 2012
By Enrico Gueli <enrico.gueli@gmail.com>
Modified 22 Dec 2012
@ -21,12 +21,12 @@ void loop() {
int xAxis = Esplora.readJoystickX();
int yAxis = Esplora.readJoystickY();
int slider = Esplora.readSlider();
// 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);
Serial.print(' ');
@ -34,9 +34,9 @@ void loop() {
Serial.print(' ');
Serial.println(blue);
// write the light levels to the LED.
// write the light levels to the LED.
Esplora.writeRGB(red, green, blue);
// add a delay to keep the LED from flickering:
// add a delay to keep the LED from flickering:
delay(10);
}

View File

@ -22,7 +22,7 @@ void setup() {
}
int lowLight = 400; // the light sensor reading when it's covered
int highLight = 1023; // the maximum light sensor reading
int highLight = 1023; // the maximum light sensor reading
int minGreen = 0; // minimum brightness of the green LED
int maxGreen = 100; // maximum brightness of the green LED
@ -31,13 +31,13 @@ void loop() {
int mic = Esplora.readMicrophone();
int light = Esplora.readLightSensor();
int slider = Esplora.readSlider();
// 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);
@ -46,10 +46,10 @@ void loop() {
Serial.print(' ');
Serial.println(blue);
// write the light levels to the LED.
// write the light levels to the LED.
// note that the green value is always 0:
Esplora.writeRGB(red, green, blue);
// add a delay to keep the LED from flickering:
delay(10);
delay(10);
}

View File

@ -1,17 +1,17 @@
/*
Esplora Led calibration
This sketch shows you how to read and calibrate the light sensor.
Because light levels vary from one location to another, you need to calibrate the
Because light levels vary from one location to another, you need to calibrate the
sensor for each location. To do this, you read the sensor for a few seconds,
and save the highest and lowest readings as maximum and minimum.
and save the highest and lowest readings as maximum and minimum.
Then, when you're using the sensor's reading (for example, to set the brightness
of the LED), you map the sensor's reading to a range between the minimum
and the maximum.
Created on 22 Dec 2012
by Tom Igoe
This example is in the public domain.
*/
@ -43,9 +43,9 @@ void loop() {
int brightness = map(light, lightMin, lightMax, 0, 255);
// limit the brightness to a range from 0 to 255:
brightness = constrain(brightness, 0, 255);
// write the brightness to the blue LED.
// write the brightness to the blue LED.
Esplora.writeBlue(brightness);
// if the calibration's been done, show the sensor and brightness
// levels in the serial monitor:
if (calibrated == true) {
@ -56,7 +56,7 @@ void loop() {
Serial.println(brightness);
}
// add a delay to keep the LED from flickering:
delay(10);
delay(10);
}
void calibrate() {
@ -64,8 +64,8 @@ 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) {
// read the sensor value:
while (Esplora.readButton(1) == LOW) {
// read the sensor value:
int light = Esplora.readLightSensor();
// record the maximum sensor value:

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() {
@ -39,8 +39,8 @@ void loop() {
// then play a note:
if (Esplora.readButton(SWITCH_DOWN) == LOW) {
int slider = Esplora.readSlider();
// use map() to map the slider's range to the
// use map() to map the slider's range to the
// range of notes you have:
byte thisNote = map(slider, 0, 1023, 0, 13);
// play the note corresponding to the slider's position:

View File

@ -1,15 +1,15 @@
/*
Esplora Sound Sensor
This sketch shows you how to read the microphone sensor. The microphone
will range from 0 (total silence) to 1023 (really loud).
will range from 0 (total silence) to 1023 (really loud).
When you're using the sensor's reading (for example, to set the brightness
of the LED), you map the sensor's reading to a range between the minimum
and the maximum.
Created on 22 Dec 2012
by Tom Igoe
This example is in the public domain.
*/
@ -26,16 +26,16 @@ void loop() {
// map the sound level to a brightness level for the LED:
int brightness = map(loudness, 0, 1023, 0, 255);
// write the brightness to the green LED:
// write the brightness to the green LED:
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);
delay(10);
}

View File

@ -1,12 +1,12 @@
/*
Esplora Temperature Sensor
This sketch shows you how to read the Esplora's temperature sensor
You can read the temperature sensor in Farhenheit or Celsius.
Created on 22 Dec 2012
by Tom Igoe
This example is in the public domain.
*/
#include <Esplora.h>
@ -14,7 +14,7 @@
void setup()
{
Serial.begin(9600); // initialize serial communications with your computer
}
}
void loop()
{

View File

@ -7,7 +7,7 @@
By moving the joystick in a direction or by pressing a switch,
the PC will "see" that a key is pressed. If the PC is running
a game that has keyboard input, the Esplora can control it.
The default configuration is suitable for SuperTuxKart, an
open-source racing game. It can be downloaded from
http://supertuxkart.sourceforge.net/ .
@ -20,11 +20,11 @@
#include <Esplora.h>
/*
You're going to handle eight different buttons. You'll use arrays,
which are ordered lists of variables with a fixed size. Each array
You're going to handle eight different buttons. You'll use arrays,
which are ordered lists of variables with a fixed size. Each array
has an index (counting from 0) to keep track of the position
you're reading in the array, and each position can contain a number.
This code uses three different arrays: one for the buttons you'll read;
a second to hold the current states of those buttons; and a third to hold
the keystrokes associated with each button.
@ -89,14 +89,14 @@ void setup() {
Here we continuously check if something happened with the
buttons.
*/
void loop() {
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!
/*
/*
The Keyboard library allows you to "press" and "release" the
keys as two distinct actions. These actions can be
linked to the buttons we're handling.
@ -112,7 +112,7 @@ void loop() {
// Store the new button state, so you can sense a difference later:
buttonStates[thisButton] = newState;
}
/*
Wait a little bit (50ms) between a check and another.
When a mechanical switch is pressed or released, the

View File

@ -1,21 +1,21 @@
/*
Esplora Pong
This sketch connects serially to a Processing sketch to control a Pong game.
It sends the position of the slider and the states of three pushbuttons to the
Processing sketch serially, separated by commas. The Processing sketch uses that
It sends the position of the slider and the states of three pushbuttons to the
Processing sketch serially, separated by commas. The Processing sketch uses that
data to control the graphics in the sketch.
The slider sets a paddle's height
Switch 1 is resets the game
Switch 2 resets the ball to the center
Switch 3 reverses the players
You can play this game with one or two Esploras.
Created on 22 Dec 2012
by Tom Igoe
This example is in the public domain.
*/

View File

@ -1,28 +1,28 @@
/*
Esplora Remote
This sketch allows to test all the Esplora's peripherals.
It is also used with the ProcessingStart sketch (for Processing).
When uploaded, you can open the Serial monitor and write one of
the following commands (without quotes) to get an answer:
"D": prints the current value of all sensors, separated by a comma.
See the dumpInputs() function below to get the meaning of
each value.
"Rxxx"
"Gxxx"
"Bxxx": set the color of the RGB led. For example, write "R255"
to turn on the red to full brightness, "G128" to turn
the green to half brightness, or "G0" to turn off
the green channel.
"Txxxx": play a tone with the buzzer. The number is the
frequency, e.g. "T440" plays the central A note.
Write "T0" to turn off the buzzer.
Created on 22 november 2012
By Enrico Gueli <enrico.gueli@gmail.com>
Modified 23 Dec 2012
@ -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,53 +48,53 @@ 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;
}
}
void dumpInputs() {
Serial.print(Esplora.readButton(SWITCH_1));
void dumpInputs() {
Serial.print(Esplora.readButton(SWITCH_1));
Serial.print(',');
Serial.print(Esplora.readButton(SWITCH_2));
Serial.print(Esplora.readButton(SWITCH_2));
Serial.print(',');
Serial.print(Esplora.readButton(SWITCH_3));
Serial.print(Esplora.readButton(SWITCH_3));
Serial.print(',');
Serial.print(Esplora.readButton(SWITCH_4));
Serial.print(Esplora.readButton(SWITCH_4));
Serial.print(',');
Serial.print(Esplora.readSlider());
Serial.print(Esplora.readSlider());
Serial.print(',');
Serial.print(Esplora.readLightSensor());
Serial.print(Esplora.readLightSensor());
Serial.print(',');
Serial.print(Esplora.readTemperature(DEGREES_C));
Serial.print(Esplora.readTemperature(DEGREES_C));
Serial.print(',');
Serial.print(Esplora.readMicrophone());
Serial.print(Esplora.readMicrophone());
Serial.print(',');
Serial.print(Esplora.readJoystickSwitch());
Serial.print(Esplora.readJoystickSwitch());
Serial.print(',');
Serial.print(Esplora.readJoystickX());
Serial.print(Esplora.readJoystickX());
Serial.print(',');
Serial.print(Esplora.readJoystickY());
Serial.print(Esplora.readJoystickY());
Serial.print(',');
Serial.print(Esplora.readAccelerometer(X_AXIS));
Serial.print(Esplora.readAccelerometer(X_AXIS));
Serial.print(',');
Serial.print(Esplora.readAccelerometer(Y_AXIS));
Serial.print(Esplora.readAccelerometer(Y_AXIS));
Serial.print(',');
Serial.print(Esplora.readAccelerometer(Z_AXIS));
Serial.print(Esplora.readAccelerometer(Z_AXIS));
Serial.println();
}

View File

@ -3,18 +3,18 @@
Acts like a keyboard that prints sensor
data in a table-like text, row by row.
At startup, it does nothing. It waits for you to open a
spreadsheet (e.g. Google Drive spreadsheet) so it can write
data. By pressing Switch 1, it starts printing the table
headers and the first row of data. It waits a bit, then it
will print another row, and so on.
The amount of time between each row is determined by the slider.
If put to full left, the sketch will wait 10 seconds; at
full right position, it will wait 5 minutes. An intermediate
position will make the sketch wait for some time in-between.
Clicking the Switch 1 at any time will stop the logging.
The color LED shows what the sketch is doing:
@ -87,7 +87,7 @@ void loop() {
* check for button presses often enough to not miss any event.
*/
activeDelay(50);
/*
* the justActivated variable may be set to true in the
* checkSwitchPress() function. Here we check its status to
@ -99,7 +99,7 @@ void loop() {
// do next sampling ASAP
nextSampleAt = startedAt = millis();
}
if (active == true) {
if (nextSampleAt < millis()) {
// it's time to sample!
@ -108,24 +108,24 @@ void loop() {
// 10 and 290 seconds.
int sampleInterval = map(slider, 0, 1023, 10, 290);
nextSampleAt = millis() + sampleInterval * 1000;
logAndPrint();
}
// let the RGB led blink green once per second, for 200ms.
unsigned int ms = millis() % 1000;
if (ms < 200)
Esplora.writeGreen(50);
else
Esplora.writeGreen(0);
Esplora.writeBlue(0);
}
}
else
// while not active, keep a reassuring blue color coming
// from the Esplora...
Esplora.writeBlue(20);
}
/*
@ -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,13 +149,13 @@ 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);
Esplora.writeRed(100);
Keyboard.print(timeSecs);
Keyboard.write(KEY_TAB);
activeDelay(300);
@ -169,7 +169,7 @@ void logAndPrint() {
Keyboard.println();
activeDelay(300);
Keyboard.write(KEY_HOME);
Esplora.writeRed(0);
}
@ -204,9 +204,9 @@ void checkSwitchPress() {
if (startBtn == HIGH) { // button released
active = !active;
if (active)
justActivated = true;
justActivated = true;
}
lastStartBtn = startBtn;
}
}