2
0
Files
lpsarii/main.cpp
2026-01-20 07:33:49 +01:00

135 lines
3.1 KiB
C++

#include "main.hpp"
#include "autom.cpp"
#include <thread>
#include <atomic>
int marche_precedent = 0;
int marche_frontmontant = 0;
int arret_precedent = 1;
int arret_frontdescedant = 0;
int bouton_precedent[8];
int bouton_frontmontant[8];
int bouton_frontdescendant[8];
int cycle = 0;
long unsigned tempo = 0;
int compteur[4];
int sens = 1;
int ci = 0;
int mode_auto = 0;
int mode_manu = 0;
int etape = 0;
int etape_2 = 0;
int c7_frontdescendant = 0;
int c7_precedent = 0;
int main()
{
mqtt_open(&client);
std::atomic<bool> running{true};
while (running)
{
std::this_thread::sleep_for(std::chrono::seconds(1));
}
mqtt_close();
return 0;
}
void process()
{
// Détection des fronts
// front montant (état courant supérieur à l'état précédent)
// front descendant (état courant inférieur à l'état précédent)
// ****************************************************************
marche_frontmontant = marche > marche_precedent;
arret_frontdescedant = arret < arret_precedent;
for (int i = 0; i < 8; i++)
{
bouton_frontmontant[i] = bouton[i] > bouton_precedent[i];
bouton_frontdescendant[i] = bouton[i] < bouton_precedent[i];
}
/* ****************************************************************
VOTRE PROGRAMME COMMENCE ICI
**************************************************************** */
if (etape == 0 && capteur[1] == 0) {
etape = 10;
tempo = millis();
}
// Etape 10 : 1 moteur allumé
if (etape == 10 && capteur[1] == 0 && millis() >= tempo + 2000) {
etape = 12;
tempo = millis();
}
if (etape == 10 && capteur[2] == 1 && millis() >= tempo + 2000) {
etape = 0;
}
// Etape 12 : 2 moteur allumés
if (etape == 12 && capteur[1] == 0 && millis() >= tempo + 2000) {
etape = 14;
tempo = millis();
}
if (etape == 12 && capteur[2] == 1 && millis() >= tempo + 2000) {
etape = 10;
tempo = millis();
}
// Etape 14 : 3 moteur allumés
if (etape == 14 && capteur[1] == 0 && millis() >= tempo + 2000) {
etape = 16;
tempo = millis();
}
if (etape == 14 && capteur[2] == 1 && millis() >= tempo + 2000) {
etape = 12;
tempo = millis();
}
// Etape 16 : 4 moteur allumés
if (etape == 16 && capteur[2] == 1) {
etape = 14;
tempo = millis();
}
/* ****************************************************************
LES ACTIONS
**************************************************************** */
moteur[0] = (etape == 10 || etape == 12 || etape == 14 || etape == 16);
moteur[1] = (etape == 12 || etape == 14 || etape == 16);
moteur[2] = (etape == 14 || etape == 16);
moteur[3] = (etape == 16);
/* ****************************************************************
VOTRE PROGRAMME S'ARRETE ICI
**************************************************************** */
sortie[10] = etape;
// Prêt pour un nouveau cycle
// L'état courant devient l'état précédent
marche_precedent = marche;
arret_precedent = arret;
for (int i = 0; i < 8; i++)
{
bouton_precedent[i] = bouton[i];
}
c7_precedent = capteur[7];
}