#include <Adafruit_NeoPixel.h>
#define PIN 18 // La broche DIN
#define NUMPIXELS 64 // Ta matrice 8x8
#define PIN_BUTTON 8 // Le bouton pour déclencher
Adafruit_NeoPixel matrix(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
// Pour gérer le clignotement sans bloquer le reste du code
unsigned long previousMillis = 0;
const long interval = 500; // Clignote toutes les 500 millisecondes
bool ledState = false; // État actuel de la LED clignotante
void setup() {
matrix.begin(); // Initialise la matrice LED
matrix.setBrightness(80); // Pas trop fort pour les yeux
// Initialize the pin for reading the button.
pinMode(PIN_BUTTON, INPUT_PULLUP);
}
void loop() {
// digitalRead renvoie LOW quand on appuie (car relié au GND)
if (digitalRead(PIN_BUTTON) == LOW) {
// Animation quand on reste appuyé (Enregistrement...)
recordingIndicator();
} else {
// État de veille
showFace(matrix.Color(0, 255, 100)); // Vert pour "Prêt"
previousMillis = 0;
ledState = false;
}
}
void showFace(uint32_t color) {
matrix.clear();
// Dessine deux yeux simples
matrix.setPixelColor(18, color);
matrix.setPixelColor(21, color);
matrix.show();
}
const int recordingPixels[] = {19, 20, 26, 27, 28, 29, 34, 35, 36, 37, 43, 44};
const int recordingSize = sizeof(recordingPixels) / sizeof(recordingPixels[0]);
void recordingIndicator() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// Il est temps de changer l'état de la LED
previousMillis = currentMillis;
ledState = !ledState; // Inverse l'état (true/false)
matrix.clear();
if (ledState) {
for (int i = 0; i < recordingSize; i++) {
matrix.setPixelColor(recordingPixels[i], matrix.Color(255, 0, 0));
}
}
matrix.show();
}
}