/*
Nome: Aplicação para automatisar uma maquina de lavar louça.
Dev: Marcelo Olimpio.
Empresa: Boxhoney.
Url: https://github.com/Boxhoney.
*/
// definição
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <U8glib.h>
#include <OneWire.h>
#include <DallasTemperature.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_NO_ACK|U8G_I2C_OPT_FAST); // Fast I2C / TWI
#define porta 12
#define power 11
#define select 10
#define sensorAgua 9
#define ONE_WIRE_BUS 8
#define valvulaEnt 7
#define resistencia 6
#define bombaLav 5
#define bombaSaida 4
#define valvulaSec 3
void btnPower();
void btnSelect();
void displaySelect();
void btnStart();
/*
void btnSelectMenu();
void btnCancel();
void loading();
void displayTemp();
void tempoDisplay();
void portaAberta();
void enchendo();
void esvaziando();
*/
// botões-----------------------------------
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
///iniciar variaveis---------------------------------
int selecao,start, ligar;
double tempo;
void setup() {
ligar = 0;
selecao = 0;
Serial.begin(9600);
sensors.begin();
pinMode(power, INPUT_PULLUP);
pinMode(select, INPUT_PULLUP);
pinMode(sensorAgua, INPUT_PULLUP);
pinMode(porta, INPUT_PULLUP);
///-----------------------------------------------
pinMode(bombaSaida, OUTPUT);
pinMode(bombaLav, OUTPUT);
pinMode(resistencia, OUTPUT);
pinMode(valvulaEnt, OUTPUT);
pinMode(valvulaSec, OUTPUT);
///iniciar funções-----------------------------------
}
void loop(){
sensors.requestTemperatures();
lcd.init();
while(ligar == 0){
btnPower("LIGANDO",1);
selecao = 1;
lcd.noBacklight();
digitalWrite(valvulaEnt, LOW);
digitalWrite(valvulaSec, LOW);
digitalWrite(resistencia, LOW);
digitalWrite(bombaLav, LOW);
digitalWrite(bombaSaida, LOW);
Serial.println("DESLIGADO");
}
while(ligar == 1){
lcd.backlight();
btnSelect(5);
Serial.println("SELEÇÃO");
}
while(ligar == 2){
loading(16,"INICIANDO",80);
Serial.println("LAVANDO");
}
}
// funções --------------------------------------------------------
void btnPower(String id,int conn){
if((digitalRead(power)==LOW)){
lcd.clear();
lcd.backlight();
loading(16,id,80);
ligar = conn;
lcd.clear();
delay(80);
}
}
void btnStart(){
if((digitalRead(power)==LOW) && (ligar == 1)){
lcd.backlight();
loading(16,"INICIANDO",80);
ligar = 2;
delay(80);
}
}
void loading(int tempo,String text, int dly){
lcd.clear();
int x = 0;
lcd.setCursor(0,0);
lcd.print(text);
while(tempo > 0){
lcd.setCursor(x,1);
lcd.print("-");
tempo = tempo -1;
x = x + 1;
delay(dly);
}
}
void btnSelect(int x){
displaySelect(16,selecao,"MENU......");
if((digitalRead(select)==LOW)){
selecao = selecao + 1;
displaySelect(16,selecao,"AGUARDE...");
if(selecao > x){
selecao = 1;
ligar = 1;
lcd.clear();
}
lcd.clear();
}
}
void displaySelect(int tempo, int prog,String msn){
int x = 0;
lcd.clear();
lcd.setCursor(0,0);
lcd.print(msn);
lcd.setCursor(11,0);
lcd.print(prog);
while(tempo > 0){
lcd.setCursor(x,1);
lcd.print("-");
tempo = tempo -1;
x = x + 1;
delay(80);
}
if(ligar == 1){
btnStart();
}
btnPower("DESLIGANDO",0);
}
/*
void btnSelectMenu(){
if((digitalRead(select)==LOW)&&(selecao==0)&&(ligar == 1)){
ligar = 2;
displaySelect(16,selecao,"MENU......");
}
}
void btnSelect(int x){
if((digitalRead(select)==LOW)){
selecao = selecao + 1;
ligar = 2;
displaySelect(16,selecao,"AGUARDE...");
if(selecao > x){
selecao = 0;
ligar = 1;
lcd.clear();
}
lcd.clear();
}
}
void displayTemp(int tempo,String text, int dly,double t){
lcd.clear();
int x = 0;
lcd.setCursor(0,0);
lcd.print(text);
lcd.setCursor(10,0);
lcd.print("-");
lcd.setCursor(11,0);
lcd.print(t);
while(tempo > 0){
lcd.setCursor(x,1);
lcd.print("-");
tempo = tempo -1;
x = x + 1;
delay(dly);
}
}
void displaySelect(int tempo, int prog,String msn){
int x = 0;
lcd.clear();
lcd.setCursor(0,0);
lcd.print(msn);
lcd.setCursor(11,0);
lcd.print(prog);
while(tempo > 0){
lcd.setCursor(x,1);
lcd.print("-");
tempo = tempo -1;
x = x + 1;
delay(80);
}
}
void tempoDisplay(int x,String txt,int pr,int call){
lcd.clear();
int xmill = 0;
int xseg = 0 ;
int xmin = x ;
while(xmin > 0){
portaAberta();
enchendo();
btnCancel();
xmill = xmill + 1;
if(xmill == 60){
xseg = xseg + 1;
xmill = 0;
}
if(xseg == 60){
xseg = 0;
xmin = xmin-1;
}
lcd.backlight();
lcd.setCursor(0,0);
lcd.print(xmin);
lcd.setCursor(2,0);
lcd.print(":");
lcd.setCursor(3,0);
lcd.print(xseg);
lcd.setCursor(5,0);
lcd.print(":");
lcd.setCursor(6,0);
lcd.print(xmill);
lcd.setCursor(0,1);
lcd.print(txt);
lcd.setCursor(14,1);
lcd.print(pr);
}
start = call;
lcd.clear();
x = 0;
}
void portaAberta(){
while(digitalRead(porta)!=LOW){
lcd.backlight();
lcd.clear();
loading(16,"PORTA ABERTA",80);
lcd.noBacklight();
}
}
void enchendo(){
while(digitalRead(sensorAgua)!=LOW){
digitalWrite(valvulaEnt,HIGH);
lcd.backlight();
lcd.clear();
loading(16,"ENCHENDO A BACIA",80);
lcd.noBacklight();
}
digitalWrite(valvulaEnt,LOW);
}
void esvaziando(){
while(digitalRead(sensorAgua)!=HIGH){
digitalWrite(bombaSaida,HIGH);
lcd.backlight();
lcd.clear();
loading(16,"ESVAZIANDO A BACIA",80);
//lcd.noBacklight();
}
digitalWrite(bombaSaida,LOW);
}
void aquecendo(double x, double y){
while(x < y){
double temp1 = sensors.getTempCByIndex(0);
sensors.requestTemperatures();
digitalWrite(resistencia,HIGH);
lcd.backlight();
lcd.clear();
displayTemp(16,"AQUECENDO",80,temp1);
}
digitalWrite(resistencia,LOW);
}
*/
Loading
ds18b20
ds18b20