const int botao = A0;
const int buzzer = A1;
unsigned long timer = 0;
#include <LiquidCrystal_I2C.h>
#include <LinkedList.h>
#include <StateMachine.h>
LiquidCrystal_I2C lcd(0x27,16,2);
StateMachine machine = StateMachine();
State* S1 = machine.addState(&state1);
State* S2 = machine.addState(&state2);
State* S3 = machine.addState(&state3);
State* S4 = machine.addState(&state4);
void setup() {
Serial.begin(9600);
DDRD = B11111100;
DDRC = B10;
lcd.begin(16,2);
lcd.print("Grupo 4");
S1->addTransition(&transitionS1S2,S2);
S2->addTransition(&transitionS2S3,S3);
S3->addTransition(&transitionS3S4,S4);
S4->addTransition(&transitionS4S1,S1);
}
void loop() {
unsigned long timer = millis();
machine.run();
}
void state1(){
PORTD = B110000;
}
void state2(){
PORTD = B101000;
}
void state3(){
PORTD = B1000100;
}
void state4(){
}
bool transitionS1S2(){
if(millis() - timer >= 5000){
timer = millis();
lcd.clear();
lcd.home();
lcd.print("A:fechando");
lcd.setCursor(0,1);
lcd.print("P:fechado");
return true;
}
else
return false;
}
bool transitionS2S3(){
if(millis() - timer >= 5000){
timer = millis();
lcd.clear();
lcd.home();
lcd.print("A:fechado");
lcd.setCursor(0,1);
lcd.print("P:aberto");
return true;
}
else
return false;
}
bool transitionS3S4(){
if(digitalRead(botao) == HIGH)
return true;
else
return false;
}
bool transitionS4S1(){
if(millis() - timer >= 5000){
timer = millis();
lcd.clear();
lcd.home();
lcd.print("A:aberto");
lcd.setCursor(0,1);
lcd.print("P:fechado");
return true;
}
else
return false;
}