Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //================================================================================================================================================================
- // COMMUTATION ANIMATION 16 possibiliés fonction des 4entrées numériques
- // FONCTIONNEMENT actuellement sur strip 144 LEDS sur Arduino NANO
- // Il s'agit d'une plaquette générique et donc nous avons libre choix de placer pour chaque fonction sélectionnée en fonction des 4 entrées et de la table de
- // vérité le code d'animation souhaité.
- // Plaquette_NANO_generique_Neopixels01
- //
- // Selon le mot binaire de 4 bits présenté sur les entrées E11 - E2 - E3 - E4, (du poids le plus fort au poids le plus faible, le code sélectionne sélectionne
- // l'animation à présenter sur la broche 6 de la UNO.
- // Certaines combinaisons du mot binaire ne sont pas utilisées
- // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- // Actuellement il subisiste un problèéme : lors de la modification du mot , il est parfois difficile de sortir de l'animation en cours
- // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- //
- // DUFOURMONT Le 13/12/2020
- // claude.dufourmont@laposte.net
- // YouTube Channel : https://www.youtube.com/channel/UCvr9eb05lJow6N7m3SKqvNw
- //================================================================================================================================================================
- //====================================================================================
- //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- // 300 LEDs au MAXIMUN >
- //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- //====================================================================================
- #include <Adafruit_NeoPixel.h>
- #define PIN 6
- #define E1 11
- #define E2 2
- #define E3 3
- #define E4 4
- #define NUM_LEDS 144
- #define FirstLed 70 // Rang de la première LED (pour éclairer les détecteurs de décollage)
- #define N 4 // Nombre de LEDS à allumer également pour le décollage
- bool etatE1 = LOW;
- bool etatE2 = LOW;
- bool etatE3 = LOW;
- bool etatE4 = LOW;
- byte colors[3][3] = { {0xff, 0,0},
- {0xff, 0xff, 0xff},
- {0 , 0 , 0xff} };
- // RunningLights(0xff,0,0, 50); // red
- // RunningLights(0xff,0xff,0xff, 50); // white
- //RunningLights(0,0,0xff, 50); // blue
- Adafruit_NeoPixel strip(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
- void setup()
- {
- //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- // Les pinMode ne sont pas déclarés car sur l'ATtiny85 c'est INPUT d'office >
- //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- // FONCTIONNEMENT CORRECT : IF ELSE TABLE VERITE >
- //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- strip.begin();
- strip.clear();
- strip.setBrightness(50);
- strip.show();
- }
- void loop ()
- {
- digitalRead (E1);
- digitalRead (E2);
- digitalRead (E3);
- digitalRead (E4);
- //========================================================================DETERMINATION DES ETATS LOGIQUE -----DEBUT-----===============================================================
- if ( digitalRead (E1) == HIGH)
- {
- etatE1 = HIGH;
- }
- else
- {
- etatE1 = LOW;
- }
- if ( digitalRead (E2) == HIGH)
- {
- etatE2 = HIGH;
- }
- else
- {
- etatE2 = LOW;
- }
- if ( digitalRead (E3) == HIGH)
- {
- etatE3 = HIGH;
- }
- else
- {
- etatE3 = LOW;
- }
- if ( digitalRead (E4) == HIGH)
- {
- etatE4 = HIGH;
- }
- else
- {
- etatE4 = LOW;
- }
- //========================================================================DETERMINATION DES ETATS LOGIQUE -----FIN-----===============================================================
- //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- //============================================================TABLE DE VERITE ET SELECTION DES ANIMATIONS-----DEBUT-----===============================================================
- if (etatE1 == LOW && etatE2 == LOW && etatE3 == LOW && etatE4 == LOW)
- {
- //AT4.00================================================================================>NON UTILISE
- strip.begin();
- strip.clear();
- strip.setBrightness(50);
- strip.show();
- }
- else if (etatE1 == LOW && etatE2 == LOW && etatE3 == LOW && etatE4 == HIGH)
- {
- //AT4.01================================================================================>NON UTILISE
- strip.begin();
- strip.clear();
- strip.setBrightness(50);
- strip.show();
- }
- else if (etatE1 == LOW && etatE2 == LOW && etatE3 == HIGH && etatE4 == LOW)
- {
- //AT4.02================================================================================>NON UTILISE
- strip.begin();
- strip.clear();
- strip.setBrightness(50);
- strip.show();
- }
- else if (etatE1 == LOW && etatE2 == LOW && etatE3 == HIGH && etatE4 == HIGH)
- {
- //AT4.003================================================================================>NON UTILISE
- strip.begin();
- strip.clear();
- strip.setBrightness(50);
- strip.show();
- }
- else if (etatE1 == LOW && etatE2 == HIGH && etatE3 == LOW && etatE4 == LOW)
- {
- //AT4.004=================================================================================> ECONOMIE ENERGIE
- strip.begin();
- strip.clear();
- strip.setBrightness(50);
- strip.show();
- }
- else if (etatE1 == LOW && etatE2 == HIGH && etatE3 == LOW && etatE4 == HIGH)
- {
- //AT4.005=================================================================================>RainbowCycleONE_NANO01
- strip.begin();
- strip.clear();
- strip.setBrightness(50);
- strip.show();
- rainbowCycle(20);
- }
- else if (etatE1 == LOW && etatE2 == HIGH && etatE3 == HIGH && etatE4 == LOW)
- {
- //AT4.006================================================================================>RandowColorTwinkleTWO_NANO01
- strip.begin();
- strip.clear();
- strip.setBrightness(50);
- strip.show();
- TwinkleRandom(20, 100, false);
- }
- else if (etatE1 == LOW && etatE2 == HIGH && etatE3 == HIGH && etatE4 == HIGH)
- {
- //AT4.007================================================================================>TheaterChaseRainbowONE_NANO01
- strip.begin();
- strip.clear();
- strip.setBrightness(50);
- strip.show();
- theaterChaseRainbow(50);
- }
- else if (etatE1 == HIGH && etatE2 == LOW && etatE3 == LOW && etatE4 == LOW)
- {
- //AT4.008================================================================================>Decollage3LEDS_ONE_NANO01
- strip.begin();
- strip.clear();
- strip.setBrightness(255);
- strip.show();
- for(int i=FirstLed; i<FirstLed+N; i++) //
- {
- strip.setPixelColor(i, 255, 255, 255);
- strip.show();
- }
- }
- else if (etatE1 == HIGH && etatE2 == LOW && etatE3 == LOW && etatE4 == HIGH)
- {
- //AT4.009================================================================================>NON UTILISE
- strip.begin();
- strip.clear();
- strip.setBrightness(50);
- strip.show();
- }
- else if (etatE1 ==HIGH && etatE2 == LOW && etatE3 == HIGH && etatE4 == LOW)
- {
- //AT4.010================================================================================>NON UTILISE
- strip.begin();
- strip.clear();
- strip.setBrightness(50);
- strip.show();
- }
- else if (etatE1 == HIGH && etatE2 == LOW && etatE3 == HIGH && etatE4 == HIGH)
- {
- //AT4.011================================================================================>NON UTILISE
- strip.begin();
- strip.clear();
- strip.setBrightness(50);
- strip.show();
- }
- else if (etatE1 == HIGH && etatE2 == HIGH && etatE3 == LOW && etatE4 == LOW)
- {
- //AT4.012================================================================================>ColorWipeONE_NANO01
- strip.begin();
- strip.clear();
- strip.setBrightness(50);
- strip.show();
- colorWipe(255,0,0, 255);
- colorWipe(0,0,255, 255);
- colorWipe(0,255,0, 255);
- colorWipe(255,100,40, 255);
- colorWipe(0,100,40, 255);
- colorWipe(255,255,0, 255);
- }
- else if (etatE1 == HIGH && etatE2 == HIGH && etatE3 == LOW && etatE4 == HIGH)
- {
- //AT4.013================================================================================>StrobeONE_NANO02
- strip.begin();
- strip.clear();
- strip.setBrightness(50);
- strip.show();
- Strobe(0xff, 0xff, 0xff, 10, 50, 50); // dernier ypique 1000
- }
- else if (etatE1 == HIGH && etatE2 == HIGH && etatE3 == HIGH && etatE4 == LOW)
- {
- //AT4.014================================================================================>MeteorRainONE_NANO01
- strip.begin();
- strip.clear();
- strip.setBrightness(50);
- strip.show();
- meteorRain(0xff,0xff,0xff,5, 60, false, 0);
- }
- else if (etatE1 == HIGH && etatE2 == HIGH && etatE3 == HIGH && etatE4 == HIGH)
- {
- //AT4.015================================================================================>NON UTILISE
- strip.begin();
- strip.clear();
- strip.setBrightness(50);
- strip.show();
- }
- }
- //============================================================TABLE DE VERITE ET SELECTION DES ANIMATIONS-----FIN-----===============================================================
- //*****************************************************************************************************************************************
- void showStrip() {
- #ifdef ADAFRUIT_NEOPIXEL_H
- strip.show();
- #endif
- #ifndef ADAFRUIT_NEOPIXEL_H
- #endif
- }
- void setPixel(int Pixel, byte red, byte green, byte blue) {
- #ifdef ADAFRUIT_NEOPIXEL_H
- strip.setPixelColor(Pixel, strip.Color(red, green, blue));
- #endif
- #ifndef ADAFRUIT_NEOPIXEL_H
- #endif
- }
- void setAll(byte red, byte green, byte blue) {
- for(int i = 0; i < NUM_LEDS; i++ ) {
- setPixel(i, red, green, blue);
- }
- showStrip();
- }
- //============
- void rainbowCycle(int SpeedDelay)
- {
- byte *c;
- uint16_t i, j;
- for(j=0; j<256*5; j++) // 5 cycles of all colors on wheel
- {
- for(i=0; i< NUM_LEDS; i++) {
- c=Wheel(((i * 256 / NUM_LEDS) + j) & 255);
- setPixel(i, *c, *(c+1), *(c+2));
- }
- showStrip();
- delay(SpeedDelay);
- }
- }
- byte * Wheel(byte WheelPos) {
- static byte c[3];
- if(WheelPos < 85)
- {
- c[0]=WheelPos * 3;
- c[1]=255 - WheelPos * 3;
- c[2]=0;
- } else if(WheelPos < 170)
- {
- WheelPos -= 85;
- c[0]=255 - WheelPos * 3;
- c[1]=0;
- c[2]=WheelPos * 3;
- } else {
- WheelPos -= 170;
- c[0]=0;
- c[1]=WheelPos * 3;
- c[2]=255 - WheelPos * 3;
- }
- return c;
- }
- //===========
- void TwinkleRandom(int Count, int SpeedDelay, boolean OnlyOne)
- {
- setAll(0,0,0);
- for (int i=0; i<Count; i++)
- {
- setPixel(random(NUM_LEDS),random(0,255),random(0,255),random(0,255));
- showStrip();
- delay(SpeedDelay);
- if(OnlyOne) {
- setAll(0,0,0);
- }
- }
- delay(SpeedDelay);
- }
- //=============
- void theaterChaseRainbow(int SpeedDelay)
- {
- byte *c;
- for (int j=0; j < 256; j++)
- { // cycle all 256 colors in the wheel
- for (int q=0; q < 3; q++)
- {
- for (int i=0; i < NUM_LEDS; i=i+3)
- {
- c = Wheel( (i+j) % 255);
- setPixel(i+q, *c, *(c+1), *(c+2)); //turn every third pixel on
- }
- showStrip();
- delay(SpeedDelay);
- for (int i=0; i < NUM_LEDS; i=i+3)
- {
- setPixel(i+q, 0,0,0); //turn every third pixel off
- }
- }
- }
- }
- /* byte * Wheel(byte WheelPos)
- {
- static byte c[3];
- if(WheelPos < 85)
- {
- c[0]=WheelPos * 3;
- c[1]=255 - WheelPos * 3;
- c[2]=0;
- }
- else if(WheelPos < 170)
- {
- WheelPos -= 85;
- c[0]=255 - WheelPos * 3;
- c[1]=0;
- c[2]=WheelPos * 3;
- }
- else
- {
- WheelPos -= 170;
- c[0]=0;
- c[1]=WheelPos * 3;
- c[2]=255 - WheelPos * 3;
- }
- return c;
- }*/
- //===========
- void colorWipe(byte red, byte green, byte blue,int SpeedDelay)
- {
- for(uint16_t i=0; i<NUM_LEDS; i++)
- {
- setPixel(i, red, green, blue);
- showStrip();
- delayMicroseconds(SpeedDelay);
- }
- }
- //==========
- void Strobe(byte red, byte green, byte blue, int StrobeCount, int FlashDelay, int EndPause)
- {
- for(int j = 0; j < StrobeCount; j++)
- {
- setAll (red,green,blue);
- showStrip();
- delay(FlashDelay);
- setAll(0,0,0);
- showStrip();
- delay(FlashDelay);
- }
- delay(EndPause);
- }
- //==========
- void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {
- setAll(0,0,0);
- for(int i = 0; i < NUM_LEDS+NUM_LEDS; i++) {
- // fade brightness all LEDs one step
- for(int j=0; j<NUM_LEDS; j++) {
- if( (!meteorRandomDecay) || (random(10)>5) ) {
- fadeToBlack(j, meteorTrailDecay );
- }
- }
- // draw meteor
- for(int j = 0; j < meteorSize; j++) {
- if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
- setPixel(i-j, red, green, blue);
- }
- }
- showStrip();
- delay(SpeedDelay);
- }
- }
- void fadeToBlack(int ledNo, byte fadeValue) {
- #ifdef ADAFRUIT_NEOPIXEL_H
- // NeoPixel
- uint32_t oldColor;
- uint8_t r, g, b;
- int value;
- oldColor = strip.getPixelColor(ledNo);
- r = (oldColor & 0x00ff0000UL) >> 16;
- g = (oldColor & 0x0000ff00UL) >> 8;
- b = (oldColor & 0x000000ffUL);
- r=(r<=10)? 0 : (int) r-(r*fadeValue/256);
- g=(g<=10)? 0 : (int) g-(g*fadeValue/256);
- b=(b<=10)? 0 : (int) b-(b*fadeValue/256);
- strip.setPixelColor(ledNo, r,g,b);
- #endif
- #ifndef ADAFRUIT_NEOPIXEL_H
- // FastLED
- leds[ledNo].fadeToBlackBy( fadeValue );
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement