1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
/*
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
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;
void setup() {
// initialize the display
EsploraTFT.begin();
// clear the background
EsploraTFT.background(0,0,0);
}
void loop()
{
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{
xPos = xPos + (map(xAxis, -512, 512, 2, -2));
}
if (yAxis<10 && yAxis>-10){
yAxis=yAxis;
}
else{
yPos = yPos + (map(yAxis, -512, 512, -2, 2));
}
// don't let the point go past the screen edges
if(xPos > 159){
(xPos = 159);
}
if(xPos < 0){
(xPos = 0);
}
if(yPos > 127){
(yPos = 127);
}
if(yPos < 0){
(yPos = 0);
}
// draw the point
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);
}
delay(33);
}
|