#define botao_M_A 23
#define motor_estender 4
#define motor_recolher 5
#define fim_estender 18
#define fim_recolher 19
#define botao_estender 21
#define botao_recolher 22
#define luz 32
#define chuva 33
int pwm = 1024;
void setup() {
Serial.begin(115200);
pinMode(botao_M_A, INPUT_PULLUP);
pinMode(motor_estender, OUTPUT);
pinMode(motor_recolher, OUTPUT);
pinMode(botao_estender, INPUT_PULLUP);
pinMode(botao_recolher, INPUT_PULLUP);
pinMode(fim_estender, INPUT_PULLUP);
pinMode(fim_recolher, INPUT_PULLUP);
pinMode(luz, INPUT_PULLUP);
pinMode(chuva, INPUT_PULLUP);
}
void loop() {
float leitura_luz = analogRead(luz);
float leitura_chuva = analogRead(chuva);
Serial.println(leitura_luz);
Serial.println(leitura_chuva);
if(digitalRead(botao_M_A )== HIGH){ // modo automático
if(leitura_chuva >= 500){ // com chuva
aciona_motor_recolher();
}else if(leitura_luz <= 500){ // noite
aciona_motor_recolher();
}else{ // com sol / sem chuva
aciona_motor_estender();
}
}else{ // modo manual
if(digitalRead(botao_estender) == LOW){
aciona_motor_estender();
}else if(digitalRead(botao_recolher) == LOW){
aciona_motor_recolher();
}
}
}
void aciona_motor_estender(){
digitalWrite(motor_estender,HIGH);
/*
if(fim_estender == HIGH){
}else{
analogWrite(motor_estender,0);
}
*/
}
void aciona_motor_recolher(){
digitalWrite(motor_recolher,HIGH);
/*
if(fim_recolher == HIGH){
}else{
analogWrite(motor_recolher,0);
}
*/
}