Created
September 28, 2016 21:18
-
-
Save LeoNero/019ad6dddd0d3000288a10fad3d4457d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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