#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
//pins
const int buzzer = 4;
const int button = 2;
//OLED display
#define screen_width 128 //OLED display width in pixels
#define screen_height 64 //OLED display height in pixels
Adafruit_SSD1306 display(screen_width, screen_height); //creating the display object
void oled_display(bool clear_display,int text_size,int cursor_x, int cursor_y,char* string){
if (clear_display){
display.clearDisplay();
}
display.setTextSize(text_size);
display.setTextColor(WHITE);
display.setCursor(cursor_x, cursor_y);
display.print(string);
display.display();
}
char* string temperature;
const float BETA = 3950; // should match the Beta Coefficient of the thermistor
bool count = false;
int time = 0;
void setup() {
pinMode(button, INPUT);
pinMode(buzzer, OUTPUT);
display.begin(SSD1306_SWITCHCAPVCC, 0x3c);
oled_display(true, 2, 6,27, "Temperature");
delay(2000);
}
void loop() {
int analogValue = analogRead(A0);
float celsius_temp = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
temperature = string(celsius_temp) + " ℃";
oled_display(true, 2, 10,27, temperature);
buttonState = digitalRead(button);
if (counter == true){
time += 6
}
if (buttonState == HIGH) {
counter = true;
}
if (time == 120){
tone(buzzer, 1000);
delay(3000);
noTone(buzzer);
}
delay(6000);
}