Monday, February 10, 2014

Esplora example: read temperature sensor

This example read and display temperature sensor of Arduino Esplora on TFT screen, in celsius and fahrenheit.

Read temperature sensor on Arduino Esplora
Read temperature sensor on Arduino Esplora

#include <TFT.h>
#include <SPI.h>
#include <Esplora.h>

int celsius = 0;
int fahrenheit = 0;
char printoutC[3];
char printoutF[3];

void setup()
{
    EsploraTFT.begin();
    EsploraTFT.background(0,0,0);
    
    //preset dummy reading to print
    String dummy = "0";
    dummy.toCharArray(printoutC, 3);
    dummy.toCharArray(printoutC, 3);
    
    EsploraTFT.stroke(255,255,255);
    EsploraTFT.text("degree C: ", 0, 10);
    EsploraTFT.text("degree F: ", 0, 20);
} 

void loop()
{
    //read the temperature sensor
    celsius = Esplora.readTemperature(DEGREES_C);  
    fahrenheit = Esplora.readTemperature(DEGREES_F);

    //clear previous print of reading
    EsploraTFT.stroke(0,0,0);
    EsploraTFT.text(printoutC, 60, 10);
    EsploraTFT.text(printoutF, 60, 20);
    
    String(celsius).toCharArray(printoutC,3);
    String(fahrenheit).toCharArray(printoutF,3);
    EsploraTFT.stroke(255,255,255);
    EsploraTFT.text(printoutC, 60, 10);
    EsploraTFT.text(printoutF, 60, 20);

    delay(1000);
}

No comments:

Post a Comment