I'm making a IR thermometer which using the digital MLX90614 and arduino ATmega328 based on this website http://bildr.org/2011/02/mlx90614-arduino/. I have the color reference which changes its color depend on the temperature. I'm using triple LED RGB.
I wonder if anyone could help me fig out how to connect a button which later will use attachinterrupt so when every I push the button it would take the current temperature as reference and display to the screen. The LCD i'm using right now is the normal 16x2. I will change to the better LCD like nokia 5530 for larger inputs.
Any help or suggesting would be very appreciated.
Thanks.
The code I'm using.
#include <i2cmaster.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
const int redled = 3;
const int blueled = 5;
const int greenled = 6;
int redfade,greenfade,bluefade;
void setup()
{
//Initialize the LCD
lcd.begin(16, 2);
pinMode(redled, OUTPUT);
digitalWrite(redled, HIGH);
pinMode(blueled, OUTPUT);
digitalWrite(blueled, HIGH);
pinMode(greenled, OUTPUT);
digitalWrite(greenled, HIGH);
i2c_init(); //Initialise the i2c bus
PORTC = (1 << PORTC4) | (1 << PORTC5);//enable pullups
}
void loop(){
int dev = 0x5A<<1;
int data_low = 0;
int data_high = 0;
int pec = 0;
i2c_start_wait(dev+I2C_WRITE);
i2c_write(0x07);
// read
i2c_rep_start(dev+I2C_READ);
data_low = i2c_readAck(); //Read 1 byte and then send ack
data_high = i2c_readAck(); //Read 1 byte and then send ack
pec = i2c_readNak();
i2c_stop();
//This converts high and low bytes together and processes temperature, MSB is a error bit and is ignored for temps
double tempFactor = 0.02; // 0.02 degrees per LSB (measurement resolution of the MLX90614)
double tempData = 0x0000; // zero out the data
int frac; // data past the decimal point
// This masks off the error bit of the high byte, then moves it left 8 bits and adds the low byte.
tempData = (double)(((data_high & 0x007F) << 8) + data_low);
tempData = (tempData * tempFactor)-0.01;
float celcius = tempData - 273.15;
float fahrenheit = (celcius*1.8) + 32;
lcd.clear();
lcd.print("Temp (C): ");
lcd.println(celcius);
lcd.setCursor(0,1);
lcd.print("Temp (F): ");
lcd.println(fahrenheit);
digitalWrite(greenled, LOW);
digitalWrite(redled, HIGH);
digitalWrite(blueled, HIGH);
if(fahrenheit > 85)
{
digitalWrite(blueled, HIGH);
redfade=255-(fahrenheit*10);
greenfade=255-(255-(fahrenheit*10));
analogWrite(greenled,greenfade);
analogWrite(redled, redfade);
}
if(fahrenheit < 70)
{
digitalWrite(redled, HIGH);
bluefade=255-(fahrenheit*8);
greenfade = 255-(255-(fahrenheit*10));
analogWrite(greenled, greenfade);
analogWrite(blueled, bluefade);
}
if (fahrenheit > 70 && fahrenheit < 85){
digitalWrite (greenled, LOW);
digitalWrite (blueled, HIGH);
digitalWrite (redled, HIGH);
}
delay(500); // wait a second before printing again
}