J"ai fini par avancer : ça marche chez moi sauf pour les boutons que je n'ai pas connectés. Donc s'il y a encore un problème, ça vient des boutons. Notamment, je n'ai pas géré les rebonds. Si on veut être précis, il ne faut pas utiliser un delay (je vais me renseigner sur e point) et faire plutôt une gestion matérielle. Là je ne suis pas très au courant, il faudra demander sur le forum.
Voici le code :
#include "FastLED.h"
#define NUM_LEDS 114 // Number of LED controls (remember I have 3 leds / controler
#define COLOR_ORDER BRG // Define color order for your strip
#define DATA_PIN 6 // Data pin for led comunication
#define BP_START 7 // Pin bouton Start
#define BP_STOP 8 // Pin bouton Stop
#define BP_RESET 9 // Pin bouton Reset
#define INTER 10 // Pin inter 15 / 45
CRGB leds[NUM_LEDS]; // Define LEDs strip
byte digits[10][28] = {
{0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, //0
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0}, //1
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0}, //2
{1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0}, //3
{1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1}, //4
{1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1}, //5
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1}, //6
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0}, //7
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, //8
{1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, //9 | 2D Array for numbers on 7 segment
};
bool Dot = true; //Dot state
int ledColor = 0x0000FF; // Color used (in hex)
int Heure = 0;
bool EtatChrono = false; // Chrono arrêté
int HeureMax = 4500;
unsigned long dernierTempsChrono;
void setup() {
Serial.begin(115200);
LEDS.addLeds<WS2811, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS); // Set LED strip type
LEDS.setBrightness(255); // Set initial brightness
pinMode(BP_START, INPUT_PULLUP); // bouton START
pinMode(BP_STOP, INPUT_PULLUP); // bouton STOP
pinMode(BP_RESET, INPUT_PULLUP); // bouton RESET
pinMode(INTER, INPUT_PULLUP); // inter 15 / 45
TimeToArray();
FastLED.show();
dernierTempsChrono = millis();
}
// Check Light sensor and set brightness accordingly
void BrightnessCheck() {
const byte sensorPin = 3; // light sensor pin
const byte brightnessLow = 5; // Low brightness value
const byte brightnessHigh = 255; // High brightness value
int sensorValue = digitalRead(sensorPin); // Read sensor
if (sensorValue == 0) {
LEDS.setBrightness(brightnessHigh);
}
else {
LEDS.setBrightness(brightnessLow);
}
}
// Convert time to array needet for display
void TimeToArray() {
int cursor = 0;
int Secondes = Heure % 100;
int Now = Heure;
Dot = true;
if (Secondes % 2 == 1) Dot = false;
if (Dot) {
leds[56] = ledColor;
leds[57] = ledColor;
}
else {
leds[56] = 0x000000;
leds[57] = 0x000000;
}
for (int i = 1; i < 5; i++) {
int digit = Now % 10; // get last digit in time
cursor = (i - 1) * 28;
if (i > 2) cursor += 2;
Serial.print (" "); Serial.print(digit);
for (int k = 0; k < 28; k++) {
leds[cursor + k] = ledColor * digits[digit][k];
}
Now /= 10;
}
Serial.println();
}
void MiseAJour()
{
Heure += 1;
if (Heure % 100 == 60) Heure = Heure + 40;
Serial.print("Heure = "); Serial.print(Heure); Serial.print (" :");
}
void LectureBoutons()
{
if (digitalRead(BP_START)) StartChrono ();
if (digitalRead(BP_STOP)) StopChrono ();
if (digitalRead(BP_RESET)) ResetChrono ();
HeureMax = 4500;
if (digitalRead(INTER)) HeureMax = 1500;
}
void loop() // Main loop
{
LectureBoutons();
if (EtatChrono)
{
if (millis() - dernierTempsChrono >= 1000)
{
MiseAJour();
TimeToArray();
dernierTempsChrono += 1000;
FastLED.show(); // Display leds array
}
}
if (Heure >= HeureMax) EtatChrono = false;
}
void StartChrono () {
EtatChrono = true;
dernierTempsChrono = millis();
}
void StopChrono () {
EtatChrono = false;
}
void ResetChrono () {
EtatChrono = false;
Heure = 0;
}
Il faut que tu règles la console à 115200 (tout en bas, liste déroulante). Le code attend que tu appuies sur le bouton Start pour lancer le chrono. Bouton stop pour l'arrêter et start pour le relancer. Reset remet à 0 et attend start pour lancer le chrono.
Enfin, l'interrupteur permet de choisir entre 15 et 45 minutes.
Dis-moi si ça marche ...
A+