#include <Wire.h>
#include "U8glib.h"
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE); // I2C
#include "Wire.h"
// set all moisture sensors PIN ID
int moisture1 = A0;
int maxMoisture = 80; // Valor inicial de umidade máxima
int minMoisture = 30; // Valor inicial de umidade mínima
bool editing = false; // Flag para saber se estamos no modo de edição
// declare moisture values
int moisture1_value = 0 ;
// set water relays
int relay1 = 6;
// set water pump
int pump = 4;
// set button
int button = 12;
int buttonSet = 6;
int buttonPlus = 5;
int buttonMinus = 4;
//pump state 1:open 0:close
int pump_state_flag = 0;
//relay1 state 1:open 0:close
int relay1_state_flag = 0;
// 'flower_health_000', 32x64px
const unsigned char epd_bitmap_flower_health_000 [] 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, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00,
0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x5a, 0x00, 0x00, 0x00, 0x55, 0x00, 0x00, 0x00, 0xa5, 0x00,
0x00, 0x00, 0x15, 0x01, 0x00, 0x80, 0xf2, 0x01, 0x00, 0x80, 0x02, 0x00, 0xe0, 0xff, 0xff, 0x0f,
0x20, 0x00, 0x00, 0x08, 0x20, 0x00, 0x00, 0x08, 0xe0, 0xfa, 0xff, 0x0f, 0x40, 0x00, 0x00, 0x04,
0x40, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x02, 0x80, 0x00, 0x00, 0x02,
0x80, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01,
0x00, 0x02, 0x80, 0x00, 0x00, 0x02, 0x80, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0xf8, 0x3f, 0x00
};
// 'flower_health_010', 32x64px
const unsigned char epd_bitmap_flower_health_010 [] 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, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x0a, 0x00, 0x00, 0x50, 0x15, 0x00,
0x00, 0x10, 0x10, 0x00, 0x00, 0x20, 0x08, 0x00, 0x00, 0xc0, 0x07, 0x00, 0x00, 0x80, 0x02, 0x00,
0x00, 0x80, 0x02, 0x00, 0x00, 0x87, 0xc2, 0x01, 0x00, 0x99, 0x32, 0x01, 0xe0, 0xff, 0xff, 0x0f,
0x20, 0x00, 0x00, 0x08, 0x20, 0x00, 0x00, 0x08, 0xe0, 0xfa, 0xff, 0x0f, 0x40, 0x00, 0x00, 0x04,
0x40, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x02, 0x80, 0x00, 0x00, 0x02,
0x80, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01,
0x00, 0x02, 0x80, 0x00, 0x00, 0xfa, 0xbf, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0xf8, 0x3f, 0x00
};
// 'flower_health_020', 32x64px
const unsigned char epd_bitmap_flower_health_020 [] 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, 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, 0x00, 0x00, 0x00, 0xa0, 0x0a, 0x00, 0x00, 0x50, 0x15, 0x00,
0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x20, 0x08, 0x00, 0x00, 0xc0, 0x07, 0x00,
0x00, 0x80, 0x02, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x80, 0x02, 0x00,
0x80, 0x83, 0x82, 0x03, 0x80, 0x8c, 0x62, 0x02, 0x80, 0x90, 0x12, 0x02, 0xe0, 0xff, 0xff, 0x0f,
0x20, 0x00, 0x00, 0x08, 0x20, 0x00, 0x00, 0x08, 0xe0, 0xfa, 0xff, 0x0f, 0x40, 0x00, 0x00, 0x04,
0x40, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x02, 0x80, 0x00, 0x00, 0x02,
0x80, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01,
0x00, 0xfa, 0xbf, 0x00, 0x00, 0xfa, 0xbf, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0xf8, 0x3f, 0x00
};
// 'flower_health_030', 32x64px
const unsigned char epd_bitmap_flower_health_030 [] 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, 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, 0xc0, 0x07, 0x00, 0x00, 0x20, 0x08, 0x00, 0x00, 0x90, 0x10, 0x00,
0x00, 0x50, 0x11, 0x00, 0x00, 0x90, 0x10, 0x00, 0x00, 0x10, 0x14, 0x00, 0x00, 0x10, 0x12, 0x00,
0x00, 0x20, 0x08, 0x00, 0x00, 0xc0, 0x07, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x80, 0x02, 0x00,
0x00, 0x80, 0x02, 0x00, 0x00, 0x80, 0x02, 0x00, 0xc0, 0x81, 0x02, 0x07, 0x40, 0x86, 0xc2, 0x04,
0x40, 0x88, 0x22, 0x04, 0x40, 0x92, 0x92, 0x04, 0x80, 0xa4, 0x4a, 0x02, 0xe0, 0xff, 0xff, 0x0f,
0x20, 0x00, 0x00, 0x08, 0x20, 0x00, 0x00, 0x08, 0xe0, 0xfa, 0xff, 0x0f, 0x40, 0x00, 0x00, 0x04,
0x40, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x02, 0x80, 0x00, 0x00, 0x02,
0x80, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0xfd, 0x7f, 0x01,
0x00, 0xfa, 0xbf, 0x00, 0x00, 0xfa, 0xbf, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0xf8, 0x3f, 0x00
};
// 'flower_health_040', 32x64px
const unsigned char epd_bitmap_flower_health_040 [] 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, 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, 0x80, 0x03, 0x00, 0x00, 0x40, 0x04, 0x00, 0x00, 0xe0, 0x0f, 0x00,
0x00, 0x30, 0x18, 0x00, 0x00, 0x98, 0x30, 0x00, 0x00, 0x54, 0x51, 0x00, 0x00, 0x94, 0x50, 0x00,
0x00, 0x14, 0x54, 0x00, 0x00, 0x18, 0x32, 0x00, 0x00, 0x30, 0x18, 0x00, 0x00, 0xe0, 0x0f, 0x00,
0x00, 0x40, 0x04, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x80, 0x02, 0x00,
0x00, 0x80, 0x02, 0x00, 0xc0, 0x81, 0x02, 0x07, 0x40, 0x86, 0xc2, 0x04, 0x40, 0x88, 0x22, 0x04,
0x40, 0x92, 0x92, 0x04, 0x80, 0xa4, 0x4a, 0x02, 0x80, 0xa8, 0x2a, 0x02, 0xe0, 0xff, 0xff, 0x0f,
0x20, 0x00, 0x00, 0x08, 0x20, 0x00, 0x00, 0x08, 0xe0, 0xfa, 0xff, 0x0f, 0x40, 0x00, 0x00, 0x04,
0x40, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x02, 0x80, 0x00, 0x00, 0x02,
0x80, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0x00, 0xfd, 0x7f, 0x01, 0x00, 0xfd, 0x7f, 0x01,
0x00, 0xfa, 0xbf, 0x00, 0x00, 0xfa, 0xbf, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0xf8, 0x3f, 0x00
};
// 'flower_health_050', 32x64px
const unsigned char epd_bitmap_flower_health_050 [] 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00, 0x40, 0x04, 0x00,
0x00, 0x20, 0x08, 0x00, 0x00, 0x20, 0x09, 0x00, 0x00, 0xe0, 0x0f, 0x00, 0x00, 0x3c, 0x78, 0x00,
0x00, 0x92, 0x90, 0x00, 0x00, 0x51, 0x11, 0x01, 0x00, 0x99, 0x30, 0x01, 0x00, 0x11, 0x14, 0x01,
0x00, 0x12, 0x92, 0x00, 0x00, 0x3c, 0x78, 0x00, 0x00, 0xe0, 0x0f, 0x00, 0x00, 0x20, 0x09, 0x00,
0x00, 0x20, 0x08, 0x00, 0x00, 0x40, 0x04, 0x00, 0x00, 0x80, 0x03, 0x00, 0xe0, 0x80, 0x02, 0x0e,
0x20, 0x83, 0x82, 0x09, 0x20, 0x84, 0x42, 0x08, 0x20, 0x89, 0x22, 0x09, 0x40, 0x92, 0x92, 0x04,
0x40, 0x94, 0x52, 0x04, 0x80, 0xa0, 0x0a, 0x02, 0x00, 0xa1, 0x0a, 0x01, 0xe0, 0xff, 0xff, 0x0f,
0x20, 0x00, 0x00, 0x08, 0x20, 0x00, 0x00, 0x08, 0xe0, 0xfa, 0xff, 0x0f, 0x40, 0x00, 0x00, 0x04,
0x40, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x02, 0x80, 0x00, 0x00, 0x02,
0x80, 0x00, 0x00, 0x02, 0x00, 0xfd, 0x7f, 0x01, 0x00, 0xfd, 0x7f, 0x01, 0x00, 0xfd, 0x7f, 0x01,
0x00, 0xfa, 0xbf, 0x00, 0x00, 0xfa, 0xbf, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0xf8, 0x3f, 0x00
};
// 'flower_health_060', 32x64px
const unsigned char epd_bitmap_flower_health_060 [] 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x80, 0x03, 0x00, 0x00, 0x40, 0x04, 0x00, 0x00, 0x20, 0x08, 0x00, 0x00, 0x20, 0x09, 0x00,
0x00, 0x20, 0x09, 0x00, 0x00, 0xe0, 0x0f, 0x00, 0x00, 0x3e, 0xf8, 0x00, 0x00, 0x91, 0x10, 0x01,
0x80, 0x50, 0x11, 0x02, 0x80, 0x9c, 0x70, 0x02, 0x80, 0x10, 0x14, 0x02, 0x00, 0x11, 0x12, 0x01,
0x00, 0x3e, 0xf8, 0x00, 0x00, 0xe0, 0x0f, 0x00, 0x00, 0x20, 0x09, 0x00, 0x00, 0x20, 0x09, 0x00,
0x00, 0x20, 0x08, 0x00, 0x00, 0x40, 0x04, 0x00, 0x00, 0x80, 0x03, 0x00, 0xe0, 0x80, 0x02, 0x0e,
0x20, 0x83, 0x82, 0x09, 0x20, 0x84, 0x42, 0x08, 0x20, 0x89, 0x22, 0x09, 0x40, 0x92, 0x92, 0x04,
0x40, 0x94, 0x52, 0x04, 0x80, 0xa0, 0x0a, 0x02, 0x00, 0xa1, 0x0a, 0x01, 0xe0, 0xff, 0xff, 0x0f,
0x20, 0x00, 0x00, 0x08, 0x20, 0x00, 0x00, 0x08, 0xe0, 0xfa, 0xff, 0x0f, 0x40, 0x00, 0x00, 0x04,
0x40, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x02, 0x80, 0x00, 0x00, 0x02,
0x80, 0xfe, 0xff, 0x02, 0x00, 0xfd, 0x7f, 0x01, 0x00, 0xfd, 0x7f, 0x01, 0x00, 0xfd, 0x7f, 0x01,
0x00, 0xfa, 0xbf, 0x00, 0x00, 0xfa, 0xbf, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0xf8, 0x3f, 0x00
};
// 'flower_health_070', 32x64px
const unsigned char epd_bitmap_flower_health_070 [] 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00, 0x40, 0x04, 0x00,
0x00, 0x20, 0x08, 0x00, 0x00, 0x20, 0x09, 0x00, 0x00, 0x20, 0x09, 0x00, 0x00, 0x20, 0x08, 0x00,
0x00, 0xc0, 0x07, 0x00, 0x00, 0x2f, 0xe8, 0x01, 0x80, 0x90, 0x10, 0x02, 0x40, 0x50, 0x11, 0x04,
0x40, 0x96, 0xd0, 0x04, 0x40, 0x10, 0x14, 0x04, 0x80, 0x10, 0x12, 0x02, 0x00, 0x2f, 0xe8, 0x01,
0x00, 0xc0, 0x07, 0x00, 0x00, 0x20, 0x08, 0x00, 0x00, 0x20, 0x09, 0x00, 0x00, 0x20, 0x09, 0x00,
0x00, 0x20, 0x08, 0x00, 0x00, 0x40, 0x04, 0x00, 0xe0, 0x80, 0x03, 0x0e, 0x20, 0x83, 0x82, 0x09,
0x20, 0x84, 0x42, 0x08, 0x20, 0x89, 0x22, 0x09, 0x40, 0x92, 0x92, 0x04, 0x40, 0x94, 0x52, 0x04,
0x80, 0xa0, 0x0a, 0x02, 0x00, 0xa1, 0x0a, 0x01, 0x00, 0xa6, 0xca, 0x00, 0xe0, 0xff, 0xff, 0x0f,
0x20, 0x00, 0x00, 0x08, 0x20, 0x00, 0x00, 0x08, 0xe0, 0xfa, 0xff, 0x0f, 0x40, 0x00, 0x00, 0x04,
0x40, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x02, 0x80, 0xfe, 0xff, 0x02,
0x80, 0xfe, 0xff, 0x02, 0x00, 0xfd, 0x7f, 0x01, 0x00, 0xfd, 0x7f, 0x01, 0x00, 0xfd, 0x7f, 0x01,
0x00, 0xfa, 0xbf, 0x00, 0x00, 0xfa, 0xbf, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0xf8, 0x3f, 0x00
};
// 'flower_health_090', 32x64px
const unsigned char epd_bitmap_flower_health_090 [] 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, 0x80, 0x03, 0x00, 0x00, 0x40, 0x04, 0x00, 0x00, 0x3c, 0x78, 0x00, 0x00, 0x22, 0x89, 0x00,
0x00, 0x21, 0x09, 0x01, 0x00, 0x29, 0x28, 0x01, 0x00, 0xd1, 0x17, 0x01, 0x00, 0x2f, 0xe8, 0x01,
0x80, 0x90, 0x10, 0x02, 0x40, 0x50, 0x11, 0x04, 0x40, 0x96, 0xd0, 0x04, 0x40, 0x10, 0x14, 0x04,
0x80, 0x10, 0x12, 0x02, 0x00, 0x2f, 0xe8, 0x01, 0x00, 0xd1, 0x17, 0x01, 0x00, 0x29, 0x28, 0x01,
0x00, 0x21, 0x09, 0x01, 0x00, 0x22, 0x89, 0x00, 0x00, 0x3c, 0x78, 0x00, 0x00, 0x40, 0x04, 0x00,
0x00, 0x80, 0x03, 0x00, 0x00, 0x80, 0x02, 0x00, 0xe0, 0x80, 0x02, 0x0e, 0x20, 0x83, 0x82, 0x09,
0x20, 0x84, 0x42, 0x08, 0x20, 0x89, 0x22, 0x09, 0x40, 0x92, 0x92, 0x04, 0x40, 0x94, 0x52, 0x04,
0x80, 0xa0, 0x0a, 0x02, 0x00, 0xa1, 0x0a, 0x01, 0x00, 0xa6, 0xca, 0x00, 0xe0, 0xff, 0xff, 0x0f,
0x20, 0x00, 0x00, 0x08, 0x20, 0x00, 0x00, 0x08, 0xe0, 0xfa, 0xff, 0x0f, 0x40, 0x00, 0x00, 0x04,
0x40, 0x00, 0x00, 0x04, 0x40, 0xff, 0xff, 0x05, 0x80, 0xfe, 0xff, 0x02, 0x80, 0xfe, 0xff, 0x02,
0x80, 0xfe, 0xff, 0x02, 0x00, 0xfd, 0x7f, 0x01, 0x00, 0xfd, 0x7f, 0x01, 0x00, 0xfd, 0x7f, 0x01,
0x00, 0xfa, 0xbf, 0x00, 0x00, 0xfa, 0xbf, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0xf8, 0x3f, 0x00
};
// 'flower_health_080', 32x64px
const unsigned char epd_bitmap_flower_health_080 [] 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, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00, 0x40, 0x04, 0x00, 0x00, 0x20, 0x08, 0x00,
0x00, 0x38, 0x39, 0x00, 0x00, 0x24, 0x49, 0x00, 0x00, 0x22, 0x88, 0x00, 0x00, 0xd2, 0x97, 0x00,
0x00, 0x2f, 0xe8, 0x01, 0x80, 0x90, 0x10, 0x02, 0x40, 0x50, 0x11, 0x04, 0x40, 0x96, 0xd0, 0x04,
0x40, 0x10, 0x14, 0x04, 0x80, 0x10, 0x12, 0x02, 0x00, 0x2f, 0xe8, 0x01, 0x00, 0xd2, 0x97, 0x00,
0x00, 0x22, 0x88, 0x00, 0x00, 0x24, 0x49, 0x00, 0x00, 0x38, 0x39, 0x00, 0x00, 0x20, 0x08, 0x00,
0x00, 0x40, 0x04, 0x00, 0x00, 0x80, 0x03, 0x00, 0xe0, 0x80, 0x02, 0x0e, 0x20, 0x83, 0x82, 0x09,
0x20, 0x84, 0x42, 0x08, 0x20, 0x89, 0x22, 0x09, 0x40, 0x92, 0x92, 0x04, 0x40, 0x94, 0x52, 0x04,
0x80, 0xa0, 0x0a, 0x02, 0x00, 0xa1, 0x0a, 0x01, 0x00, 0xa6, 0xca, 0x00, 0xe0, 0xff, 0xff, 0x0f,
0x20, 0x00, 0x00, 0x08, 0x20, 0x00, 0x00, 0x08, 0xe0, 0xfa, 0xff, 0x0f, 0x40, 0x00, 0x00, 0x04,
0x40, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0x04, 0x80, 0xfe, 0xff, 0x02, 0x80, 0xfe, 0xff, 0x02,
0x80, 0xfe, 0xff, 0x02, 0x00, 0xfd, 0x7f, 0x01, 0x00, 0xfd, 0x7f, 0x01, 0x00, 0xfd, 0x7f, 0x01,
0x00, 0xfa, 0xbf, 0x00, 0x00, 0xfa, 0xbf, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0xf8, 0x3f, 0x00
};
// 'flower_health_100', 32x64px
const unsigned char epd_bitmap_flower_health_100 [] 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, 0x80, 0x03, 0x00,
0x00, 0x4e, 0xe4, 0x00, 0x00, 0x31, 0x18, 0x01, 0x80, 0x20, 0x09, 0x02, 0x80, 0x24, 0x49, 0x02,
0x80, 0x28, 0x28, 0x02, 0x00, 0xc1, 0x07, 0x01, 0x00, 0x2f, 0xe8, 0x01, 0x80, 0x90, 0x10, 0x02,
0x40, 0x50, 0x11, 0x04, 0x40, 0x96, 0xd0, 0x04, 0x40, 0x10, 0x14, 0x04, 0x80, 0x10, 0x12, 0x02,
0x00, 0x2f, 0xe8, 0x01, 0x00, 0xc1, 0x07, 0x01, 0x80, 0x28, 0x28, 0x02, 0x80, 0x24, 0x49, 0x02,
0x80, 0x20, 0x09, 0x02, 0x00, 0x31, 0x18, 0x01, 0x00, 0x4e, 0xe4, 0x00, 0x00, 0x80, 0x03, 0x00,
0x00, 0x80, 0x02, 0x00, 0x00, 0x80, 0x02, 0x00, 0xe0, 0x80, 0x02, 0x0e, 0x20, 0x83, 0x82, 0x09,
0x20, 0x84, 0x42, 0x08, 0x20, 0x89, 0x22, 0x09, 0x40, 0x92, 0x92, 0x04, 0x40, 0x94, 0x52, 0x04,
0x80, 0xa0, 0x0a, 0x02, 0x00, 0xa1, 0x0a, 0x01, 0x00, 0xa6, 0xca, 0x00, 0xe0, 0xff, 0xff, 0x0f,
0x20, 0x00, 0x00, 0x08, 0x20, 0x00, 0x00, 0x08, 0xe0, 0xfa, 0xff, 0x0f, 0x40, 0x00, 0x00, 0x04,
0x40, 0xff, 0xff, 0x05, 0x40, 0xff, 0xff, 0x05, 0x80, 0xfe, 0xff, 0x02, 0x80, 0xfe, 0xff, 0x02,
0x80, 0xfe, 0xff, 0x02, 0x00, 0xfd, 0x7f, 0x01, 0x00, 0xfd, 0x7f, 0x01, 0x00, 0xfd, 0x7f, 0x01,
0x00, 0xfa, 0xbf, 0x00, 0x00, 0xfa, 0xbf, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0xf8, 0x3f, 0x00
};
// Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 2992)
const unsigned char* bitmaps_flowers[11] = {
epd_bitmap_flower_health_000,
epd_bitmap_flower_health_010,
epd_bitmap_flower_health_020,
epd_bitmap_flower_health_030,
epd_bitmap_flower_health_040,
epd_bitmap_flower_health_050,
epd_bitmap_flower_health_060,
epd_bitmap_flower_health_070,
epd_bitmap_flower_health_080,
epd_bitmap_flower_health_090,
epd_bitmap_flower_health_100
};
void setup()
{
delay(2000);
Wire.begin();
Serial.begin(9600);
// declare relay as output
pinMode(relay1, OUTPUT);
// declare pump as output
pinMode(pump, OUTPUT);
// declare switch as input
pinMode(button, INPUT_PULLUP);
pinMode(buttonSet, INPUT_PULLUP);
pinMode(buttonMinus, INPUT_PULLUP);
pinMode(buttonPlus, INPUT_PULLUP);
}
void loop() {
// Ler os valores do sensor de umidade
read_value();
water_flower();
// Verificar o estado do botão Set
if (digitalRead(buttonSet) == LOW) {
// Alternar entre editar e visualizar
editing = !editing;
delay(500); // Debounce do botão
}
// Se estiver no modo de edição, alterar os valores de maxMoisture e minMoisture
if (editing) {
if (digitalRead(buttonPlus) == LOW) {
maxMoisture += 5; // Aumentar maxMoisture
minMoisture += 5; // Aumentar minMoisture
delay(200); // Debounce do botão
}
if (digitalRead(buttonMinus) == LOW) {
maxMoisture -= 5; // Diminuir maxMoisture
minMoisture -= 5; // Diminuir minMoisture
delay(200); // Debounce do botão
}
}
// Exibir os valores na tela (primeiro exibe umidade, depois os valores max/min)
u8g.firstPage();
do {
drawTH(); // Exibe o valor de umidade
drawLimits(); // Exibe os valores de maxMoisture e minMoisture
} while (u8g.nextPage());
}
// Função para ler o valor do sensor de umidade
void read_value() {
float value1 = analogRead(A0);
moisture1_value = map(value1, 590, 360, 0, 100);
delay(20);
if (moisture1_value < 0) {
moisture1_value = 0;
}
}
// Função para controlar a irrigação
void water_flower() {
if (moisture1_value < minMoisture) {
digitalWrite(relay1, HIGH);
relay1_state_flag = 1;
if (pump_state_flag == 0) {
digitalWrite(pump, HIGH);
pump_state_flag = 1;
}
}
else if (moisture1_value > maxMoisture) {
digitalWrite(relay1, LOW);
relay1_state_flag = 0;
if (relay1_state_flag == 0) {
digitalWrite(pump, LOW);
pump_state_flag = 0;
}
}
}
// Função para desenhar o valor de umidade no display
void drawTH() {
char buffer[20];
int str_width;
u8g.setFont(u8g_font_7x14);
itoa(constrain(moisture1_value, 0, 100), buffer, 10);
str_width = u8g.getStrWidth(buffer);
u8g.drawStr(60 - str_width / 2, 12, buffer);
}
// Função para desenhar os valores maxMoisture e minMoisture na tela
void drawLimits() {
char bufferMax[20], bufferMin[20];
int str_widthMax, str_widthMin;
u8g.setFont(u8g_font_7x14);
// Convertendo os valores para string
itoa(maxMoisture, bufferMax, 10);
itoa(minMoisture, bufferMin, 10);
// Desenhando os valores na parte direita da tela
str_widthMax = u8g.getStrWidth(bufferMax);
str_widthMin = u8g.getStrWidth(bufferMin);
// Desenhando maxMoisture na parte superior direita
u8g.drawStr(100 - str_widthMax, 12, bufferMax);
// Desenhando minMoisture na parte inferior direita
u8g.drawStr(100 - str_widthMin, 30, bufferMin);
}