Skip to content

Instantly share code, notes, and snippets.

@LeoNero
Created September 28, 2016 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeoNero/019ad6dddd0d3000288a10fad3d4457d to your computer and use it in GitHub Desktop.
Save LeoNero/019ad6dddd0d3000288a10fad3d4457d to your computer and use it in GitHub Desktop.
#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 5, 4, 2, 3);
int portaBtnEnter = 10;
int portaBtnMoveSeta = 9;
bool btnEnter;
bool btnMoveSeta;
int posicaoSeta = 0;
int portasPlantas[] = {A0, A1, A2, A3};
int plantas[4];
bool mostrandoPlanta = false;
void setup() {
lcd.begin(16, 2);
pinMode(portaBtnEnter, INPUT);
pinMode(portaBtnMoveSeta, INPUT);
setupInicialDisplay();
Serial.begin(9600);
}
void loop() {
btnEnter = digitalRead(portaBtnEnter);
btnMoveSeta = digitalRead(portaBtnMoveSeta);
delay(100);
setupPlantas();
moverSeta();
selecionarPlanta();
delay(100);
}
void setupInicialDisplay() {
lcd.setCursor(0, 0);
lcd.print("1234");
lcd.setCursor(0, 1);
lcd.print("^");
}
void setupPlantas() {
for (int i = 0; i < 4; i++) {
plantas[i] = analogRead(portasPlantas[i]);
}
}
void moverSeta() {
if (btnMoveSeta) {
lcd.setCursor(posicaoSeta, 1);
lcd.print(" ");
if (posicaoSeta == 3) {
posicaoSeta = 0;
} else {
posicaoSeta += 1;
}
lcd.setCursor(posicaoSeta, 1);
lcd.print("^");
}
}
void selecionarPlanta() {
mostrarDadosPlanta(posicaoSeta);
}
void mostrarDadosPlanta(int planta) {
int valorPlantaSelecionada = analogRead(portasPlantas[planta]);
int valorUmidade = analogicoParaUmidade(valorPlantaSelecionada);
avisaUmidadeSolo(valorUmidade);
avisaNivelAgua(valorPlantaSelecionada);
}
int analogicoParaUmidade(int analogico) {
return map(analogico, 100, 1023, 100, 0);
}
void avisaUmidadeSolo(int umidade) {
lcd.setCursor(6, 0);
lcd.print("Umi: ");
lcd.print(umidade);
lcd.print("%");
}
void avisaNivelAgua(int umidade) {
lcd.setCursor(7, 1);
if (umidade >= 250 && umidade <= 450) {
lcd.print("Ok!");
} else if (umidade >= 451 && umidade <= 650) {
lcd.print("Atencao!");
} else if (umidade > 650) {
lcd.print("Regar!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment