1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-11 22:24:13 +01:00
Arduino/libraries/TFT/examples/Esplora/EsploraTFTGraph/EsploraTFTGraph.ino

57 lines
1.2 KiB
Arduino
Raw Normal View History

2013-05-17 12:39:31 +02:00
/*
Esplora TFT Graph
This example for the Esplora with an Arduino TFT reads
2013-05-17 12:39:31 +02:00
the value of the light sensor, and graphs the values on
the screen.
2013-05-17 12:39:31 +02:00
This example code is in the public domain.
2013-05-17 12:39:31 +02:00
Created 15 April 2013 by Scott Fitzgerald
2013-05-17 12:39:31 +02:00
http://arduino.cc/en/Tutorial/EsploraTFTGraph
2013-05-17 12:39:31 +02:00
*/
#include <Esplora.h>
#include <TFT.h> // Arduino LCD library
#include <SPI.h>
// position of the line on screen
int xPos = 0;
void setup() {
2013-05-17 12:39:31 +02:00
// initialize the screen
EsploraTFT.begin();
// clear the screen with a nice color
EsploraTFT.background(250, 16, 200);
2013-05-17 12:39:31 +02:00
}
void loop() {
2013-05-17 12:39:31 +02:00
// read the sensor value
int sensor = Esplora.readLightSensor();
// map the sensor value to the height of the screen
int graphHeight = map(sensor, 0, 1023, 0, EsploraTFT.height());
2013-05-17 12:39:31 +02:00
// draw the line in a pretty color
EsploraTFT.stroke(250, 180, 10);
2013-05-17 12:39:31 +02:00
EsploraTFT.line(xPos, EsploraTFT.height() - graphHeight, xPos, EsploraTFT.height());
// if the graph reaches the edge of the screen
// erase it and start over from the other side
if (xPos >= 160) {
xPos = 0;
EsploraTFT.background(250, 16, 200);
}
2013-05-17 12:39:31 +02:00
else {
// increment the horizontal position:
xPos++;
}
delay(16);
}