1 | /*
|
---|
2 |
|
---|
3 | Esplora TFT Temperature Display
|
---|
4 |
|
---|
5 | This example for the Arduino TFT screen is for use
|
---|
6 | with an Arduino Esplora.
|
---|
7 |
|
---|
8 | This example reads the temperature of the Esplora's
|
---|
9 | on board thermisistor and displays it on an attached
|
---|
10 | LCD screen, updating every second.
|
---|
11 |
|
---|
12 | This example code is in the public domain.
|
---|
13 |
|
---|
14 | Created 15 April 2013 by Scott Fitzgerald
|
---|
15 |
|
---|
16 | http://arduino.cc/en/Tutorial/EsploraTFTTemp
|
---|
17 |
|
---|
18 | */
|
---|
19 |
|
---|
20 | // include the necessary libraries
|
---|
21 | #include <Esplora.h>
|
---|
22 | #include <TFT.h> // Arduino LCD library
|
---|
23 | #include <SPI.h>
|
---|
24 |
|
---|
25 | char tempPrintout[3]; // array to hold the temperature data
|
---|
26 |
|
---|
27 | void setup() {
|
---|
28 |
|
---|
29 | // Put this line at the beginning of every sketch that uses the GLCD
|
---|
30 | EsploraTFT.begin();
|
---|
31 |
|
---|
32 | // clear the screen with a black background
|
---|
33 | EsploraTFT.background(0, 0, 0);
|
---|
34 |
|
---|
35 | // set the text color to magenta
|
---|
36 | EsploraTFT.stroke(200, 20, 180);
|
---|
37 | // set the text to size 2
|
---|
38 | EsploraTFT.setTextSize(2);
|
---|
39 | // start the text at the top left of the screen
|
---|
40 | // this text is going to remain static
|
---|
41 | EsploraTFT.text("Degrees in C :\n ", 0, 0);
|
---|
42 |
|
---|
43 | // set the text in the loop to size 5
|
---|
44 | EsploraTFT.setTextSize(5);
|
---|
45 | }
|
---|
46 |
|
---|
47 | void loop() {
|
---|
48 |
|
---|
49 | // read the temperature in Celcius and store it in a String
|
---|
50 | String temperature = String(Esplora.readTemperature(DEGREES_C));
|
---|
51 |
|
---|
52 | // convert the string to a char array
|
---|
53 | temperature.toCharArray(tempPrintout, 3);
|
---|
54 |
|
---|
55 | // set the text color to white
|
---|
56 | EsploraTFT.stroke(255, 255, 255);
|
---|
57 | // print the temperature one line below the static text
|
---|
58 | EsploraTFT.text(tempPrintout, 0, 30);
|
---|
59 |
|
---|
60 | delay(1000);
|
---|
61 | // erase the text for the next loop
|
---|
62 | EsploraTFT.stroke(0, 0, 0);
|
---|
63 | EsploraTFT.text(tempPrintout, 0, 30);
|
---|
64 | }
|
---|