#include <Tiny4kOLED.h>
#include <dht.h>
//definições
#define DHT22_PIN 8
//Classes
dht DHT;
//Protótipo da função
void iniciaDisplay();
void limpadisplay();
void menuTemperatura();
void incrementa();
void decrementa();
//Variavéis globais
int8_t contador = 0 ;
const uint8_t termometro[] PROGMEM = {
0x00, 0xfe, 0x03, 0xfe, 0x50,
0x00, 0xff, 0x00, 0xff, 0x55,
0x60, 0x9f, 0x80, 0x9f, 0x65,
};
// 'bob_esponja', 68x64px
const unsigned char bob_esponja [] PROGMEM = {
0x00, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x68, 0x58,
0x94, 0x84, 0x1a, 0x52, 0x1a, 0x19, 0x29, 0x0f, 0x00, 0x00, 0x43, 0x04, 0x00, 0x01, 0x44, 0x00,
0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x02, 0x00, 0x00,
0x00, 0x00, 0x00, 0x10, 0x20, 0x00, 0x20, 0x00, 0x00, 0xc0, 0x00, 0x00, 0xc0, 0x00, 0x02, 0x20,
0x00, 0x00, 0x40, 0x00, 0x08, 0x66, 0xff, 0xff, 0xff, 0xff, 0xff, 0xbf, 0xff, 0xff, 0x7e, 0x38,
0x00, 0x9f, 0x1c, 0x1e, 0x00, 0x20, 0x00, 0xf0, 0x05, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x80,
0x06, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x60, 0x00, 0x00, 0x00, 0x18, 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, 0x14,
0x08, 0x00, 0x00, 0x00, 0x04, 0x04, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x01, 0x08, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x02, 0x04, 0x00, 0x00, 0x00, 0x05, 0x01, 0x02, 0x85, 0x25, 0x31, 0x01, 0x00,
0x00, 0x00, 0xc0, 0x08, 0x7a, 0x02, 0xf8, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x02,
0x00, 0x00, 0xfe, 0xf2, 0xf4, 0xe0, 0xfc, 0xc4, 0xf8, 0xf0, 0xf0, 0xe0, 0x00, 0x40, 0xc0, 0xc0,
0xc0, 0xc0, 0xc4, 0xc0, 0xa0, 0x12, 0x80, 0xc0, 0x20, 0x50, 0x00, 0x24, 0x10, 0x20, 0x60, 0x40,
0xc0, 0xc4, 0x13, 0x38, 0x80, 0x00, 0x42, 0x00, 0x00, 0x16, 0x06, 0x0c, 0x09, 0x28, 0x48, 0x68,
0x60, 0x00, 0x08, 0x08, 0x28, 0x00, 0x00, 0x00, 0x80, 0xf0, 0xf8, 0xf0, 0x3c, 0xe0, 0x80, 0xe0,
0xf8, 0x78, 0x00, 0x50, 0x70, 0x20, 0x70, 0x30, 0x20, 0x10, 0x00, 0x00, 0x01, 0x90, 0xb0, 0x08,
0x00, 0x00, 0x10, 0x01, 0x20, 0x5f, 0xc0, 0x0e, 0x30, 0x01, 0x00, 0x40, 0x80, 0x00, 0x40, 0x00,
0x80, 0x80, 0x80, 0x90, 0x84, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x03, 0x00, 0x01, 0x21, 0x25, 0x2f, 0x7f, 0xff, 0xff, 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bf,
0x38, 0x20, 0x44, 0xc6, 0xec, 0x99, 0x97, 0xbf, 0xb7, 0x07, 0x4f, 0x4f, 0xf7, 0x3f, 0x0f, 0x03,
0x01, 0x19, 0x19, 0x19, 0x51, 0x79, 0x36, 0x07, 0x1f, 0x1f, 0x5f, 0x5f, 0x1f, 0x1f, 0x3e, 0xfe,
0xfe, 0xfe, 0xfe, 0xff, 0xff, 0xc0, 0xc0, 0xc0, 0xc4, 0xc0, 0xc0, 0xc0, 0xc0, 0x80, 0x98, 0x80,
0x80, 0x84, 0x84, 0xb8, 0x88, 0x91, 0x93, 0x16, 0x25, 0x07, 0x0f, 0x0e, 0x2e, 0x0f, 0x1d, 0x3f,
0xbf, 0xbf, 0x3e, 0xbc, 0xf8, 0x00, 0x00, 0xc0, 0x90, 0xa0, 0xf0, 0xd8, 0x7b, 0x73, 0xd3, 0xd3,
0xf3, 0x73, 0xa3, 0x87, 0x0f, 0x1e, 0x38, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x61, 0xe0,
0xf0, 0x19, 0x43, 0xc3, 0x83, 0x03, 0x06, 0x07, 0x66, 0xf7, 0xe3, 0xe5, 0xe6, 0xef, 0xe7, 0xe7,
0xef, 0x2f, 0x07, 0x00, 0x00, 0x06, 0x02, 0x0d, 0x09, 0x01, 0x00, 0x00, 0x00, 0x30, 0x10, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x60, 0x40,
0x06, 0x47, 0x67, 0x67, 0xe7, 0xe7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x1f, 0x1f, 0x0f,
0x3f, 0x1f, 0x17, 0xf7, 0xf7, 0xf7, 0x75, 0x01, 0x04, 0x80, 0xe2, 0xe1, 0xe0, 0x00, 0x01, 0x05,
0x63, 0xe3, 0xc3, 0xc3, 0xc2, 0x8f, 0x18, 0x20, 0x00, 0x40, 0xc0, 0xc0, 0x81, 0x81, 0x81, 0x81,
0x81, 0x81, 0x87, 0x8e, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x08, 0x00, 0x01, 0x01, 0x01, 0x01, 0x03, 0x01, 0x03, 0x03, 0x03, 0x01, 0x03,
0x03, 0x03, 0x04, 0x00, 0x00, 0x60, 0x60, 0x20, 0x60, 0x02, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x00, 0x00, 0x00, 0x60, 0xe0, 0xf4, 0xf3, 0xf0,
0xf0, 0xf0, 0xf8, 0xf8, 0xf8, 0xf9, 0xf8, 0xff, 0xff, 0xff, 0xef, 0xff, 0xef, 0xef, 0xec, 0xe8,
0xe8, 0xe8, 0xf8, 0xe8, 0xef, 0xee, 0xe0, 0xfc, 0xe9, 0xfc, 0xff, 0xff, 0xff, 0xfc, 0xfc, 0xfc,
0xfc, 0xfc, 0xfb, 0xff, 0xfb, 0xfb, 0xff, 0xfe, 0xfc, 0xfc, 0xfc, 0xff, 0xff, 0xf7, 0xf7, 0xf7,
0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf6,
0xf6, 0xf6, 0xf4, 0xfc, 0xf2, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};
void setup() {
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(DHT22_PIN, INPUT);
//Configura INT(interrupção) nos pinos 2 e 3
attachInterrupt(digitalPinToInterrupt (3), incrementa, RISING );
attachInterrupt(digitalPinToInterrupt (2), decrementa, RISING );
// put your setup code here, to run once:
iniciaDisplay();
delay(2000);
limpadisplay();
}
void loop() {
/*
oled.setCursor (32,1); // Configuração de cursor
oled.print (F("Contador: ")); //Exibir
oled.print(contador); //Exibir
oled.print(" ");
*/
oled.setCursor (0,0);
oled.bitmap(42,0,68+42,64/8+0, bob_esponja );
}
//Implementação das funções
void iniciaDisplay() {
oled.begin(); //Inicia
oled.clear(); //Limpa
oled.setFont (FONT8X16); //Configurar Fonte
oled.setCursor (35,1); // Configuração de cursor
oled.print (F("IFPB")); //Exibir
oled.setFont (FONT6X8);
oled.setCursor (35,4);
oled.print (F("ADELE"));
oled.setFont (FONT6X8);
oled.setCursor (20,6);
oled.print (F("Sistema Digitais"));
delay (2000);
}
void limpadisplay(){
oled.clear();
oled.switchRenderFrame(); // Trocar metade da tela
oled.clear(); //Limpar
oled.switchRenderFrame();
}
void menuTemperatura(){
DHT.read22(DHT22_PIN);
oled.setFont (FONT8X16);
oled.setCursor(20,1 );
oled.print ("Tem: ");
oled.print (DHT.temperature);
oled.print ( "C ");
oled.setCursor(20,4 );
oled.print ("Hum: ");
oled.print (DHT.humidity);
oled.print ( "% ");
oled.bitmap(3,1,5+3,3+1, termometro);
}
void incrementa(){
// variável local
static long tempo_anterior = 0;
long tempo_atual = millis();
if ((tempo_atual - tempo_anterior) >200){
//contador = contador ++
contador = contador +1;
}
tempo_anterior = tempo_atual;
}
void decrementa(){
static long tempo_anterior = 0;
long tempo_atual = millis();
if ((tempo_atual - tempo_anterior) >200){
contador--;
}
tempo_anterior = tempo_atual;
}