1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-08-07 00:04:36 +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,26 +1,26 @@
/*
Esplora TFT Bitmap Logos
This example for the Arduino TFT screen is for use
with an Arduino Esplora.
This example reads an image file from a micro-SD card
and draws it on the screen, at random locations.
There is a .bmp file included with this sketch.
There is a .bmp file included with this sketch.
- open the sketch folder (Ctrl-K or Cmd-K)
- copy the "arduino.bmp" file to a micro-SD
- put the SD into the SD slot of the Arduino LCD module.
This example code is in the public domain.
Created 19 April 2013 by Enrico Gueli
http://arduino.cc/en/Tutorial/EsploraTFTBitmapLogo
*/
// include the necessary libraries
#include <Esplora.h>
#include <SPI.h>
@@ -46,13 +46,13 @@ void setup() {
EsploraTFT.println("Open serial monitor");
EsploraTFT.println("to run the sketch");
// initialize the serial port: it will be used to
// initialize the serial port: it will be used to
// print some diagnostic info
Serial.begin(9600);
while (!Serial) {
// wait for serial monitor to be open
}
// try to access the SD card. If that fails (e.g.
// no card present), the Esplora's LED will turn red.
Serial.print("Initializing SD card...");
@@ -62,10 +62,10 @@ void setup() {
return;
}
Serial.println("OK!");
// clear the GLCD screen before starting
EsploraTFT.background(255, 255, 255);
// now that the SD card can be access, try to load the
// image file. The Esplora LED will turn green or red if
// the loading went OK or not.
@@ -84,18 +84,18 @@ void loop() {
if (logo.isValid() == false) {
return;
}
Serial.println("drawing image");
// get a random location where to draw the image.
// To avoid the image to be draw outside the screen,
// take into account the image size.
int x = random(EsploraTFT.width() - logo.width());
int y = random(EsploraTFT.height() - logo.height());
// draw the image to the screen
EsploraTFT.image(logo, x, y);
// wait a little bit before drawing again
delay(1500);
}

View File

@@ -1,17 +1,17 @@
/*
Esplora TFT Color Picker
This example for the Esplora with an Arduino TFT reads
This example for the Esplora with an Arduino TFT reads
the input of the joystick and slider, using the values
to change the screen's color.
This example code is in the public domain.
Created 15 April 2013 by Scott Fitzgerald
http://arduino.cc/en/Tutorial/TFTColorPicker
*/
#include <Esplora.h>
@@ -35,10 +35,10 @@ void loop() {
int xValue = map(Esplora.readJoystickX(), -512, 512, 0, 255); // read the joystick's X position
int yValue = map(Esplora.readJoystickY(), -512, 512, 0, 255); // read the joystick's Y position
int slider = map(Esplora.readSlider(), 0, 1023, 0, 255); // read the slider's position
// change the background color based on the mapped values
EsploraTFT.background(xValue, yValue, slider);
// print the mapped values to the Serial monitor
Serial.print("background(");
Serial.print(xValue);
@@ -47,7 +47,7 @@ void loop() {
Serial.print(" , ");
Serial.print(slider);
Serial.println(")");
delay(33);
}

View File

@@ -1,34 +1,34 @@
/*
Esplora TFT EtchASketch
This example for the Arduino TFT and Esplora draws
a white line on the screen, based on the position
of the joystick. To clear the screen, shake the
This example for the Arduino TFT and Esplora draws
a white line on the screen, based on the position
of the joystick. To clear the screen, shake the
Esplora, using the values from the accelerometer.
This example code is in the public domain.
Created 15 April 2013 by Scott Fitzgerald
http://arduino.cc/en/Tutorial/EsploraTFTEtchASketch
*/
#include <Esplora.h>
#include <TFT.h> // Arduino LCD library
#include <SPI.h>
// initial position of the cursor
int xPos = EsploraTFT.width()/2;
int yPos = EsploraTFT.height()/2;
int xPos = EsploraTFT.width() / 2;
int yPos = EsploraTFT.height() / 2;
void setup() {
// initialize the display
EsploraTFT.begin();
// clear the background
EsploraTFT.background(0,0,0);
EsploraTFT.background(0, 0, 0);
}
void loop()
@@ -39,45 +39,45 @@ void loop()
// update the position of the line
// depending on the position of the joystick
if (xAxis<10 && xAxis>-10){
xPos=xPos;
if (xAxis < 10 && xAxis > -10) {
xPos = xPos;
}
else{
else {
xPos = xPos + (map(xAxis, -512, 512, 2, -2));
}
if (yAxis<10 && yAxis>-10){
yAxis=yAxis;
if (yAxis < 10 && yAxis > -10) {
yAxis = yAxis;
}
else{
else {
yPos = yPos + (map(yAxis, -512, 512, -2, 2));
}
// don't let the point go past the screen edges
if(xPos > 159){
// don't let the point go past the screen edges
if (xPos > 159) {
(xPos = 159);
}
if(xPos < 0){
if (xPos < 0) {
(xPos = 0);
}
if(yPos > 127){
if (yPos > 127) {
(yPos = 127);
}
if(yPos < 0){
if (yPos < 0) {
(yPos = 0);
}
// draw the point
EsploraTFT.stroke(255,255,255);
EsploraTFT.point(xPos,yPos);
EsploraTFT.stroke(255, 255, 255);
EsploraTFT.point(xPos, yPos);
// check the accelerometer values and clear
// the screen if it is being shaken
if(abs(Esplora.readAccelerometer(X_AXIS))>200 || abs(Esplora.readAccelerometer(Y_AXIS))>200){
EsploraTFT.background(0,0,0);
// the screen if it is being shaken
if (abs(Esplora.readAccelerometer(X_AXIS)) > 200 || abs(Esplora.readAccelerometer(Y_AXIS)) > 200) {
EsploraTFT.background(0, 0, 0);
}
delay(33);
delay(33);
}

View File

@@ -1,17 +1,17 @@
/*
Esplora TFT Graph
This example for the Esplora with an Arduino TFT reads
This example for the Esplora with an Arduino TFT reads
the value of the light sensor, and graphs the values on
the screen.
This example code is in the public domain.
Created 15 April 2013 by Scott Fitzgerald
http://arduino.cc/en/Tutorial/EsploraTFTGraph
*/
#include <Esplora.h>
@@ -21,32 +21,32 @@
// position of the line on screen
int xPos = 0;
void setup(){
void setup() {
// initialize the screen
EsploraTFT.begin();
// clear the screen with a nice color
EsploraTFT.background(250,16,200);
EsploraTFT.background(250, 16, 200);
}
void loop(){
void loop() {
// read the sensor value
int sensor = Esplora.readLightSensor();
// map the sensor value to the height of the screen
int graphHeight = map(sensor,0,1023,0,EsploraTFT.height());
int graphHeight = map(sensor, 0, 1023, 0, EsploraTFT.height());
// draw the line in a pretty color
EsploraTFT.stroke(250,180,10);
EsploraTFT.stroke(250, 180, 10);
EsploraTFT.line(xPos, EsploraTFT.height() - graphHeight, xPos, EsploraTFT.height());
// if the graph reaches the edge of the screen
// erase it and start over from the other side
if (xPos >= 160) {
xPos = 0;
EsploraTFT.background(250,16,200);
}
EsploraTFT.background(250, 16, 200);
}
else {
// increment the horizontal position:
xPos++;

View File

@@ -1,17 +1,17 @@
/*
Esplora TFT Horizon
This example for the Arduino TFT and Esplora draws
This example for the Arduino TFT and Esplora draws
a line on the screen that stays level with the ground
as you tile the Esplora side to side
This example code is in the public domain.
Created 15 April 2013 by Scott Fitzgerald
http://arduino.cc/en/Tutorial/EsploraTFTHorizon
*/
#include <Esplora.h>
@@ -19,8 +19,8 @@
#include <SPI.h>
// horizontal start and end positions
int yStart = EsploraTFT.height()/2;
int yEnd = EsploraTFT.height()/2;
int yStart = EsploraTFT.height() / 2;
int yEnd = EsploraTFT.height() / 2;
// previous start and end positions
int oldEndY;
@@ -30,7 +30,7 @@ void setup() {
// initialize the display
EsploraTFT.begin();
// make the background black
EsploraTFT.background(0,0,0);
EsploraTFT.background(0, 0, 0);
}
void loop()
@@ -41,23 +41,23 @@ void loop()
// the values are 100 when tilted to the left
// and -100 when tilted to the right
// map these values to the start and end points
yStart = map(tilt,-100,100,EsploraTFT.height(),0);
yEnd = map(tilt,-100,100,0,EsploraTFT.height());
yStart = map(tilt, -100, 100, EsploraTFT.height(), 0);
yEnd = map(tilt, -100, 100, 0, EsploraTFT.height());
// if the previous values are different than the current values
// erase the previous line
if (oldStartY != yStart || oldEndY != yEnd) {
EsploraTFT.stroke(0,0,0);
EsploraTFT.stroke(0, 0, 0);
EsploraTFT.line(0, oldStartY, EsploraTFT.width(), oldEndY);
}
// draw the line in magenta
EsploraTFT.stroke(255,0,255);
EsploraTFT.line(0,yStart,EsploraTFT.width(),yEnd);
EsploraTFT.stroke(255, 0, 255);
EsploraTFT.line(0, yStart, EsploraTFT.width(), yEnd);
// save the current start and end points
// to compare int he next loop
oldStartY= yStart;
oldStartY = yStart;
oldEndY = yEnd;
delay(10);
delay(10);
}

View File

@@ -1,20 +1,20 @@
/*
Esplora TFT Pong
This example for the Esplora with an Arduino TFT screen reads
This example for the Esplora with an Arduino TFT screen reads
the value of the joystick to move a rectangular platform
on the x and y axes. The platform can intersect with a ball
causing it to bounce. The Esplora's slider adjusts the speed
of the ball.
This example code is in the public domain.
Created by Tom Igoe December 2012
Modified 15 April 2013 by Scott Fitzgerald
http://arduino.cc/en/Tutorial/EsploraTFTPong
*/
#include <Esplora.h>
@@ -37,7 +37,7 @@ void setup() {
// initialize the display
EsploraTFT.begin();
// set the background the black
EsploraTFT.background(0,0,0);
EsploraTFT.background(0, 0, 0);
}
void loop() {
@@ -45,16 +45,16 @@ void loop() {
int myWidth = EsploraTFT.width();
int myHeight = EsploraTFT.height();
// map the paddle's location to the joystick's position
paddleX = map(Esplora.readJoystickX(), 512, -512, 0, myWidth) - 20/2;
paddleY = map(Esplora.readJoystickY(), -512, 512, 0, myHeight) - 5/2;
// map the paddle's location to the joystick's position
paddleX = map(Esplora.readJoystickX(), 512, -512, 0, myWidth) - 20 / 2;
paddleY = map(Esplora.readJoystickY(), -512, 512, 0, myHeight) - 5 / 2;
Serial.print(paddleX);
Serial.print(" ");
Serial.println(paddleY);
// set the fill color to black and erase the previous
// set the fill color to black and erase the previous
// position of the paddle if different from present
EsploraTFT.fill(0,0,0);
EsploraTFT.fill(0, 0, 0);
if (oldPaddleX != paddleX || oldPaddleY != paddleY) {
EsploraTFT.rect(oldPaddleX, oldPaddleY, 20, 5);
@@ -62,13 +62,13 @@ void loop() {
// draw the paddle on screen, save the current position
// as the previous.
EsploraTFT.fill(255,255,255);
EsploraTFT.fill(255, 255, 255);
EsploraTFT.rect(paddleX, paddleY, 20, 5);
oldPaddleX = paddleX;
oldPaddleY = paddleY;
// read the slider to determinde the speed of the ball
int ballSpeed = map(Esplora.readSlider(), 0, 1023, 0, 80)+1;
int ballSpeed = map(Esplora.readSlider(), 0, 1023, 0, 80) + 1;
if (millis() % ballSpeed < 2) {
moveBall();
}
@@ -84,7 +84,7 @@ void moveBall() {
if (ballY > EsploraTFT.height() || ballY < 0) {
ballDirectionY = -ballDirectionY;
}
}
// check if the ball and the paddle occupy the same space on screen
if (inPaddle(ballX, ballY, paddleX, paddleY, 20, 5)) {
@@ -96,14 +96,14 @@ void moveBall() {
ballY += ballDirectionY;
// erase the ball's previous position
EsploraTFT.fill(0,0,0);
EsploraTFT.fill(0, 0, 0);
if (oldBallX != ballX || oldBallY != ballY) {
EsploraTFT.rect(oldBallX, oldBallY, 5, 5);
}
// draw the ball's current position
EsploraTFT.fill(255,255,255);
EsploraTFT.fill(255, 255, 255);
EsploraTFT.rect(ballX, ballY, 5, 5);
@@ -117,10 +117,10 @@ void moveBall() {
boolean inPaddle(int x, int y, int rectX, int rectY, int rectWidth, int rectHeight) {
boolean result = false;
if ((x >= rectX && x <= (rectX + rectWidth)) &&
(y >= rectY && y <= (rectY + rectHeight))) {
result = true;
if ((x >= rectX && x <= (rectX + rectWidth)) &&
(y >= rectY && y <= (rectY + rectHeight))) {
result = true;
}
return result;
return result;
}

View File

@@ -1,24 +1,24 @@
/*
Esplora TFT Temperature Display
This example for the Arduino TFT screen is for use
with an Arduino Esplora.
This example reads the temperature of the Esplora's
on board thermisistor and displays it on an attached
LCD screen, updating every second.
This example code is in the public domain.
Created 15 April 2013 by Scott Fitzgerald
http://arduino.cc/en/Tutorial/EsploraTFTTemp
*/
// include the necessary libraries
#include <Esplora.h>
#include <Esplora.h>
#include <TFT.h> // Arduino LCD library
#include <SPI.h>
@@ -30,15 +30,15 @@ void setup() {
EsploraTFT.begin();
// clear the screen with a black background
EsploraTFT.background(0,0,0);
EsploraTFT.background(0, 0, 0);
// set the text color to magenta
EsploraTFT.stroke(200,20,180);
EsploraTFT.stroke(200, 20, 180);
// set the text to size 2
EsploraTFT.setTextSize(2);
// start the text at the top left of the screen
// this text is going to remain static
EsploraTFT.text("Degrees in C :\n ",0,0);
EsploraTFT.text("Degrees in C :\n ", 0, 0);
// set the text in the loop to size 5
EsploraTFT.setTextSize(5);
@@ -53,12 +53,12 @@ void loop() {
temperature.toCharArray(tempPrintout, 3);
// set the text color to white
EsploraTFT.stroke(255,255,255);
EsploraTFT.stroke(255, 255, 255);
// print the temperature one line below the static text
EsploraTFT.text(tempPrintout, 0, 30);
delay(1000);
// erase the text for the next loop
EsploraTFT.stroke(0,0,0);
EsploraTFT.stroke(0, 0, 0);
EsploraTFT.text(tempPrintout, 0, 30);
}