aboutsummaryrefslogtreecommitdiff
path: root/libraries/TFT/examples/Esplora/EsploraTFTGraph
diff options
context:
space:
mode:
authorCristian Maglie <c.maglie@bug.st>2013-06-01 23:16:02 +0200
committerCristian Maglie <c.maglie@bug.st>2013-06-01 23:16:02 +0200
commit177ad96f866714a4962be57f69cd3d5a6334cde1 (patch)
tree1072239986340d6a239adac924eddf2e1d1ca566 /libraries/TFT/examples/Esplora/EsploraTFTGraph
parent6cff36ac5e85c74bcb45cc53491ad69d64520b36 (diff)
parentd90fcca5839d13d57ed527d4009b78d22dafbde7 (diff)
Merge branch 'merge-1.0.5' into ide-1.5.x-discovery
Diffstat (limited to 'libraries/TFT/examples/Esplora/EsploraTFTGraph')
-rw-r--r--libraries/TFT/examples/Esplora/EsploraTFTGraph/EsploraTFTGraph.ino56
1 files changed, 56 insertions, 0 deletions
diff --git a/libraries/TFT/examples/Esplora/EsploraTFTGraph/EsploraTFTGraph.ino b/libraries/TFT/examples/Esplora/EsploraTFTGraph/EsploraTFTGraph.ino
new file mode 100644
index 0000000..7f2a427
--- /dev/null
+++ b/libraries/TFT/examples/Esplora/EsploraTFTGraph/EsploraTFTGraph.ino
@@ -0,0 +1,56 @@
+/*
+
+ Esplora TFT Graph
+
+ This example for the Esplora with an Arduino TFT reads
+ the value of the light sensor, and graphs the values on
+ the screen.
+
+ This example code is in the public domain.
+
+ Created 15 April 2013 by Scott Fitzgerald
+
+ http://arduino.cc/en/Tutorial/EsploraTFTGraph
+
+ */
+
+#include <Esplora.h>
+#include <TFT.h> // Arduino LCD library
+#include <SPI.h>
+
+// position of the line on screen
+int xPos = 0;
+
+void setup(){
+
+ // initialize the screen
+ EsploraTFT.begin();
+
+ // clear the screen with a nice color
+ EsploraTFT.background(250,16,200);
+}
+
+void loop(){
+
+ // 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());
+
+ // draw the line in a pretty color
+ EsploraTFT.stroke(250,180,10);
+ 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);
+ }
+ else {
+ // increment the horizontal position:
+ xPos++;
+ }
+
+ delay(16);
+}