I'm a newbie,
I'm using a mlx90614 ir sensor, for my project I want to read temperature and to detect (scan) heat spots ie detect increments in temperature by 5 degrees Fahrenheit.
I have one button to simply read temp, and the other to always check the temp every 1/2 secs, if there is a incerement of 5F, to alarm the user.
After I select either button one or two, I want to break that loop and jump to the desired button pushed loop (if I pressed one, I want to jump to button 2 loop when i press button 2 and vice versa).
Also, I'm not sure If I'm correctly checking the increments for the scan loop.
PLEASE HELP!
This is the code:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <stdint.h>
#include <Adafruit_MLX90614.h>
const int button1 = 2;//read
const int button2 = 3;//scan
int buzzer = 4; //buzzer to pin 4
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
void setup()
{
Serial.begin(57600);
Serial.println("Adafruit MLX90614 test");
mlx.begin();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32)
pinMode (2, INPUT);//button #1 as input
pinMode (3, INPUT);//button #2 as input
pinMode(buzzer, OUTPUT);
}
void loop(){
// Clear the buffer.
display.clearDisplay();
// text display tests
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(16,1);
display.print("Press 1 to read or 2 to scan");
display.display();
if(digitalRead(button1) == HIGH){
do{
// Clear the buffer.
display.clearDisplay();
// text display tests
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(16,1);
display.print("Object 1: ");
display.setCursor(16,9);
display.print(mlx.readObjectTempC());
display.print(" C");
display.setCursor(16,17);
display.print(mlx.readObjectTempF());
display.print(" F");
display.display();
delay(500);
}
while(digitalRead(button2) == LOW);
}
else if(digitalRead(button2) == HIGH){
do{
float sec1 = mlx.readObjectTempF();
delay(500);
float sec2 = mlx.readObjectTempF();
delay(500);
if((sec1 > sec2 + 5) || (sec2 > sec1 + 5)){
// Clear the buffer.
display.clearDisplay();
// text display tests
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(8,0);
display.print("Change in temp");
display.display();
tone(buzzer, 2000); // Send 2KHz sound signal...
delay(500); // ...for 1/2 sec
noTone(buzzer); // Stop sound...
delay(250);
}
else {
// Clear the buffer.
display.clearDisplay();
// text display tests
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(16,1);
display.print("Object 2: ");
display.setCursor(16,9);
display.print(mlx.readObjectTempC());
display.print(" C");
display.setCursor(16,17);
display.print(mlx.readObjectTempF());
display.print(" F");
display.display();
delay(500);
}
}
while(digitalRead(button1) == LOW);
}
}
org_scan1.ino (2.68 KB)