Bonjour la communauté, je m'adresse a vous aujourd'hui car j'ai un petit ( gros ) problème j'ai un vu-ètre qui normalement es contrôler avec un arduino mais le soucis es que le code es fait pour 60 leds ws2812b mais moi j'en es 596 ce que es beaucoup trop pour le processeur de l'arduino ( même un méga ne fonctionne pas ) du coup j'ai demander a plusieurs personne et on ma dit de prendre un ESP32 mais le soucis es que le code n'est pas compatible donc je suis bloquer et n'aillant pas de grosse connaissance en codage je demande votre aide pour m'aider a adapter le code au ESP32. Je vous met le code ci-dessous. Je vous remercie d'avance et bonne journée à tous.
#include <Adafruit_NeoPixel.h>
#define BrocheEntreeAudioGauche A0
#define BrocheEntreeAudioDroite A1
#define BrochePotarLuminosite A2
#define BrochePotarSensibilite A3
#define BrocheStrip 6
#define BrocheBPEclairage 4
int nombreLEDStrip = 84;
uint32_t stripColor[43];
boolean displayMiddleLED = true;
unsigned long t1DebutTempoStopMiddleLED = 0;
boolean splitStrip = false;
int middleOffset = 1;
int startupAnimationDelay = 14;
int orangeLimitAmount = 0;
boolean swapLeftRight = false;
int dropDelay = 4;
float dropFactor = 0.92;
int peakTimeNoDropDelay = 250;
int peakTimeFirstDropDelay = 130;
int peakTimeDropDelay = 7;
float peakDropFactor = 0.93;
boolean droppingPeakFade = false;
int bouncingPeaksNumOfLEDs = 6;
int bouncingPeakDelay = 4;
int bouncingPeakCounterInc = 10;
int minValue = 10;
int maxValue = 350;
int sensitivityValue = 128;
int maxSensitivity = 2 * 255;
int LEDBrightness = 30;
int sensorDeviationBrightness = 1;
int overflowDelay = 20;
boolean displayPeaks = false;
boolean droppingPeak = true;
boolean bouncingPeaks = true;
int numOfSegments = nombreLEDStrip / 2;
int halfNumOfSegments = numOfSegments / 2;
int stripMiddle = nombreLEDStrip / 2;
int maxDisplaySegments = stripMiddle - 1;
float sensitivityFactor;
int brightnessValue;
int prevBrightnessValue;
float LEDFactor;
float LEDFactor_div_numOfSegments;
int leftValue = 0;
int rightValue = 0;
int leftAnalogValue = 0;
int rightAnalogValue = 0;
int prevLeftValue = 0;
int prevRightValue = 0;
int prevLeftAnalogValue = 0;
int prevRightAnalogValue = 0;
int i, j;
int leftDropTime;
int rightDropTime;
int leftPeak = 0;
int rightPeak = 0;
int leftPeakTime = 0;
int rightPeakTime = 0;
boolean leftFirstPeak = true;
boolean rightFirstPeak = true;
int readShowPeaksPin, prevReadShowPeaksPin;
uint32_t stripMiddleColor;
uint32_t stripOverflowColor;
uint32_t stripHoldColor;
boolean leftPeakBouncing = false;
boolean rightPeakBouncing = false;
int leftPeakBounce = 0;
int rightPeakBounce = 0;
int prevLeftPeakBounce = 0;
int prevRightPeakBounce = 0;
int leftPeakBounceCounter = 0;
int rightPeakBounceCounter = 0;
int leftPeakBounceDelayCounter = 0;
int rightPeakBounceDelayCounter = 0;
bool EtatBPEclairage = HIGH;
bool DernierEtatBPEclairage = HIGH;
int ModeAffichage = 0;
long CouleurRoueChromatique = 0;
int LEDTeinte = 0;
bool AffichageChroma = false;
int LuminositeCourante = 255;
int LuminositePotar = 0;
int DerniereLuminositePotar = 0;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(nombreLEDStrip, BrocheStrip, NEO_GRB + NEO_KHZ800);
void setup()
{
Serial.begin(9600);
pinMode(BrocheBPEclairage, INPUT_PULLUP);
strip.begin();
strip.setBrightness(LuminositeCourante);
strip.show();
setStripColors();
t1DebutTempoStopMiddleLED = millis();
}
void loop()
{
EtatBPEclairage = digitalRead(BrocheBPEclairage);
if (DernierEtatBPEclairage != EtatBPEclairage)
{
delay(25);
if (DernierEtatBPEclairage == HIGH && EtatBPEclairage == LOW)
{
ModeAffichage++;
if (ModeAffichage > 2) {
ModeAffichage = 0;
}
if (ModeAffichage == 0)
{
AffichageChroma = false;
LuminositeCourante = 255;
strip.clear();
strip.setBrightness(LuminositeCourante);
strip.show();
}
else if (ModeAffichage == 1)
{
AffichageChroma = true;
LuminositeCourante = 255;
strip.clear();
strip.setBrightness(LuminositeCourante);
strip.show();
}
else if (ModeAffichage == 2)
{
for (int ADRLED = 0; ADRLED < nombreLEDStrip; ADRLED++) {
strip.setPixelColor(ADRLED, 255, 255, 255);
}
strip.show();
}
DernierEtatBPEclairage = EtatBPEclairage;
}
else {
DernierEtatBPEclairage = HIGH;
}
}
if (ModeAffichage == 2)
{
LuminositePotar = analogRead(BrochePotarLuminosite);
LuminositePotar = map(LuminositePotar, 0, 1023, 0, 255);
if (abs(LuminositePotar - DerniereLuminositePotar) > 2)
{
LuminositeCourante = LuminositePotar;
strip.setBrightness(LuminositeCourante);
strip.show();
DerniereLuminositePotar = LuminositePotar;
}
return;
}
//**************************************************************************************************************************************************************************
readSensorValues();
readValues();
drawValues();
if (displayPeaks)
{
getPeaks();
drawPeaks();
}
storePrevValues();
//**************************************************************************************************************************************************************************
//**************************************************************************************************************************************************************************
}
//**************************************************************************************************************************************************************************
//*** Fonction de lecture des potentiomètres de luminosité et de sensibilité ***********************************************************************************************
//**************************************************************************************************************************************************************************
void readSensorValues ()
{
brightnessValue = analogRead(BrochePotarLuminosite);
brightnessValue = map(brightnessValue, 0, 1024, 0, 255);
if (abs(brightnessValue - prevBrightnessValue) > sensorDeviationBrightness)
{
LEDBrightness = brightnessValue;
setStripColors();
prevBrightnessValue = brightnessValue;
}
sensitivityValue = analogRead(BrochePotarSensibilite);
sensitivityValue = map(sensitivityValue, 0, 1024, 0, 255);
// sensitivityValue_div_numOfSegments = sensitivityValue / numOfSegments;
sensitivityFactor = ((float) sensitivityValue / 255 * (float) maxSensitivity / 255);
}
//**************************************************************************************************************************************************************************
//*** Fonction de lecture des entrées audio droite et gauche ***************************************************************************************************************
//**************************************************************************************************************************************************************************
void readValues ()
{
leftAnalogValue = analogRead(BrocheEntreeAudioGauche);
rightAnalogValue = analogRead(BrocheEntreeAudioDroite);
if (swapLeftRight)
{
int tempValue = leftAnalogValue;
leftAnalogValue = rightAnalogValue;
rightAnalogValue = tempValue;
}
if (leftAnalogValue < prevLeftAnalogValue)
{
leftDropTime++;
if (leftDropTime > dropDelay)
{
leftAnalogValue = prevLeftAnalogValue * dropFactor;
leftDropTime = 0;
}
else {
leftAnalogValue = prevLeftAnalogValue;
}
}
if (rightAnalogValue < prevRightAnalogValue)
{
rightDropTime++;
if (rightDropTime > dropDelay)
{
rightAnalogValue = prevRightAnalogValue * dropFactor;
rightDropTime = 0;
}
else {
rightAnalogValue = prevRightAnalogValue;
}
}
leftValue = map(leftAnalogValue * sensitivityFactor, minValue, maxValue, 0, maxDisplaySegments);
rightValue = map(rightAnalogValue * sensitivityFactor, minValue, maxValue, 0, maxDisplaySegments);
if (leftValue > maxDisplaySegments)
{
leftValue = maxDisplaySegments;
drawOverflow();
}
if (rightValue > maxDisplaySegments)
{
rightValue = maxDisplaySegments;
drawOverflow();
}
}
//**************************************************************************************************************************************************************************
//*** Fonction de mémorisation des dernières lectures audio droite et gauche ***********************************************************************************************
//**************************************************************************************************************************************************************************
void storePrevValues ()
{
prevLeftAnalogValue = leftAnalogValue;
prevRightAnalogValue = rightAnalogValue;
prevLeftValue = leftValue;
prevRightValue = rightValue;
}
//**************************************************************************************************************************************************************************
//*** Fonction de la gestion des Pics **************************************************************************************************************************************
//**************************************************************************************************************************************************************************
void getPeaks ()
{
if (leftValue > leftPeak)
{
leftPeak = leftValue;
leftPeakTime = 0;
leftFirstPeak = false;
if (bouncingPeaks)
{
leftPeakBouncing = true;
leftPeakBounceCounter = 0;
leftPeakBounceDelayCounter = 0;
}
}
else
{
leftPeakTime++;
if (droppingPeak)
{
if (leftFirstPeak)
{
if (leftPeakTime > peakTimeFirstDropDelay)
{
clearLeftPeak();
leftFirstPeak = false;
}
}
else
{
if (leftPeakTime > peakTimeDropDelay) {
clearLeftPeak();
}
}
}
else
{
if (leftPeakTime > peakTimeNoDropDelay) {
clearLeftPeak();
}
}
}
if (leftPeakBouncing)
{
if (leftFirstPeak)
{
leftPeakBounceDelayCounter++;
if (leftPeakBounceDelayCounter >= bouncingPeakDelay)
{
leftPeakBounceDelayCounter = 0;
leftPeakBounceCounter += bouncingPeakCounterInc;
if (leftPeakBounceCounter >= 180)
{
clearLeftBouncePeak();
clearLeftBounce();
}
else
{
leftPeakBounce = min((sin(leftPeakBounceCounter * 0.0174532925) * bouncingPeaksNumOfLEDs), (maxDisplaySegments - leftPeak));
if (leftPeakBounce != prevLeftPeakBounce) {
clearLeftBouncePeak();
}
prevLeftPeakBounce = leftPeakBounce;
}
}
}
}
if (rightValue > rightPeak)
{
rightPeak = rightValue;
rightPeakTime = 0;
rightFirstPeak = false;
if (bouncingPeaks)
{
rightPeakBouncing = true;
rightPeakBounceCounter = 0;
rightPeakBounceDelayCounter = 0;
}
}
else
{
rightPeakTime++;
if (droppingPeak)
{
if (rightFirstPeak)
{
if (rightPeakTime > peakTimeFirstDropDelay)
{
clearRightPeak();
rightFirstPeak = false;
}
}
else
{
if (rightPeakTime > peakTimeDropDelay) {
clearRightPeak();
}
}
}
else
{
if (rightPeakTime > peakTimeNoDropDelay) {
clearRightPeak();
}
}
}
if (rightPeakBouncing)
{
if (rightFirstPeak)
{
rightPeakBounceDelayCounter++;
if (rightPeakBounceDelayCounter >= bouncingPeakDelay)
{
rightPeakBounceDelayCounter = 0;
rightPeakBounceCounter += bouncingPeakCounterInc;
if (rightPeakBounceCounter >= 180)
{
clearRightBouncePeak();
clearRightBounce();
}
else
{
rightPeakBounce = min((sin(rightPeakBounceCounter * 0.0174532925) * bouncingPeaksNumOfLEDs), (maxDisplaySegments - rightPeak));
if (rightPeakBounce != prevRightPeakBounce) {
clearRightBouncePeak();
}
prevRightPeakBounce = rightPeakBounce;
}
}
}
}
}
//**************************************************************************************************************************************************************************
//*** Fonction d'affichage des LED *****************************************************************************************************************************************
//**************************************************************************************************************************************************************************
void drawValues ()
{
if (splitStrip)
{
for (i = middleOffset; i < leftValue; i++) {
strip.setPixelColor(i, stripColor[i]);
}
for (i = prevLeftValue; i > leftValue; i--) {
strip.setPixelColor(i, 0);
}
for (i = middleOffset; i < rightValue; i++) {
strip.setPixelColor(stripMiddle + i, stripColor[i]);
}
for (i = prevRightValue; i > rightValue; i--) {
strip.setPixelColor(stripMiddle + i, 0);
}
if (rightValue != 0 && leftValue != 0) {
t1DebutTempoStopMiddleLED = millis();
}
}
else
{
if (AffichageChroma)
{
for (i = middleOffset; i < leftValue; i++)
{
LEDTeinte = CouleurRoueChromatique + (i * 65536L / strip.numPixels());
strip.setPixelColor(stripMiddle + i, strip.gamma32(strip.ColorHSV(LEDTeinte, 255, LEDBrightness)));
}
for (i = middleOffset; i < rightValue; i++)
{
LEDTeinte = CouleurRoueChromatique + (i * 65536L / strip.numPixels());
strip.setPixelColor(stripMiddle - i, strip.gamma32(strip.ColorHSV(LEDTeinte, 255, LEDBrightness)));
}
CouleurRoueChromatique = CouleurRoueChromatique + 256;
if (CouleurRoueChromatique > 65535) {
CouleurRoueChromatique = 0;
LEDTeinte = 0;
}
}
else
{
for (i = middleOffset; i < leftValue; i++) {
strip.setPixelColor(stripMiddle + i, stripColor[i]);
}
for (i = middleOffset; i < rightValue; i++) {
strip.setPixelColor(stripMiddle - i, stripColor[i]);
}
}
for (i = prevLeftValue; i > leftValue; i--) {
strip.setPixelColor(stripMiddle + i, 0);
}
for (i = prevRightValue; i > rightValue; i--) {
strip.setPixelColor(stripMiddle - i, 0);
}
if (rightValue != 0 && leftValue != 0) {
t1DebutTempoStopMiddleLED = millis();
}
}
if (displayMiddleLED)
{
if (millis() - t1DebutTempoStopMiddleLED <= 5000 && t1DebutTempoStopMiddleLED != 0)
{
strip.setPixelColor(stripMiddle, stripMiddleColor);
}
else if (millis() - t1DebutTempoStopMiddleLED > 5000 && t1DebutTempoStopMiddleLED != 0)
{
strip.setPixelColor(stripMiddle, 0);
t1DebutTempoStopMiddleLED = 0;
}
}
strip.show();
}
//**************************************************************************************************************************************************************************
//*** Fonction d'affichage des Pics ****************************************************************************************************************************************
//**************************************************************************************************************************************************************************
void drawPeaks ()
{
if (leftPeak > 0)
{
if (droppingPeakFade && leftPeakBouncing == false) {
stripHoldColor = strip.Color(max(1, (255 * leftPeak * LEDFactor_div_numOfSegments)), 0, 0);
}
else {
stripHoldColor = stripColor[numOfSegments];
}
if (splitStrip) {
strip.setPixelColor((leftPeak + leftPeakBounce), stripHoldColor);
}
else {
strip.setPixelColor(stripMiddle + (leftPeak + leftPeakBounce), stripHoldColor);
}
}
if (rightPeak > 0)
{
if (droppingPeakFade && rightPeakBouncing == false) {
stripHoldColor = strip.Color(max(1, (255 * rightPeak * LEDFactor_div_numOfSegments)), 0, 0);
}
else {
stripHoldColor = stripColor[numOfSegments];
}
if (splitStrip) {
strip.setPixelColor(stripMiddle + rightPeak + prevRightPeakBounce, stripHoldColor);
}
else {
strip.setPixelColor(stripMiddle - (rightPeak + prevRightPeakBounce), stripHoldColor);
}
}
if (leftPeak > 0 || rightPeak > 0) {
strip.show();
}
}
//**************************************************************************************************************************************************************************
//*** Fonction d'effacement du Pic gauche **********************************************************************************************************************************
//**************************************************************************************************************************************************************************
void clearLeftPeak ()
{
if (splitStrip) {
strip.setPixelColor((leftPeak + prevLeftPeakBounce), 0);
}
else {
strip.setPixelColor(stripMiddle + (leftPeak + prevLeftPeakBounce), 0);
}
if (droppingPeak) {
leftPeak = leftPeak * peakDropFactor;
}
else {
leftPeak = 0;
}
leftPeakTime = 0;
}
void clearLeftBounce()
{
leftPeakBouncing = false;
leftPeakBounceCounter = 0;
leftPeakBounce = 0;
prevLeftPeakBounce = 0;
}
void clearLeftBouncePeak()
{
if (splitStrip) {
strip.setPixelColor((leftPeak + prevLeftPeakBounce), 0);
}
else {
strip.setPixelColor(stripMiddle + (leftPeak + prevLeftPeakBounce), 0);
}
}
//**************************************************************************************************************************************************************************
//*** Fonction d'effacement du Pic droit ***********************************************************************************************************************************
//**************************************************************************************************************************************************************************
void clearRightPeak ()
{
if (splitStrip) {
strip.setPixelColor(stripMiddle + rightPeak + prevRightPeakBounce, 0);
}
else {
strip.setPixelColor(stripMiddle - (rightPeak + prevRightPeakBounce), 0);
}
if (droppingPeak) {
rightPeak = rightPeak * peakDropFactor;
}
else {
rightPeak = 0;
}
rightPeakTime = 0;
}
void clearRightBounce ()
{
rightPeakBouncing = false;
rightPeakBounceCounter = 0;
rightPeakBounce = 0;
prevRightPeakBounce = 0;
}
void clearRightBouncePeak ()
{
if (splitStrip) {
strip.setPixelColor((stripMiddle + rightPeak + prevRightPeakBounce), 0);
}
else {
strip.setPixelColor(stripMiddle - (rightPeak + prevRightPeakBounce), 0);
}
}
//**************************************************************************************************************************************************************************
//*** Fonction d'affichage en cas de dépassement ***************************************************************************************************************************
//**************************************************************************************************************************************************************************
void drawOverflow ()
{
for (i = 0; i <= numOfSegments; i++)
{
strip.setPixelColor(stripMiddle + i, stripOverflowColor);
strip.setPixelColor(stripMiddle - i, stripOverflowColor);
}
strip.show();
delay(overflowDelay);
for (i = 0; i <= numOfSegments; i++)
{
strip.setPixelColor(stripMiddle + i, 0);
strip.setPixelColor(stripMiddle - i, 0);
}
strip.show();
}
//**************************************************************************************************************************************************************************
//*** Fonction pour définir la couleur d'affichage des LED *****************************************************************************************************************
//**************************************************************************************************************************************************************************
void setStripColors ()
{
int orangeLimit;
LEDFactor = (float)LEDBrightness / 255;
float orangeFactor = orangeLimitAmount / halfNumOfSegments;
LEDFactor_div_numOfSegments = LEDFactor / numOfSegments;
stripOverflowColor = strip.Color(min(255, 255 * LEDFactor * 1.5), 0, 0);
stripMiddleColor = strip.Color(0, 0, 255 * LEDFactor);
stripColor[0] = strip.Color(0, 255 * LEDFactor, 0);
for (i = 1; i <= numOfSegments; i++)
{
if (i <= halfNumOfSegments) {
orangeLimit = (i * orangeFactor);
}
else {
orangeLimit = ((numOfSegments - i) * orangeFactor);
}
stripColor[i] = strip.Color((255 * i * LEDFactor_div_numOfSegments), ((255 - orangeLimit) * (numOfSegments - i) * LEDFactor_div_numOfSegments), 0);
}
stripHoldColor = stripColor[numOfSegments];
}