1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-11 22:24:13 +01:00
Arduino/libraries/TFT/examples/Esplora/EsploraTFTEtchASketch/EsploraTFTEtchASketch.ino

81 lines
1.7 KiB
Arduino
Raw Normal View History

2013-05-17 12:39:31 +02:00
/*
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
2013-05-17 12:39:31 +02:00
Esplora, using the values from the accelerometer.
2013-05-17 12:39:31 +02:00
This example code is in the public domain.
2013-05-17 12:39:31 +02:00
Created 15 April 2013 by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/EsploraTFTEtchASketch
2013-05-17 12:39:31 +02:00
*/
2013-05-17 12:39:31 +02:00
#include <Esplora.h>
#include <TFT.h> // Arduino LCD library
#include <SPI.h>
2013-05-17 12:39:31 +02:00
// initial position of the cursor
int xPos = EsploraTFT.width() / 2;
int yPos = EsploraTFT.height() / 2;
2013-05-17 12:39:31 +02:00
void setup() {
// initialize the display
EsploraTFT.begin();
2013-05-17 12:39:31 +02:00
// clear the background
EsploraTFT.background(0, 0, 0);
2013-05-17 12:39:31 +02:00
}
void loop() {
2013-05-17 12:39:31 +02:00
int xAxis = Esplora.readJoystickX(); // read the X axis
int yAxis = Esplora.readJoystickY(); // read the Y axis
// update the position of the line
// depending on the position of the joystick
if (xAxis < 10 && xAxis > -10) {
xPos = xPos;
} else {
2013-05-17 12:39:31 +02:00
xPos = xPos + (map(xAxis, -512, 512, 2, -2));
}
if (yAxis < 10 && yAxis > -10) {
yAxis = yAxis;
} else {
2013-05-17 12:39:31 +02:00
yPos = yPos + (map(yAxis, -512, 512, -2, 2));
}
// don't let the point go past the screen edges
if (xPos > 159) {
2013-05-17 12:39:31 +02:00
(xPos = 159);
}
if (xPos < 0) {
2013-05-17 12:39:31 +02:00
(xPos = 0);
}
if (yPos > 127) {
2013-05-17 12:39:31 +02:00
(yPos = 127);
}
if (yPos < 0) {
2013-05-17 12:39:31 +02:00
(yPos = 0);
}
2013-05-17 12:39:31 +02:00
// draw the point
EsploraTFT.stroke(255, 255, 255);
EsploraTFT.point(xPos, yPos);
2013-05-17 12:39:31 +02:00
// 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);
2013-05-17 12:39:31 +02:00
}
delay(33);
2013-05-17 12:39:31 +02:00
}