#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <stdint.h>
#include <Adafruit_MLX90614.h>

#define SCREEN_WIDTH 128 // OLED屏的宽，128个像素点
#define SCREEN_HEIGHT 64 // OLED屏的高，64个像素点
#define OLED_RESET 4
 
Adafruit_SSD1306 display(OLED_RESET);
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
int z = 4.0 ;

 
void setup()   
{                
  Serial.begin(9600);
  pinMode(7, OUTPUT);
  
  Serial.println("Adafruit MLX90614 test");  
  mlx.begin();  
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  //屏幕的IIC地址为0X3C
}
 
 
void loop() 
{


  Serial.println("Temperature from MLX90614:");
  Serial.print("Ambient:      ");
  Serial.print(mlx.readAmbientTempC());
  Serial.println(" °C");
  Serial.print("Contactless: ");
  Serial.print(mlx.readObjectTempC());
  Serial.println(" °C");
  Serial.println();
  delay(1000);


  
  display.clearDisplay(); //清屏
 
  display.setTextSize(1); //设置字体大小
  display.setTextColor(WHITE); //设置颜色
  display.setCursor(0,0);
  display.print("Ambient: ");
  display.print(mlx.readAmbientTempC()); //显示环境温度
  display.print("C");
  display.setCursor(0,10);
  display.print("Object: ");
  display.print(mlx.readObjectTempC()+ z);  //显示目标温度
  display.print("C");
  display.display();

  if(mlx.readObjectTempC()+z > 34.5 && mlx.readObjectTempC()+z<37.5)     //传感器测出的目标温度+修正值在正常体温范围
  {
          delay(10);
          tone(7, 1000);              //蜂鸣器提示
          delay(200);
          tone(7, 1200);
          delay(200);
          noTone(7);
  }
if(mlx.readObjectTempC()+z > 37.6)  //体温超过正常值
{
          delay(10);
          tone(7, 1100);              //蜂鸣器“报警”
          delay(100);
          tone(7, 1300);
          delay(100);
          tone(7, 1100);              
          delay(100);
          tone(7, 1300);
          delay(100);
          tone(7, 1100);              
          delay(100);
          tone(7, 1300);
          delay(100);
          tone(7, 1100);              
          delay(100);
          tone(7, 1300);
          delay(100);
          noTone(7);
  }

 
  delay(2000);
  
}
