source: rtos_arduino/trunk/arduino_lib/libraries/TFT/examples/Esplora/EsploraTFTHorizon/EsploraTFTHorizon.ino@ 136

Last change on this file since 136 was 136, checked in by ertl-honda, 8 years ago

ライブラリとOS及びベーシックなサンプルの追加.

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://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{
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}
Note: See TracBrowser for help on using the repository browser.