#include "DHT.h"
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define DHTTYPE DHT22
#define DHTPIN 19
DHT dht(DHTPIN, DHTTYPE);
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library.
// On an arduino UNO: A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO: 2(SDA), 3(SCL), ...
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
const int boton=0;
int estado=1;
int=ultimoestado=HIGH;
const unsigned char img_temp [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf0, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf0, 0x00, 0x00,
0x00, 0x00, 0x00, 0xf0, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x0f, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xf0, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x0f, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xf0, 0x0f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x0f, 0xf0, 0x00, 0x00,
0x00, 0x00, 0x00, 0xf0, 0x0f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x0f, 0xf0, 0x00, 0x00,
0x00, 0x00, 0x00, 0xf3, 0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf3, 0xcf, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xf3, 0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf3, 0xcf, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xf3, 0xcf, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf3, 0xcf, 0xf0, 0x00, 0x00,
0x00, 0x00, 0x00, 0xf3, 0xcf, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf3, 0xcf, 0xf0, 0x00, 0x00,
0x00, 0x00, 0x00, 0xf3, 0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf3, 0xcf, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xf3, 0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf3, 0xcf, 0x80, 0x00, 0x00,
0x00, 0x00, 0x03, 0xf3, 0xcf, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x07, 0xe3, 0xc7, 0xe0, 0x00, 0x00,
0x00, 0x00, 0x0f, 0xc3, 0xc3, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x03, 0xc0, 0xf0, 0x00, 0x00,
0x00, 0x00, 0x1f, 0x03, 0xc0, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x0f, 0xf0, 0x78, 0x00, 0x00,
0x00, 0x00, 0x3e, 0x1f, 0xf8, 0x78, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x1f, 0xf8, 0x3c, 0x00, 0x00,
0x00, 0x00, 0x3c, 0x3f, 0xfc, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x3f, 0xfc, 0x3c, 0x00, 0x00,
0x00, 0x00, 0x3c, 0x3f, 0xfc, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x3f, 0xfc, 0x3c, 0x00, 0x00,
0x00, 0x00, 0x3c, 0x1f, 0xf8, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x1f, 0xf8, 0x7c, 0x00, 0x00,
0x00, 0x00, 0x1e, 0x0f, 0xf0, 0x78, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x03, 0xc0, 0xf8, 0x00, 0x00,
0x00, 0x00, 0x0f, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x01, 0xf0, 0x00, 0x00,
0x00, 0x00, 0x07, 0xe0, 0x07, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x03, 0xf8, 0x1f, 0xc0, 0x00, 0x00,
0x00, 0x00, 0x01, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3f, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xf0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const unsigned char epd_bitmap_gotita [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x08, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x0f, 0x00, 0x00,
0x00, 0x00, 0x3e, 0x0f, 0x80, 0x00, 0x00, 0x00, 0x3e, 0x1f, 0xc0, 0x00, 0x00, 0x00, 0x7f, 0x3f,
0xe0, 0x00, 0x00, 0x00, 0xff, 0xbf, 0xe0, 0x00, 0x00, 0x01, 0xff, 0x9f, 0xf0, 0x00, 0x00, 0x01,
0xff, 0xcf, 0xf8, 0x00, 0x00, 0x03, 0xff, 0xe7, 0xf8, 0x00, 0x00, 0x07, 0xff, 0xf7, 0xfc, 0x00,
0x00, 0x07, 0xff, 0xf3, 0xfe, 0x00, 0x00, 0x0f, 0xff, 0xf9, 0xff, 0x00, 0x00, 0x1f, 0xff, 0xfd,
0xff, 0x00, 0x00, 0x3f, 0xff, 0xfc, 0xff, 0x80, 0x00, 0x3f, 0xff, 0xfe, 0x7f, 0x80, 0x00, 0x7f,
0xff, 0xff, 0x3f, 0xc0, 0x00, 0xff, 0xff, 0xff, 0x3f, 0xc0, 0x00, 0xff, 0xff, 0xff, 0x9f, 0xc0,
0x01, 0xff, 0xff, 0xff, 0xdf, 0xc0, 0x01, 0xff, 0xff, 0xff, 0xcf, 0xc0, 0x01, 0xff, 0xff, 0xff,
0xcf, 0xc0, 0x03, 0xff, 0xff, 0xff, 0xcf, 0x80, 0x03, 0xff, 0xff, 0xff, 0xef, 0x80, 0x03, 0xff,
0xff, 0xf7, 0xef, 0x00, 0x03, 0xff, 0xff, 0xe7, 0xef, 0x00, 0x03, 0xff, 0xff, 0xe7, 0xce, 0x00,
0x01, 0xff, 0xff, 0xef, 0xcc, 0x00, 0x01, 0xff, 0xff, 0xcf, 0xc0, 0x00, 0x01, 0xff, 0xff, 0x9f,
0xc0, 0x00, 0x00, 0xff, 0xff, 0x3f, 0x80, 0x00, 0x00, 0xff, 0xf0, 0x7f, 0x80, 0x00, 0x00, 0x7f,
0xf1, 0xff, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xfc, 0x00, 0x00,
0x00, 0x0f, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x03, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0xff, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
void setup() {
Serial.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
boton_INPUT;
}
Serial.println(F("DHTxx test!"));
dht.begin();
}
void loop() {
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
Serial.print(h);
Serial.print(t);
display.clearDisplay();
display.drawBitmap(0,0,img_temp ,64,64,SSD1306_WHITE);
display.setCursor(52,16);
display.setTextSize(3);
display.setTextColor(WHITE,BLACK);
display.print(t);
display.display();
delay(3000);
display.clearDisplay();
display.drawBitmap(0,0, epd_bitmap_gotita ,48,48,SSD1306_WHITE);
display.setCursor(52,16);
display.setTextSize(2);
display.setTextColor(WHITE,BLACK);
display.print(h);
display.display();
if (estado=1){
digitalWrite(boton, HIGH);
digitalWrite(boton.LOW);}
else{
digitalWrite(LOW)
digitalWrite(HIGH);;
}
int estadoboton=digitalRead(boton)
if (digitalRead(boton)==LOW && ultimoestado==HIGH)
delay(50);//para evitar revote de contacto
if (pantalla=1);
pantalla=2;
else
pantalla=1;
}
ultimoEstado=EstadoBoton;
if (pantalla=1)