1 | /*
|
---|
2 |
|
---|
3 | Esplora TFT Horizon
|
---|
4 |
|
---|
5 | This example for the Arduino TFT and Esplora draws
|
---|
6 | a line on the screen that stays level with the ground
|
---|
7 | as you tile the Esplora side to side
|
---|
8 |
|
---|
9 | This example code is in the public domain.
|
---|
10 |
|
---|
11 | Created 15 April 2013 by Scott Fitzgerald
|
---|
12 |
|
---|
13 | http://arduino.cc/en/Tutorial/EsploraTFTHorizon
|
---|
14 |
|
---|
15 | */
|
---|
16 |
|
---|
17 | #include <Esplora.h>
|
---|
18 | #include <TFT.h> // Arduino LCD library
|
---|
19 | #include <SPI.h>
|
---|
20 |
|
---|
21 | // horizontal start and end positions
|
---|
22 | int yStart = EsploraTFT.height() / 2;
|
---|
23 | int yEnd = EsploraTFT.height() / 2;
|
---|
24 |
|
---|
25 | // previous start and end positions
|
---|
26 | int oldEndY;
|
---|
27 | int oldStartY;
|
---|
28 |
|
---|
29 | void setup() {
|
---|
30 | // initialize the display
|
---|
31 | EsploraTFT.begin();
|
---|
32 | // make the background black
|
---|
33 | EsploraTFT.background(0, 0, 0);
|
---|
34 | }
|
---|
35 |
|
---|
36 | void loop()
|
---|
37 | {
|
---|
38 | // read the x-axis of te accelerometer
|
---|
39 | int tilt = Esplora.readAccelerometer(X_AXIS);
|
---|
40 |
|
---|
41 | // the values are 100 when tilted to the left
|
---|
42 | // and -100 when tilted to the right
|
---|
43 | // map these values to the start and end points
|
---|
44 | yStart = map(tilt, -100, 100, EsploraTFT.height(), 0);
|
---|
45 | yEnd = map(tilt, -100, 100, 0, EsploraTFT.height());
|
---|
46 |
|
---|
47 | // if the previous values are different than the current values
|
---|
48 | // erase the previous line
|
---|
49 | if (oldStartY != yStart || oldEndY != yEnd) {
|
---|
50 | EsploraTFT.stroke(0, 0, 0);
|
---|
51 | EsploraTFT.line(0, oldStartY, EsploraTFT.width(), oldEndY);
|
---|
52 | }
|
---|
53 |
|
---|
54 | // draw the line in magenta
|
---|
55 | EsploraTFT.stroke(255, 0, 255);
|
---|
56 | EsploraTFT.line(0, yStart, EsploraTFT.width(), yEnd);
|
---|
57 |
|
---|
58 | // save the current start and end points
|
---|
59 | // to compare int he next loop
|
---|
60 | oldStartY = yStart;
|
---|
61 | oldEndY = yEnd;
|
---|
62 | delay(10);
|
---|
63 | }
|
---|