Bonjour,
je me tourne vers vous pour un petit problème que je ne parvient pas a résoudre.
projet simple : 1 ruban a leds, 3 boutons a bascule, 3 effets.
bouton1 : le ruban reste allumer.
bouton2 : un effet rainbow cycle mais que en rouge.
bouton3 : un effet theaterChase également en rouge.
pour les effets pas de soucie même si ma version du code dois vous piquer les yeux. Mon problème est au niveau des boutons.
J'essaie d avoir sur chaque bouton deux positions, off et mise en route de son effet a l infinie jusqu’à remise en position off mais voila, si pour le off in y a pas de problème.
C'est lors de la mise en route de l'effet voulue, celui si s'active bien mais que pendant un laps de temps cours.
bouton1 : le ruban clignote rapidement 1 fois toutr les 8 sec.
bouton2 : le rainbow rouge, ne fois qu'un voyage et ne va pas jusqu’au bout s'arrête 3 sec puis reprends.
bouton3 : le theaterChase se fais pendant 5 sec et s'arrête 4 sec et reprends.
je effectuer des recherche mais s'en succès.
voici mon code... :
#include <Adafruit_NeoPixel.h>
#define PinLed 6
#define NumLed 10
int const Btn_BasculeA = 3;
int const Btn_BasculeB = 4;
int const Btn_BasculeC = 5;
int boutonStateA = 0;
int boutonStateB = 0;
int boutonStateC = 0;
Adafruit_NeoPixel strip(NumLed, PinLed, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.show();
pinMode(Btn_BasculeA, INPUT_PULLUP);
pinMode(Btn_BasculeB, INPUT_PULLUP);
pinMode(Btn_BasculeC, INPUT_PULLUP);
}
void loop() {
boutonStateA = digitalRead(Btn_BasculeA);
if (boutonStateA == LOW) {
allumLed(strip.Color(255, 0, 0), 1);
}
else {
allumLed(strip.Color(0, 0, 0), 1);
}
boutonStateB = digitalRead(Btn_BasculeB);
if (boutonStateB == LOW) {
rougeCycle(20);
}
else {
rougeCycleOff(20);
}
boutonStateC = digitalRead(Btn_BasculeC);
if (boutonStateC == LOW) {
rougeClignot(strip.Color(255, 0, 0), 100);
}
else {
rougeClignot(strip.Color(0, 0, 0), 100);
}
}
void allumLed(uint32_t color, int wait) {
for (int i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, color);
strip.show();
}
}
void rougeCycle(uint8_t wait) {
uint16_t i, j;
for (j = 0; j < 256; j++) {
for (i = strip.numPixels(); i > 0 ; i--) {
strip.setPixelColor(i, Wheel((i * 1 - j) & 255));
}
strip.show();
delay(wait);
}
}
uint32_t Wheel(byte WheelPos) {
if (WheelPos < 85) {
return strip.Color(WheelPos * 3, 0, 0);
}
else if (WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, 0);
}
else {
WheelPos -= 170;
return strip.Color(0, 0, 0);
}
}
void rougeCycleOff(uint8_t wait) {
uint16_t i, j;
for (j = 0; j < 256; j++) {
for (i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel2((i * 1 + j) & 255));
}
strip.show();
delay(wait);
}
}
uint32_t Wheel2(byte WheelPos) {
if (WheelPos < 0) {
return strip.Color(0, 0, 0);
}
else if (WheelPos < 0) {
WheelPos -= 0;
return strip.Color(0, 0, 0);
}
else {
WheelPos -= 0;
return strip.Color(0, 0, 0);
}
}
void rougeClignot(uint32_t color, int wait) {
for (int a = 0; a < 10; a++) { // Repeat 10 times...
for (int b = 0; b < 3; b++) { // 'b' counts from 0 to 2...
strip.clear(); // Set all pixels in RAM to 0 (off)
// 'c' counts up from 'b' to end of strip in steps of 3...
for (int c = b; c < strip.numPixels(); c += 3) {
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
}
strip.show();
delay(wait);
}
}
}
mon montage :
je tiens a préciser que je suis noob dans le domain
D'avance merci de tous aide que vous m’apporterez et par c'est temps.... compliquer prenez soin de vous et votre entourage.

