source: arduino-1-6-7/trunk/fuentes/arduino-ide-amd64/libraries/TFT/examples/Esplora/EsploraTFTHorizon/EsploraTFTHorizon.ino @ 46

Last change on this file since 46 was 46, checked in by jrpelegrina, 4 years ago

First release to Xenial

File size: 1.5 KB
Line 
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://www.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
22int yStart = EsploraTFT.height() / 2;
23int yEnd = EsploraTFT.height() / 2;
24
25// previous start and end positions
26int oldEndY;
27int oldStartY;
28
29void setup() {
30  // initialize the display
31  EsploraTFT.begin();
32  // make the background black
33  EsploraTFT.background(0, 0, 0);
34}
35
36void loop() {
37  // read the x-axis of te accelerometer
38  int tilt = Esplora.readAccelerometer(X_AXIS);
39
40  // the values are 100 when tilted to the left
41  // and  -100 when tilted to the right
42  // map these values to the start and end points
43  yStart = map(tilt, -100, 100, EsploraTFT.height(), 0);
44  yEnd = map(tilt, -100, 100, 0, EsploraTFT.height());
45
46  // if the previous values are different than the current values
47  // erase the previous line
48  if (oldStartY != yStart || oldEndY != yEnd) {
49    EsploraTFT.stroke(0, 0, 0);
50    EsploraTFT.line(0, oldStartY, EsploraTFT.width(), oldEndY);
51  }
52
53  // draw the line in magenta
54  EsploraTFT.stroke(255, 0, 255);
55  EsploraTFT.line(0, yStart, EsploraTFT.width(), yEnd);
56
57  // save the current start and end points
58  // to compare int he next loop
59  oldStartY = yStart;
60  oldEndY = yEnd;
61  delay(10);
62}
Note: See TracBrowser for help on using the repository browser.