1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-16 11:21:18 +03:00

Run new astyle formatter against all the examples

This commit is contained in:
Federico Fissore
2013-10-21 09:58:40 +02:00
parent 3c6ee46828
commit b4c68b3dff
259 changed files with 5160 additions and 5217 deletions

View File

@ -1,24 +1,24 @@
/*
Arduino TFT Bitmap Logo example
This example reads an image file from a micro-SD card
and draws it on the screen, at random locations.
In this sketch, the Arduino logo is read from a micro-SD card.
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 TFT module.
This example code is in the public domain.
Created 19 April 2013 by Enrico Gueli
http://arduino.cc/en/Tutorial/TFTBitmapLogo
*/
// include the necessary libraries
#include <SPI.h>
#include <SD.h>
@ -28,13 +28,13 @@
#define sd_cs 4
#define lcd_cs 10
#define dc 9
#define rst 8
#define rst 8
// pin definition for the Leonardo
//#define sd_cs 8
//#define lcd_cs 7
//#define dc 0
//#define rst 1
//#define rst 1
TFT TFTscreen = TFT(lcd_cs, dc, rst);
@ -55,8 +55,8 @@ void setup() {
TFTscreen.println("Open serial monitor");
TFTscreen.println("to run the sketch");
// initialize the serial port: it will be used to
// print some diagnostic info
// initialize the serial port: it will be used to
// print some diagnostic info
Serial.begin(9600);
while (!Serial) {
// wait for serial line to be ready
@ -64,7 +64,7 @@ void setup() {
// clear the GLCD screen before starting
TFTscreen.background(255, 255, 255);
// try to access the SD card. If that fails (e.g.
// no card present), the setup process will stop.
Serial.print("Initializing SD card...");
@ -73,7 +73,7 @@ void setup() {
return;
}
Serial.println("OK!");
// initialize and clear the GLCD screen
TFTscreen.begin();
TFTscreen.background(255, 255, 255);
@ -91,7 +91,7 @@ void loop() {
if (logo.isValid() == false) {
return;
}
Serial.println("drawing image");
// get a random location where to draw the image.

View File

@ -1,28 +1,28 @@
/*
TFT Color Picker
This example for the Arduino screen reads the input of
This example for the Arduino screen reads the input of
potentiometers or analog sensors attached to A0, A1,
and A2 and uses 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
*/
// pin definition for the Uno
#define cs 10
#define dc 9
#define rst 8
#define rst 8
// pin definition for the Leonardo
// #define cs 7
// #define dc 0
// #define rst 1
// #define rst 1
#include <TFT.h> // Arduino LCD library
#include <SPI.h>
@ -44,13 +44,13 @@ void setup() {
void loop() {
// read the values from your sensors and scale them to 0-255
int redVal = map(analogRead(A0), 0, 1023, 0, 255);
int greenVal = map(analogRead(A1), 0, 1023, 0, 255);
int redVal = map(analogRead(A0), 0, 1023, 0, 255);
int greenVal = map(analogRead(A1), 0, 1023, 0, 255);
int blueVal = map(analogRead(A2), 0, 1023, 0, 255);
// draw the background based on the mapped values
TFTscreen.background(redVal, greenVal, blueVal);
// send the values to the serial monitor
Serial.print("background(");
Serial.print(redVal);
@ -59,7 +59,7 @@ void loop() {
Serial.print(" , ");
Serial.print(blueVal);
Serial.println(")");
// wait for a moment
delay(33);

View File

@ -1,18 +1,18 @@
/*
Arduino TFT text example
This example demonstrates how to draw text on the
TFT with an Arduino. The Arduino reads the value
of an analog sensor attached to pin A0, and writes
This example demonstrates how to draw text on the
TFT with an Arduino. The Arduino reads the value
of an analog sensor attached to pin A0, and writes
the value to the LCD screen, updating every
quarter second.
This example code is in the public domain
Created 15 April 2013 by Scott Fitzgerald
http://arduino.cc/en/Tutorial/TFTDisplayText
*/
#include <TFT.h> // Arduino LCD library
@ -21,12 +21,12 @@
// pin definition for the Uno
#define cs 10
#define dc 9
#define rst 8
#define rst 8
// pin definition for the Leonardo
// #define cs 7
// #define dc 0
// #define rst 1
// #define rst 1
// create an instance of the library
TFT TFTscreen = TFT(cs, dc, rst);
@ -35,20 +35,20 @@ TFT TFTscreen = TFT(cs, dc, rst);
char sensorPrintout[4];
void setup() {
// Put this line at the beginning of every sketch that uses the GLCD:
TFTscreen.begin();
// clear the screen with a black background
TFTscreen.background(0, 0, 0);
// write the static text to the screen
// set the font color to white
TFTscreen.stroke(255,255,255);
TFTscreen.stroke(255, 255, 255);
// set the font size
TFTscreen.setTextSize(2);
// write the text to the top left corner of the screen
TFTscreen.text("Sensor Value :\n ",0,0);
TFTscreen.text("Sensor Value :\n ", 0, 0);
// ste the font size very large for the loop
TFTscreen.setTextSize(5);
}
@ -57,18 +57,18 @@ void loop() {
// Read the value of the sensor on A0
String sensorVal = String(analogRead(A0));
// convert the reading to a char array
sensorVal.toCharArray(sensorPrintout, 4);
// set the font color
TFTscreen.stroke(255,255,255);
TFTscreen.stroke(255, 255, 255);
// print the sensor value
TFTscreen.text(sensorPrintout, 0, 20);
// wait for a moment
delay(250);
// erase the text you just wrote
TFTscreen.stroke(0,0,0);
TFTscreen.stroke(0, 0, 0);
TFTscreen.text(sensorPrintout, 0, 20);
}

View File

@ -1,37 +1,37 @@
/*
TFT EtchASketch
This example for the Arduino screen draws a white point
on the GLCD based on the values of 2 potentiometers.
on the GLCD based on the values of 2 potentiometers.
To clear the screen, press a button attached to pin 2.
This example code is in the public domain.
Created 15 April 2013 by Scott Fitzgerald
http://arduino.cc/en/Tutorial/TFTEtchASketch
*/
#include <TFT.h> // Arduino LCD library
#include <SPI.h>
// pin definition for the Uno
#define cs 10
#define dc 9
#define rst 8
#define rst 8
// pin definition for the Leonardo
// #define cs 7
// #define dc 0
// #define rst 1
// #define rst 1
TFT TFTscreen = TFT(cs, dc, rst);
// initial position of the cursor
int xPos = TFTscreen.width()/2;
int yPos = TFTscreen.height()/2;
int xPos = TFTscreen.width() / 2;
int yPos = TFTscreen.height() / 2;
// pin the erase switch is connected to
int erasePin = 2;
@ -42,43 +42,43 @@ void setup() {
// initialize the screen
TFTscreen.begin();
// make the background black
TFTscreen.background(0,0,0);
TFTscreen.background(0, 0, 0);
}
void loop()
{
// read the potentiometers on A0 and A1
// read the potentiometers on A0 and A1
int xValue = analogRead(A0);
int yValue = analogRead(A1);
// map the values and update the position
xPos = xPos + (map(xValue, 0, 1023, 2, -2));
yPos = yPos + (map(yValue, 0, 1023, -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
TFTscreen.stroke(255,255,255);
TFTscreen.point(xPos,yPos);
TFTscreen.stroke(255, 255, 255);
TFTscreen.point(xPos, yPos);
// read the value of the pin, and erase the screen if pressed
if(digitalRead(erasePin) == HIGH){
TFTscreen.background(0,0,0);
if (digitalRead(erasePin) == HIGH) {
TFTscreen.background(0, 0, 0);
}
delay(33);
delay(33);
}

View File

@ -1,38 +1,38 @@
/*
TFT Graph
This example for an Arduino screen reads
the value of an analog sensor on A0, and
This example for an Arduino screen reads
the value of an analog sensor on A0, 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/TFTGraph
*/
#include <TFT.h> // Arduino LCD library
#include <SPI.h>
// pin definition for the Uno
// pin definition for the Uno
#define cs 10
#define dc 9
#define rst 8
#define rst 8
// pin definition for the Leonardo
// #define cs 7
// #define dc 0
// #define rst 1
// #define rst 1
TFT TFTscreen = TFT(cs, dc, rst);
// position of the line on screen
int xPos = 0;
void setup(){
void setup() {
// initialize the serial port
Serial.begin(9600);
@ -40,27 +40,27 @@ void setup(){
TFTscreen.begin();
// clear the screen with a pretty color
TFTscreen.background(250,16,200);
TFTscreen.background(250, 16, 200);
}
void loop(){
void loop() {
// read the sensor and map it to the screen height
int sensor = analogRead(A0);
int drawHeight = map(sensor,0,1023,0,TFTscreen.height());
int drawHeight = map(sensor, 0, 1023, 0, TFTscreen.height());
// print out the height to the serial monitor
Serial.println(drawHeight);
// draw a line in a nice color
TFTscreen.stroke(250,180,10);
TFTscreen.line(xPos, TFTscreen.height()-drawHeight, xPos, TFTscreen.height());
TFTscreen.stroke(250, 180, 10);
TFTscreen.line(xPos, TFTscreen.height() - drawHeight, xPos, TFTscreen.height());
// if the graph has reached the screen edge
// erase the screen and start again
if (xPos >= 160) {
xPos = 0;
TFTscreen.background(250,16,200);
}
TFTscreen.background(250, 16, 200);
}
else {
// increment the horizontal position:
xPos++;

View File

@ -1,19 +1,19 @@
/*
TFT Pong
This example for the Arduino screen reads the values
This example for the Arduino screen reads the values
of 2 potentiometers to move a rectangular platform
on the x and y axes. The platform can intersect
with a ball causing it to bounce.
on the x and y axes. The platform can intersect
with a ball causing it to bounce.
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/TFTPong
*/
#include <TFT.h> // Arduino LCD library
@ -22,12 +22,12 @@
// pin definition for the Uno
#define cs 10
#define dc 9
#define rst 8
#define rst 8
// pin definition for the Leonardo
// #define cs 7
// #define dc 0
// #define rst 1
// #define rst 1
TFT TFTscreen = TFT(cs, dc, rst);
@ -46,7 +46,7 @@ void setup() {
// initialize the display
TFTscreen.begin();
// black background
TFTscreen.background(0,0,0);
TFTscreen.background(0, 0, 0);
}
void loop() {
@ -54,22 +54,22 @@ void loop() {
// save the width and height of the screen
int myWidth = TFTscreen.width();
int myHeight = TFTscreen.height();
// map the paddle's location to the position of the potentiometers
paddleX = map(analogRead(A0), 512, -512, 0, myWidth) - 20/2;
paddleY = map(analogRead(A1), 512, -512, 0, myHeight) - 5/2;
// set the fill color to black and erase the previous
// position of the paddle if different from present
TFTscreen.fill(0,0,0);
if (oldPaddleX != paddleX || oldPaddleY != paddleY) {
// map the paddle's location to the position of the potentiometers
paddleX = map(analogRead(A0), 512, -512, 0, myWidth) - 20 / 2;
paddleY = map(analogRead(A1), 512, -512, 0, myHeight) - 5 / 2;
// set the fill color to black and erase the previous
// position of the paddle if different from present
TFTscreen.fill(0, 0, 0);
if (oldPaddleX != paddleX || oldPaddleY != paddleY) {
TFTscreen.rect(oldPaddleX, oldPaddleY, 20, 5);
}
// draw the paddle on screen, save the current position
// as the previous.
TFTscreen.fill(255,255,255);
TFTscreen.fill(255, 255, 255);
TFTscreen.rect(paddleX, paddleY, 20, 5);
oldPaddleX = paddleX;
@ -77,59 +77,59 @@ void loop() {
// update the ball's position and draw it on screen
if (millis() % ballSpeed < 2) {
moveBall();
moveBall();
}
}
// this function determines the ball's position on screen
void moveBall() {
// if the ball goes offscreen, reverse the direction:
if (ballX > TFTscreen.width() || ballX < 0) {
ballDirectionX = -ballDirectionX;
}
if (ballX > TFTscreen.width() || ballX < 0) {
ballDirectionX = -ballDirectionX;
}
if (ballY > TFTscreen.height() || ballY < 0) {
ballDirectionY = -ballDirectionY;
}
ballDirectionY = -ballDirectionY;
}
// check if the ball and the paddle occupy the same space on screen
if (inPaddle(ballX, ballY, paddleX, paddleY, 20, 5)) {
ballDirectionX = -ballDirectionX;
ballDirectionY = -ballDirectionY;
}
// update the ball's position
ballX += ballDirectionX;
ballY += ballDirectionY;
// erase the ball's previous position
TFTscreen.fill(0,0,0);
}
// update the ball's position
ballX += ballDirectionX;
ballY += ballDirectionY;
// erase the ball's previous position
TFTscreen.fill(0, 0, 0);
if (oldBallX != ballX || oldBallY != ballY) {
TFTscreen.rect(oldBallX, oldBallY, 5, 5);
}
// draw the ball's current position
TFTscreen.fill(255,255,255);
TFTscreen.fill(255, 255, 255);
TFTscreen.rect(ballX, ballY, 5, 5);
oldBallX = ballX;
oldBallY = ballY;
}
// this function checks the position of the ball
// to see if it intersects with the paddle
boolean inPaddle(int x, int y, int rectX, int rectY, int rectWidth, int rectHeight) {
boolean result = false;
if ((x >= rectX && x <= (rectX + rectWidth)) &&
if ((x >= rectX && x <= (rectX + rectWidth)) &&
(y >= rectY && y <= (rectY + rectHeight))) {
result = true;
}
return result;
result = true;
}
return result;
}