source: rtos_arduino/trunk/arduino_lib/libraries/TFT/examples/Arduino/TFTGraph/TFTGraph.ino@ 136

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

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

File size: 1.4 KB
Line 
1/*
2
3 TFT Graph
4
5 This example for an Arduino screen reads
6 the value of an analog sensor on A0, and
7 graphs the values on the screen.
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/TFTGraph
14
15 */
16
17#include <TFT.h> // Arduino LCD library
18#include <SPI.h>
19
20// pin definition for the Uno
21#define cs 10
22#define dc 9
23#define rst 8
24
25// pin definition for the Leonardo
26// #define cs 7
27// #define dc 0
28// #define rst 1
29
30TFT TFTscreen = TFT(cs, dc, rst);
31
32// position of the line on screen
33int xPos = 0;
34
35void setup() {
36 // initialize the serial port
37 Serial.begin(9600);
38
39 // initialize the display
40 TFTscreen.begin();
41
42 // clear the screen with a pretty color
43 TFTscreen.background(250, 16, 200);
44}
45
46void loop() {
47 // read the sensor and map it to the screen height
48 int sensor = analogRead(A0);
49 int drawHeight = map(sensor, 0, 1023, 0, TFTscreen.height());
50
51 // print out the height to the serial monitor
52 Serial.println(drawHeight);
53
54 // draw a line in a nice color
55 TFTscreen.stroke(250, 180, 10);
56 TFTscreen.line(xPos, TFTscreen.height() - drawHeight, xPos, TFTscreen.height());
57
58 // if the graph has reached the screen edge
59 // erase the screen and start again
60 if (xPos >= 160) {
61 xPos = 0;
62 TFTscreen.background(250, 16, 200);
63 }
64 else {
65 // increment the horizontal position:
66 xPos++;
67 }
68
69 delay(16);
70}
71
Note: See TracBrowser for help on using the repository browser.