#include <stdint.

h>
#include <TFTv2.h>
#include <SPI.h>
#include <i2cmaster.h>

int direccionSensor1 = 0x50<<1; // Direcci�n del sensor 1
int direccionSensor2 = 0x55<<1; // Direcci�n del sensor 2
int direccionSensor3 = 0x5A<<1; // Direcci�n del sensor 2

float celcius1 = 0; // Guardara temperatura 1 en Celcius
float celcius2 = 0; // Guardara temperatura 2 en Celcius
float celcius3 = 0; // Guardara temperatura 2 en Celcius

void setup()
{
TFT_BL_ON; // Ilumina el TFT Shield
Tft.TFTinit(); // Inicia el TFT Shield*/

Serial.begin(9600); // Comunicaci�n serial en 9600bps.
i2c_init(); // Inicializar i2c bus.
PORTC = (1 << PORTC4) | (1 << PORTC5); // Pullups.
}

void loop()
{
celcius1 = temperaturaCelcius(direccionSensor1); //Lee la temperatura para cada
sensor y
celcius2 = temperaturaCelcius(direccionSensor2); //la guarda en la respectiva
variable
celcius3 = temperaturaCelcius(direccionSensor3); //

/*fahrenheit1 = (celcius1*1.8) + 32; // Sidesean convertir en Fahrenheit
fahrenheit2 = (celcius2*1.8) + 32;*/

Tft.drawString("Temp1",0,0,4,CYAN);
Tft.fillRectangle(0,40,200,70,BLACK);
Tft.drawFloat(celcius1,0,0,40,6,CYAN);

Tft.drawString("Temp2",0,115,4,CYAN);
Tft.fillRectangle(0,155,200,70,BLACK);
Tft.drawFloat(celcius2,0,0,155,6,CYAN);

Tft.drawString("Temp3",0,230,4,CYAN);
Tft.fillRectangle(0,270,200,70,BLACK);
Tft.drawFloat(celcius3,0,0,270,6,CYAN);

Serial.print(celcius1);
Serial.print(",");
Serial.print(celcius1);
Serial.print(",");
Serial.print(celcius2);
Serial.print(",");
Serial.print(celcius3);
Serial.println();

delay(5000); // Espera tres segundo para tomar otro par
de lecturas
}

pec = i2c_readNak(). strcat(str. // Increase if the "units" string is lengthened int ptr = 0. // Data past the decimal point // This masks off the error bit of the high byte.co float temperaturaCelcius(int address) { int dev = address. int pec = 0.02. i2c_write(0x07). // This converts high and low bytes together and processes temperature. int dec = 100 * (value . } /* Function to convert a float (or double) type to a string array * The value will be printed to 2 decimal places */ char* dec2str(float value) { char str[24].005.01. // Read 1 byte and then send ack. // Returns temperature un Celcius. float celcius = tempData . otherwise x. // Remove the sign value += 0.//Funci�n con comentarios originales de http://wiki.02 degrees per LSB (measurement // resolution of the MLX90614). // Array member pointer if (value < -0. // Optionally add � or $ etc for monetary values value = abs(value). tempData = (double)(((data_high & 0x007F) << 8) + data_low). . i2c_stop().(unsigned long)value). // Fudge factor. ptr++. // MSB is a error bit and is ignored for temps. int data_high = 0. ptr++. int data_low = 0. // Read i2c_rep_start(dev+I2C_READ). str + ptr. } // Check sign and append // else {str[ptr]='+'. data_low = i2c_readAck(). ". tempData = (tempData * tempFactor)-0. // 0.15. then moves it left // 8 bits and adds the low byte. // Zero out the data int frac.").273. // Add to round number up value -= 0. return celcius.} // Optionally add + sign at beginning // str[ptr]='$'. ptr++. 10).0049999999 is rounded up (value of 0 not affected) ltoa(value. // Read 1 byte and then send ack. // Write i2c_start_wait(dev+I2C_WRITE).0000000005. data_high = i2c_readAck().wiring. double tempData = 0x0000. double tempFactor = 0.005) { str[ptr] = '-'.

// Could add units string passed as a parameter to function // strcat(str. &str[strlen(str)]. 10). ltoa(dec. if (dec < 10) strcat(str. } ." mV"). // Optionally add "units" to end of string return str. "0").