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

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

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

File size: 1.2 KB
Line 
1/*
2
3 Esplora TFT Graph
4
5 This example for the Esplora with an Arduino TFT reads
6 the value of the light sensor, and graphs the values on
7 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/EsploraTFTGraph
14
15 */
16
17#include <Esplora.h>
18#include <TFT.h> // Arduino LCD library
19#include <SPI.h>
20
21// position of the line on screen
22int xPos = 0;
23
24void setup() {
25
26 // initialize the screen
27 EsploraTFT.begin();
28
29 // clear the screen with a nice color
30 EsploraTFT.background(250, 16, 200);
31}
32
33void loop() {
34
35 // read the sensor value
36 int sensor = Esplora.readLightSensor();
37 // map the sensor value to the height of the screen
38 int graphHeight = map(sensor, 0, 1023, 0, EsploraTFT.height());
39
40 // draw the line in a pretty color
41 EsploraTFT.stroke(250, 180, 10);
42 EsploraTFT.line(xPos, EsploraTFT.height() - graphHeight, xPos, EsploraTFT.height());
43
44 // if the graph reaches the edge of the screen
45 // erase it and start over from the other side
46 if (xPos >= 160) {
47 xPos = 0;
48 EsploraTFT.background(250, 16, 200);
49 }
50 else {
51 // increment the horizontal position:
52 xPos++;
53 }
54
55 delay(16);
56}
Note: See TracBrowser for help on using the repository browser.