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

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

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

File size: 1.7 KB
Line 
1/*
2
3 Esplora TFT EtchASketch
4
5 This example for the Arduino TFT and Esplora draws
6 a white line on the screen, based on the position
7 of the joystick. To clear the screen, shake the
8 Esplora, using the values from the accelerometer.
9
10 This example code is in the public domain.
11
12 Created 15 April 2013 by Scott Fitzgerald
13
14 http://arduino.cc/en/Tutorial/EsploraTFTEtchASketch
15
16 */
17
18#include <Esplora.h>
19#include <TFT.h> // Arduino LCD library
20#include <SPI.h>
21
22// initial position of the cursor
23int xPos = EsploraTFT.width() / 2;
24int yPos = EsploraTFT.height() / 2;
25
26void setup() {
27 // initialize the display
28 EsploraTFT.begin();
29
30 // clear the background
31 EsploraTFT.background(0, 0, 0);
32}
33
34void loop()
35{
36
37 int xAxis = Esplora.readJoystickX(); // read the X axis
38 int yAxis = Esplora.readJoystickY(); // read the Y axis
39
40 // update the position of the line
41 // depending on the position of the joystick
42 if (xAxis < 10 && xAxis > -10) {
43 xPos = xPos;
44 }
45 else {
46 xPos = xPos + (map(xAxis, -512, 512, 2, -2));
47 }
48 if (yAxis < 10 && yAxis > -10) {
49 yAxis = yAxis;
50 }
51 else {
52 yPos = yPos + (map(yAxis, -512, 512, -2, 2));
53 }
54
55 // don't let the point go past the screen edges
56 if (xPos > 159) {
57 (xPos = 159);
58 }
59
60 if (xPos < 0) {
61 (xPos = 0);
62 }
63 if (yPos > 127) {
64 (yPos = 127);
65 }
66
67 if (yPos < 0) {
68 (yPos = 0);
69 }
70
71 // draw the point
72 EsploraTFT.stroke(255, 255, 255);
73 EsploraTFT.point(xPos, yPos);
74
75 // check the accelerometer values and clear
76 // the screen if it is being shaken
77 if (abs(Esplora.readAccelerometer(X_AXIS)) > 200 || abs(Esplora.readAccelerometer(Y_AXIS)) > 200) {
78 EsploraTFT.background(0, 0, 0);
79 }
80
81 delay(33);
82}
83
Note: See TracBrowser for help on using the repository browser.