Bonjour,
je suis débutant dans la programmation arduino. (je suis électricien et informaticien)
Mon projet est de mettre en lumiere une Montgolfier en métal (voir photo)
Il y aura donc un dichro led en 12volt dans le panier qui sera piloter par un relais et un ou deux ruban
Néopixel sur l'anneau en cuivre.
Un télérupteur alimente les alimentation du système.
Il y aura un bouton poussoir pour changer le mode d'éclairage.
J'ai un problème avec le changement de mode d'animation avec le bouton poussoir.
Je pense avoir identifier le problème mais je ne sais pas modifier le programme pour que ça fonctionne.
Quand on n'a des animation un peu complexe avec un delai je n'arrive pas à changer d'animation (ça bloque à "case 3".
Merci de votre aide
#include <Adafruit_NeoPixel.h>
#include <avr/power.h>
#define PIN 6 // Which pin on the Arduino is connected to the NeoPixels ; On a Trinket or Gemma we suggest changing this to 1
#define NUMPIXELS 60 // How many NeoPixels are attached to the Arduino?
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int relai = 3; // le relai active le signal de déclenchement - actif haut;
// PushButton Stat
boolean PushButtonStat = false;
// PushbuttonPin
const int PushbuttonPin = 7;
// Variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
int NumberOfMode = 9; // 7 + 2 mode OFF
long Mode1previousMillis = 0;
long Mode2previousMillis = 0;
long Mode3previousMillis = 0;
long PushButtonpreviousMillis = 0;
unsigned long currentMillis = 0;
long Mode1Interval = 50; // Timer (Delay) Mode 1
long Mode2Interval = 500; // Timer (Delay) Mode 2
long Mode3Interval = 50; // Timer (Delay) Mode 3
long Pushinterval = 750;
long blinkMillis = 300; // Blinker delay
// Color Set Mode 1
int R = 250;
int G = 250;
int B = 250;
// Color Set Mode 2
int R_2 = 0;
int G_2 = 0;
int B_2 = 50;
// Color Set Mode 3
int R_3 = 0;
int G_3 = 50;
int B_3 = 0;
// Color Set Mode 4
int R_4 = 250;
int G_4 = 0;
int B_4 = 250;
// Color Set Mode 5
int R_5 = 0;
int G_5 = 20;
int B_5 = 25;
// Color Set Mode 6
int R_6 = 25;
int G_6 = 20;
int B_6 = 0;
// Color Set Mode 7
int R_7 = 0;
int G_7 = 0;
int B_7 = 30;
// Color Set Mode 8
int R_8 = 0;
int G_8 = 0;
int B_8 = 30;
// **** Test ******************
long FirstcurrentMillis = 0;
long FirstpreviousMillis = 0;
long SeccurrentMillis = 0;
long SecpreviousMillis = 0;
long ThirdcurrentMillis = 0;
long ThirdpreviousMillis = 0;
int testvalue = 0;
int ledState = LOW;
int LedPos = 0;
int LedPos2 = 0;
boolean LedOff = false;
// ************Test***********
// Program Start //
void setup() {
pinMode (relai, OUTPUT); // Définir la broche "relai" comme étant une sortie;
pinMode(PushbuttonPin, INPUT_PULLUP); // initialize the button pin as a input:
Serial.begin(9600); // initialize serial communication:
pixels.begin(); // This initializes the NeoPixel library.
}
/* Définition des couleurs */
int RED[3] = {255, 0, 0}; // Couleur Rouge
int GREEN[3] = {0, 255, 0}; // Couleur Verte
int CYAN[3] = {0, 255, 255}; // Couleur Cyan
int YELLOW[3] = {255, 125, 0}; // Couleur Jaune
int ORANGE[3] = {255, 40, 0}; // Couleur Orange
int PURPLE[3] = {255, 0 , 255}; // Couleur Violette
int PINK[3] = {255, 0, 100}; // Couleur Rose
int BLUE[3] = {0, 0, 255}; // Couleur Bleu
int WHITE[3] = {255, 255, 255}; // Couleur Blanche
void loop() {
currentMillis = millis();
// Push Button Counter
if(currentMillis - PushButtonpreviousMillis > Pushinterval)
{
buttonState = digitalRead(PushbuttonPin);
// compare the buttonState to its previous state
if (buttonState != lastButtonState)
{
// if the state has changed, increment the counter
if (buttonState == HIGH)
{
// if the current state is HIGH then the button
// wend from off to on:
buttonPushCounter++;
Serial.println("on");
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter);
}
else
{
// if the current state is LOW then the button
// wend from on to off:
Serial.println("off");
}
}
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState;
if (buttonPushCounter == NumberOfMode)
{
buttonPushCounter = 0; // reset buttonPushCounter
}
} // Push Button Counter
//***************** Start Modes **********************//
switch (buttonPushCounter)
{
case 0:
digitalWrite (relai, LOW); // relai inactif
for (int i = 0; i<NUMPIXELS; i++)
{
pixels.setPixelColor(i, pixels.Color(0,0,B)); // All Leds OFF.
pixels.show(); // This sends the updated pixel color to the hardware.
}
break;
case 1:
for (int i = 0; i<NUMPIXELS; i++)
{
pixels.setPixelColor(i, pixels.Color(R,G,B));
pixels.show(); // This sends the updated pixel color to the hardware.
}
break;
case 2:
digitalWrite (relai, HIGH); // Le relai s'active
anim_fire();
break;
case 3:
SeccurrentMillis = millis();
if(SeccurrentMillis - SecpreviousMillis > 40)
{
theaterChaseRainbow(50);
}
if (LedPos > NUMPIXELS)
{
LedPos = 0;
}
break;
case 4:
SeccurrentMillis = millis();
if(SeccurrentMillis - SecpreviousMillis > 40)
{
SecpreviousMillis = SeccurrentMillis;
pixels.setPixelColor(LedPos, pixels.Color(R_6,G_6,B_6));
pixels.show(); // This sends the updated pixel color to the hardware.
pixels.setPixelColor(LedPos - 1 , pixels.Color(0,0,0)); // turn off previous led
pixels.show(); // This sends the updated pixel color to the hardware.
LedPos = LedPos + 1 ;
}
if (LedPos > NUMPIXELS)
{
LedPos = 0;
}
break;