Bonjour,
Mon fils s'entraîne seul en roller de vitesse. En me basant sur plusieurs projets, j'ai réussi à créer un chrono seconde - centième (ss:dc) qui affiche chaque tour le temps réalisé sur des afficheurs MAX72 (2 lignes de 8 modules) grâce à la bibliothèque PAROLA (GitHub - MajicDesigns/MD_Parola: Library for modular scrolling LED matrix text displays).
Il souhaite maintenant s'en servir pour afficher le temps quand il fait du fond.
Je cherche à compléter le code pour que le comptage passe en minute-seconde à partir d'une minute (mm:ss).
Malgré quelques essais, je n'y arrive pas.
Auriez-vous une idée, une piste à me conseiller ?
Le code n'est pas très propre. Je suis vraiment un amateur.
Merci.
saisissez ou collez du code ici
// Header file includes
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include "Font_Data.h"
// Define the number of devices we have in the chain and the hardware interface
// NOTE: These pin numbers will probably not work with your hardware and may
// need to be adapted
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_CLK_ZONES 2
#define ZONE_SIZE 4
#define MAX_DEVICES (MAX_CLK_ZONES * ZONE_SIZE)
#define ZONE_UPPER 1
#define ZONE_LOWER 0
#define CLK_PIN D5
#define DATA_PIN D7
#define CS_PIN D1
// Hardware SPI connection
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// Arbitrary output pins
// MD_Parola P = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
#define SPEED_TIME 75
#define PAUSE_TIME 0
#define MAX_MESG 6
unsigned long Tps0;
unsigned long TpsB;
unsigned long TAA;
unsigned long tpsaffichage;
// Hardware adaptation parameters for scrolling
bool invertUpperZone = false;
// Turn on debug statements to the serial output
#define DEBUG 0
// Global variables
char szTimeL[MAX_MESG]; // ss:cc\0
char szTimeH[MAX_MESG];
void getTime(char *psz, bool f = true)
// Code for reading clock time
// Simulated clock runs 1 minute every seond
{
uint16_t s, c;
c = TAA/10;
s = (c/100) % 60;
c %= 60;
sprintf(psz, "%02d%c%02d", s, (f ? ':' : ' '), c);
}
void createHString(char *pH, char *pL)
{
for (; *pL != '\0'; pL++)
*pH++ = *pL | 0x80; // offset character
*pH = '\0'; // terminate the string
}
void setup(void)
{Tps0 = 0;
TAA = 0;
tpsaffichage = 4000;
pinMode(D3, INPUT);
invertUpperZone = (HARDWARE_TYPE == MD_MAX72XX::GENERIC_HW || HARDWARE_TYPE == MD_MAX72XX::PAROLA_HW);
// initialise the LED display
P.begin(MAX_CLK_ZONES);
// Set up zones for 2 halves of the display
P.setZone(ZONE_LOWER, 0, ZONE_SIZE - 1);
P.setZone(ZONE_UPPER, ZONE_SIZE, MAX_DEVICES - 1);
P.setFont(numeric7SegDouble);
P.setCharSpacing(P.getCharSpacing() * 2); // double height --> double spacing
if (invertUpperZone)
{
P.setZoneEffect(ZONE_UPPER, true, PA_FLIP_UD);
P.setZoneEffect(ZONE_UPPER, true, PA_FLIP_LR);
P.displayZoneText(ZONE_LOWER, szTimeL, PA_RIGHT, SPEED_TIME, PAUSE_TIME, PA_PRINT, PA_NO_EFFECT);
P.displayZoneText(ZONE_UPPER, szTimeH, PA_LEFT, SPEED_TIME, PAUSE_TIME, PA_PRINT, PA_NO_EFFECT);
}
else
{
P.displayZoneText(ZONE_LOWER, szTimeL, PA_CENTER, SPEED_TIME, PAUSE_TIME, PA_PRINT, PA_NO_EFFECT);
P.displayZoneText(ZONE_UPPER, szTimeH, PA_CENTER, SPEED_TIME, PAUSE_TIME, PA_PRINT, PA_NO_EFFECT);
}
}
void loop(void)
{
while ((digitalRead(D3) == 1)){
TAA = ((millis()) - Tps0);
{
static uint32_t lastTime = 0; // millis() memory
static bool flasher = false; // seconds passing flasher
P.displayAnimate();
if (P.getZoneStatus(ZONE_LOWER) && P.getZoneStatus(ZONE_UPPER))
{
// Adjust the time string if we have to. It will be adjusted
// every second at least for the flashing colon separator.
if (millis() - lastTime >= 100)
{
lastTime = millis();
getTime(szTimeL, flasher);
createHString(szTimeH, szTimeL);
flasher = !flasher;
P.displayReset();
// synchronise the start
P.synchZoneStart();
}
}
}
delay(10);
}
TAA = (millis()) - Tps0;
Tps0 = (millis());
{
static uint32_t lastTime = 0; // millis() memory
static bool flasher = false; // seconds passing flasher
P.displayAnimate();
if (P.getZoneStatus(ZONE_LOWER) && P.getZoneStatus(ZONE_UPPER))
{
// Adjust the time string if we have to. It will be adjusted
// every second at least for the flashing colon separator.
if (millis() - lastTime >= 100)
{
lastTime = millis();
getTime(szTimeL, flasher);
createHString(szTimeH, szTimeL);
flasher = !flasher;
P.displayReset();
// synchronise the start
P.synchZoneStart();
}
}
}
delay(tpsaffichage)
}