1#include <U8g2lib.h>
2U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);
3float i;
4int buzzer_pin4 = 4;
5int alarma = 50;
6void setup() {
7Serial.begin(9600);
8 pinMode(buzzer_pin4, OUTPUT);
9 u8g2.begin();
10}
11void loop() {
12
13 unsigned int pinA3=pinA3_promedio(200);
14 i=((double)pinA3*450/614.4-70);
15 Serial.print(i);
16 Serial.println("\u2103");
17 delay(100);
18
19 if(i >=alarma){
20 digitalWrite(buzzer_pin4, HIGH);
21 delay(40);
22 digitalWrite(buzzer_pin4, LOW);
23 delay(20);
24 }
25oled();
26}
27
28 int pinA3_promedio(double n)
29{
30 long sumatoria=0;
31 for(int i=0;i<n;i++)
32 {
33 sumatoria=sumatoria+analogRead(A3);
34 }
35 return(sumatoria/n);
36}
37
38void oled(){
39 u8g2.clearBuffer();
40 u8g2.setFont(u8g2_font_ncenB10_tr);
41 u8g2.setCursor(0, 20);
42 u8g2.print("Temp: ");
43 u8g2.print(i);
44 u8g2.print("^C");
45 u8g2.setCursor(0, 40);
46 u8g2.print("Alar: ");
47 u8g2.print(alarma);
48 u8g2.print("^C");
49
50 if(i >= alarma){
51 u8g2.setCursor(0, 60);
52 u8g2.print("Alerta!!!");
53 }
54 u8g2.sendBuffer();
55 }