4.0 KiB
#include "main.hpp" #include "autom.cpp" #include #include
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 moteur_plusutilise(); int moteur_moinsutilise();
int main() { mqtt_open(&client);
std::atomic 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 == 11 && capteur[2] == 1 && millis() >= tempo + 2000)
{
etape = 0;
tempo = millis();
}
// Etape 12 : 2 moteurs allumés
if (etape == 12 && capteur[1] == 0 && millis() >= tempo + 2000)
{
etape = 14;
tempo = millis();
}
if (etape == 12 && capteur[2] == 1)
{
etape = 11;
}
if (etape == 13 && capteur[2] == 1 && millis() >= tempo + 2000)
{
etape = 11;
tempo = millis();
}
// Etape 14 : 3 moteurs allumés
if (etape == 14 && capteur[1] == 0 && millis() >= tempo + 2000)
{
etape = 16;
tempo = millis();
}
if (etape == 14 && capteur[2] == 1) {
etape = 13;
}
if (etape == 15 && capteur[2] == 1 && millis() >= tempo + 2000)
{
etape = 13;
tempo = millis();
}
// Etape 13 : 4 moteurs allumés
if (etape == 16 && capteur[2] == 1)
{
etape = 15;
tempo = millis();
}
int moteur_precedent[4];
for (int i = 0 ; i < 4 ; i++) {
moteur_precedent[i] = moteur[i];
}
moteur[0] = (etape == 10 || etape == 11 || etape == 12 || etape == 13 || etape == 14 || etape == 15 || etape == 16);
moteur[1] = (etape == 12 || etape == 13 || etape == 14 || etape == 15 || etape == 16);
moteur[2] = (etape == 14 || etape == 15 || etape == 16);
moteur[3] = (etape == 16);
for (int i = 0; i < 4; i++)
{
if (moteur[i] > moteur_precedent[i])
{
compteur[i] = compteur[i] + 1;
}
}
std::cout << compteur[0] << " " << compteur[1] << " "
<< compteur[2] << " " << compteur[3] << std::endl;
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];
}
int moteur_plusutilise() { int index = -1; int max = 0;
for (int i = 0 ; i < 4 ; i++) { if (compteur[i] > max) { max = compteur[i]; index = i; // Lequel est le maximum } }
return index; }
int moteur_moinsutilise() { int index = -1; int min = INT32_MAX;
for (int i = 0; i < 4; i++) { if (compteur[i] < min) { min = compteur[i]; index = i; // Lequel est le maximum } }
return index; }