Documente Academic
Documente Profesional
Documente Cultură
Raport
Disciplina: Internetul Lucrurilor(IoT)
Tema: “Control comportamental cu Automate Finite”
Chişinău 2022
Sarcina propusă
Sa se realizeze o aplicatie ce va implementa Automatele finite dupa cum urmeaza:
- Proiectare Automat Finit aplicatie Button-Led.
- Proiectare Automat Finit aplicatie Semafor
Recomandare:
- Sa sa se utiliza interfata seriala pentru rapoarte de functionare a automatelor;
- Reutilizati la maxim solutiile prezentate in laboratoarele precedente;
- Revizuiti resursele predate la curs.
Pentru început automatul finit va avea starea inițială și anume ca semaforul pe vertical este verde
iar cel de pe orizontală este roșu. Acest lucru se observă în Figura 2.
Figura 2 – Aprinderea semaforului vertical în intersecție
În cazul când apar mașini pe orizontală, sau în cazul nostru se apasă butonul push care indică
horizontal flow, culorile se vor schimba respectiv, astfel în Figura 3 este aratată această schimbare.
În timpul de schimbare ale culorilor se face o tranziție prin culoarea galbenă după care ajunge la
starea finală, lucru demonstrat în Figura 3.
Codul sursă
#define NORTH_PIN 1
#define EAST_PIN 2
#define EAST_RED_PIN 5
#define EAST_YELLOW_PIN 6
#define EAST_GREEN_PIN 7
#define NORTH_RED_PIN 8
#define NORTH_YELLOW_PIN 9
#define NORTH_GREEN_PIN 10
#define goN 0 // 0b00
#define waitN 1 // 0b01
#define goE 2 // 0b10
#define waitE 3 // 0b11
#define LED_PIN 13
#define LED_BUTTON_PIN 12
#define LED_OFF_STATE 0
#define LED_ON_STATE 1
struct SemaphoreState {
unsigned long Out;
unsigned long Time;
unsigned long Next[4];
};
typedef
const struct SemaphoreState SemaphoreType;
struct LedState {
unsigned long Out;
unsigned long Time;
unsigned long Next[2];
};
typedef
const struct LedState LedType;
SemaphoreType Semaphore[4] = {
{
0b100001,
1000,
{
goN,
waitN,
goN,
waitN
}
},
{
0b100010,
200,
{
goE,
goE,
goE,
goE
}
},
{
0b001100,
1000,
{
goE,
goE,
waitE,
waitE
}
},
{
0b010100,
200,
{
goN,
goN,
goN,
goN
}
}
};
LedType LedFSM[2] = {
{
0,
10,
{
LED_OFF_STATE,
LED_ON_STATE
}
},
{
1,
10,
{
LED_ON_STATE,
LED_OFF_STATE
}
}
};
void setup()
// init led
pinMode(EAST_RED_PIN, OUTPUT);
pinMode(EAST_YELLOW_PIN, OUTPUT);
pinMode(EAST_GREEN_PIN, OUTPUT);
pinMode(NORTH_RED_PIN, OUTPUT);
pinMode(NORTH_YELLOW_PIN, OUTPUT);
pinMode(NORTH_GREEN_PIN, OUTPUT);
pinMode(LED_PIN, OUTPUT);
int GetInputSemaphore(void) {
else if (northButton)
return 0b10;
else if (eastButton)
return 0b01;
else
return 0b00;
int ledState;
void HandleSemaphore(void) {
// 3. get input
Semaphore_State = Semaphore[Semaphore_State].Next[input];
void HandleLed(void) {
void loop()
HandleLed();
HandleSemaphore();