Advertisement
claudiusmarius

Nano In ANO 04 .01

Dec 13th, 2020
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 15.12 KB | None | 0 0
  1.  //================================================================================================================================================================
  2.   //    COMMUTATION ANIMATION 16 possibiliés fonction des 4entrées numériques                                        
  3.   //    FONCTIONNEMENT actuellement sur strip 144 LEDS sur Arduino NANO
  4.   //    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
  5.   //    vérité le code d'animation souhaité.
  6.   //    Plaquette_NANO_generique_Neopixels01
  7.   //
  8.   //    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
  9.   //    l'animation à présenter sur la broche 6 de la UNO.
  10.   //    Certaines combinaisons du mot binaire ne sont pas utilisées
  11.  
  12.   //    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  13.   //    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  14.   //    Actuellement il subisiste un problèéme : lors de la modification du mot , il est parfois difficile de sortir de l'animation en cours
  15.   //    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  16.   //    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  17.   //
  18.   //    DUFOURMONT Le 13/12/2020
  19.   //    claude.dufourmont@laposte.net
  20.   //    YouTube Channel : https://www.youtube.com/channel/UCvr9eb05lJow6N7m3SKqvNw
  21.   //================================================================================================================================================================
  22.  
  23.                             //====================================================================================  
  24.                                 //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  25.                                 //                            300 LEDs au MAXIMUN                            >    
  26.                                 //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  27.                             //====================================================================================  
  28.                            
  29.   #include <Adafruit_NeoPixel.h>
  30.   #define PIN      6
  31.  
  32.   #define E1 11
  33.   #define E2 2
  34.   #define E3 3
  35.   #define E4 4
  36.  
  37.   #define NUM_LEDS 144
  38.  
  39.   #define FirstLed 70                                                                             // Rang de la première LED (pour éclairer les détecteurs de décollage)
  40.   #define N 4                                                                                     // Nombre de LEDS à allumer également pour le décollage
  41.  
  42.   bool etatE1 = LOW;
  43.   bool etatE2 = LOW;
  44.   bool etatE3 = LOW;
  45.   bool etatE4 = LOW;
  46.  
  47.   byte colors[3][3] = { {0xff, 0,0},
  48.                         {0xff, 0xff, 0xff},
  49.                         {0   , 0   , 0xff} };
  50.  
  51.  // RunningLights(0xff,0,0, 50);        // red
  52.  // RunningLights(0xff,0xff,0xff, 50);  // white
  53.   //RunningLights(0,0,0xff, 50);        // blue
  54.  
  55.   Adafruit_NeoPixel strip(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
  56.  
  57.   void setup()
  58.   {
  59.                               //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  60.                               // Les pinMode ne sont pas déclarés car sur l'ATtiny85 c'est INPUT d'office     >
  61.                               //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  62.  
  63.                               //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  64.                               //                 FONCTIONNEMENT CORRECT : IF ELSE TABLE VERITE                  >
  65.                               //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  66.  
  67.  
  68.  
  69.   strip.begin();
  70.   strip.clear();
  71.   strip.setBrightness(50);
  72.   strip.show();
  73.   }
  74.  
  75.   void loop ()
  76.   {
  77.   digitalRead (E1);
  78.   digitalRead (E2);
  79.   digitalRead (E3);
  80.   digitalRead (E4);
  81.  
  82.   //========================================================================DETERMINATION DES ETATS LOGIQUE -----DEBUT-----===============================================================
  83.   if (  digitalRead (E1) == HIGH)
  84.   {
  85.   etatE1 = HIGH;
  86.   }
  87.   else
  88.   {
  89.   etatE1 = LOW;
  90.   }
  91.   if (  digitalRead (E2) == HIGH)
  92.   {
  93.   etatE2 = HIGH;
  94.   }
  95.   else
  96.   {
  97.   etatE2 = LOW;
  98.   }
  99.   if (  digitalRead (E3) == HIGH)
  100.   {
  101.   etatE3 = HIGH;
  102.   }
  103.   else
  104.   {
  105.   etatE3 = LOW;
  106.   }
  107.   if (  digitalRead (E4) == HIGH)
  108.   {
  109.   etatE4 = HIGH;
  110.   }
  111.   else
  112.   {
  113.   etatE4 = LOW;
  114.   }
  115.   //========================================================================DETERMINATION DES ETATS LOGIQUE -----FIN-----===============================================================
  116.  
  117.  //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  118.  
  119.  //============================================================TABLE DE VERITE ET SELECTION DES ANIMATIONS-----DEBUT-----===============================================================
  120.   if (etatE1 == LOW && etatE2 == LOW && etatE3 == LOW && etatE4 == LOW)
  121.   {
  122.   //AT4.00================================================================================>NON UTILISE
  123.   strip.begin();
  124.   strip.clear();
  125.   strip.setBrightness(50);
  126.   strip.show();
  127.   }
  128.  
  129.   else if (etatE1 == LOW && etatE2 == LOW && etatE3 == LOW && etatE4 == HIGH)
  130.   {
  131.   //AT4.01================================================================================>NON UTILISE
  132.   strip.begin();
  133.   strip.clear();
  134.   strip.setBrightness(50);
  135.   strip.show();
  136.   }
  137.  
  138.   else if (etatE1 == LOW && etatE2 == LOW && etatE3 == HIGH && etatE4 == LOW)
  139.   {
  140.   //AT4.02================================================================================>NON UTILISE
  141.   strip.begin();
  142.   strip.clear();
  143.   strip.setBrightness(50);
  144.   strip.show();
  145.   }
  146.  
  147.   else if (etatE1 == LOW && etatE2 == LOW && etatE3 == HIGH && etatE4 == HIGH)
  148.   {
  149.   //AT4.003================================================================================>NON UTILISE
  150.   strip.begin();
  151.   strip.clear();
  152.   strip.setBrightness(50);
  153.   strip.show();
  154.   }
  155.  
  156.   else if (etatE1 == LOW && etatE2 == HIGH && etatE3 == LOW && etatE4 == LOW)
  157.   {
  158.   //AT4.004=================================================================================> ECONOMIE ENERGIE
  159.   strip.begin();
  160.   strip.clear();
  161.   strip.setBrightness(50);
  162.   strip.show();
  163.   }
  164.  
  165.   else if (etatE1 == LOW && etatE2 == HIGH && etatE3 == LOW && etatE4 == HIGH)
  166.   {
  167.   //AT4.005=================================================================================>RainbowCycleONE_NANO01                                        
  168.   strip.begin();
  169.   strip.clear();
  170.   strip.setBrightness(50);
  171.   strip.show();
  172.   rainbowCycle(20);
  173.   }
  174.  
  175.   else if (etatE1 == LOW && etatE2 == HIGH && etatE3 == HIGH && etatE4 == LOW)
  176.   {
  177.   //AT4.006================================================================================>RandowColorTwinkleTWO_NANO01
  178.   strip.begin();
  179.   strip.clear();
  180.   strip.setBrightness(50);
  181.   strip.show();
  182.   TwinkleRandom(20, 100, false);
  183.   }
  184.  
  185.   else if (etatE1 == LOW && etatE2 == HIGH && etatE3 == HIGH && etatE4 == HIGH)
  186.   {
  187.   //AT4.007================================================================================>TheaterChaseRainbowONE_NANO01
  188.   strip.begin();
  189.   strip.clear();
  190.   strip.setBrightness(50);
  191.   strip.show();
  192.   theaterChaseRainbow(50);
  193.   }
  194.  
  195.   else if (etatE1 == HIGH && etatE2 == LOW && etatE3 == LOW && etatE4 == LOW)
  196.   {
  197.   //AT4.008================================================================================>Decollage3LEDS_ONE_NANO01
  198.   strip.begin();
  199.   strip.clear();
  200.   strip.setBrightness(255);
  201.   strip.show();
  202.   for(int i=FirstLed; i<FirstLed+N; i++)                                                          //
  203.   {
  204.   strip.setPixelColor(i, 255, 255, 255);
  205.   strip.show();
  206.   }
  207.   }
  208.  
  209.   else if (etatE1 == HIGH && etatE2 == LOW && etatE3 == LOW && etatE4 == HIGH)
  210.   {
  211.   //AT4.009================================================================================>NON UTILISE
  212.   strip.begin();
  213.   strip.clear();
  214.   strip.setBrightness(50);
  215.   strip.show();
  216.   }
  217.  
  218.   else if (etatE1 ==HIGH && etatE2 == LOW && etatE3 == HIGH && etatE4 == LOW)
  219.   {
  220.   //AT4.010================================================================================>NON UTILISE
  221.   strip.begin();
  222.   strip.clear();
  223.   strip.setBrightness(50);
  224.   strip.show();
  225.   }
  226.  
  227.   else if (etatE1 == HIGH && etatE2 == LOW && etatE3 == HIGH && etatE4 == HIGH)
  228.   {
  229.   //AT4.011================================================================================>NON UTILISE
  230.   strip.begin();
  231.   strip.clear();
  232.   strip.setBrightness(50);
  233.   strip.show();
  234.   }
  235.  
  236.   else if (etatE1 == HIGH && etatE2 == HIGH && etatE3 == LOW && etatE4 == LOW)
  237.   {
  238.   //AT4.012================================================================================>ColorWipeONE_NANO01
  239.   strip.begin();
  240.   strip.clear();
  241.   strip.setBrightness(50);
  242.   strip.show();
  243.   colorWipe(255,0,0, 255);
  244.   colorWipe(0,0,255, 255);
  245.   colorWipe(0,255,0, 255);
  246.   colorWipe(255,100,40, 255);
  247.   colorWipe(0,100,40, 255);
  248.   colorWipe(255,255,0, 255);
  249.   }
  250.  
  251.   else if (etatE1 == HIGH && etatE2 == HIGH && etatE3 == LOW && etatE4 == HIGH)
  252.   {
  253.   //AT4.013================================================================================>StrobeONE_NANO02
  254.   strip.begin();
  255.   strip.clear();
  256.   strip.setBrightness(50);
  257.   strip.show();
  258.   Strobe(0xff, 0xff, 0xff, 10, 50, 50);       // dernier ypique 1000
  259.   }
  260.  
  261.   else if (etatE1 == HIGH && etatE2 == HIGH && etatE3 == HIGH && etatE4 == LOW)
  262.   {
  263.   //AT4.014================================================================================>MeteorRainONE_NANO01
  264.   strip.begin();
  265.   strip.clear();
  266.   strip.setBrightness(50);
  267.   strip.show();
  268.   meteorRain(0xff,0xff,0xff,5, 60, false, 0);
  269.   }
  270.  
  271.   else if (etatE1 == HIGH && etatE2 == HIGH && etatE3 == HIGH && etatE4 == HIGH)
  272.   {
  273.   //AT4.015================================================================================>NON UTILISE
  274.   strip.begin();
  275.   strip.clear();
  276.   strip.setBrightness(50);
  277.   strip.show();
  278.   }
  279.   }
  280.   //============================================================TABLE DE VERITE ET SELECTION DES ANIMATIONS-----FIN-----===============================================================
  281.  
  282.  
  283.  
  284. //*****************************************************************************************************************************************
  285.   void showStrip() {
  286.   #ifdef ADAFRUIT_NEOPIXEL_H
  287.   strip.show();
  288.   #endif
  289.   #ifndef ADAFRUIT_NEOPIXEL_H
  290.   #endif
  291.   }
  292.  
  293.   void setPixel(int Pixel, byte red, byte green, byte blue) {
  294.   #ifdef ADAFRUIT_NEOPIXEL_H
  295.   strip.setPixelColor(Pixel, strip.Color(red, green, blue));
  296.   #endif
  297.   #ifndef ADAFRUIT_NEOPIXEL_H
  298.   #endif
  299.   }
  300.  
  301.   void setAll(byte red, byte green, byte blue) {
  302.   for(int i = 0; i < NUM_LEDS; i++ ) {
  303.   setPixel(i, red, green, blue);
  304.   }
  305.   showStrip();
  306.   }
  307.  
  308. //============
  309.  
  310. void rainbowCycle(int SpeedDelay)
  311. {
  312.   byte *c;
  313.   uint16_t i, j;
  314.  
  315.   for(j=0; j<256*5; j++) // 5 cycles of all colors on wheel
  316.   {
  317.     for(i=0; i< NUM_LEDS; i++) {
  318.       c=Wheel(((i * 256 / NUM_LEDS) + j) & 255);
  319.       setPixel(i, *c, *(c+1), *(c+2));
  320.   }
  321.   showStrip();
  322.   delay(SpeedDelay);
  323.   }
  324.   }
  325.  
  326.   byte * Wheel(byte WheelPos) {
  327.   static byte c[3];
  328.  
  329.   if(WheelPos < 85)
  330.   {
  331.    c[0]=WheelPos * 3;
  332.    c[1]=255 - WheelPos * 3;
  333.    c[2]=0;
  334.   } else if(WheelPos < 170)
  335.   {
  336.    WheelPos -= 85;
  337.    c[0]=255 - WheelPos * 3;
  338.    c[1]=0;
  339.    c[2]=WheelPos * 3;
  340.   } else {
  341.    WheelPos -= 170;
  342.    c[0]=0;
  343.    c[1]=WheelPos * 3;
  344.    c[2]=255 - WheelPos * 3;
  345.   }
  346.   return c;
  347.   }
  348. //===========
  349.  
  350. void TwinkleRandom(int Count, int SpeedDelay, boolean OnlyOne)
  351.   {
  352.   setAll(0,0,0);
  353.   for (int i=0; i<Count; i++)
  354.   {
  355.      setPixel(random(NUM_LEDS),random(0,255),random(0,255),random(0,255));
  356.      showStrip();
  357.      delay(SpeedDelay);
  358.      if(OnlyOne) {
  359.      setAll(0,0,0);
  360.   }
  361.   }
  362.  
  363.   delay(SpeedDelay);
  364.   }
  365. //=============
  366.  
  367. void theaterChaseRainbow(int SpeedDelay)
  368.   {
  369.   byte *c;
  370.  
  371.   for (int j=0; j < 256; j++)
  372.   {     // cycle all 256 colors in the wheel
  373.   for (int q=0; q < 3; q++)
  374.   {
  375.   for (int i=0; i < NUM_LEDS; i=i+3)
  376.   {
  377.           c = Wheel( (i+j) % 255);
  378.           setPixel(i+q, *c, *(c+1), *(c+2));    //turn every third pixel on
  379.   }
  380.   showStrip();
  381.   delay(SpeedDelay);
  382.   for (int i=0; i < NUM_LEDS; i=i+3)
  383.   {
  384.   setPixel(i+q, 0,0,0);        //turn every third pixel off
  385.   }
  386.   }
  387.   }
  388.   }
  389.  
  390.  /* byte * Wheel(byte WheelPos)
  391.   {
  392.   static byte c[3];
  393.    if(WheelPos < 85)
  394.    {
  395.    c[0]=WheelPos * 3;
  396.    c[1]=255 - WheelPos * 3;
  397.    c[2]=0;
  398.   }
  399.   else if(WheelPos < 170)
  400.   {
  401.    WheelPos -= 85;
  402.    c[0]=255 - WheelPos * 3;
  403.    c[1]=0;
  404.    c[2]=WheelPos * 3;
  405.   }
  406.   else
  407.   {
  408.    WheelPos -= 170;
  409.    c[0]=0;
  410.    c[1]=WheelPos * 3;
  411.    c[2]=255 - WheelPos * 3;
  412.   }
  413.  
  414.   return c;
  415. }*/
  416. //===========
  417.  
  418. void colorWipe(byte red, byte green, byte blue,int SpeedDelay)
  419.   {
  420.   for(uint16_t i=0; i<NUM_LEDS; i++)
  421.   {
  422.   setPixel(i, red, green, blue);
  423.   showStrip();
  424.   delayMicroseconds(SpeedDelay);
  425.   }
  426.   }
  427.  
  428. //==========
  429.  
  430. void Strobe(byte red, byte green, byte blue, int StrobeCount, int FlashDelay, int EndPause)
  431.   {
  432.   for(int j = 0; j < StrobeCount; j++)
  433.   {
  434.     setAll (red,green,blue);
  435.     showStrip();
  436.     delay(FlashDelay);
  437.     setAll(0,0,0);
  438.     showStrip();
  439.     delay(FlashDelay);
  440.   }
  441.   delay(EndPause);
  442.   }
  443.  
  444. //==========
  445.  
  446. void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {  
  447.   setAll(0,0,0);
  448.  
  449.   for(int i = 0; i < NUM_LEDS+NUM_LEDS; i++) {
  450.    
  451.    
  452.     // fade brightness all LEDs one step
  453.     for(int j=0; j<NUM_LEDS; j++) {
  454.       if( (!meteorRandomDecay) || (random(10)>5) ) {
  455.         fadeToBlack(j, meteorTrailDecay );        
  456.       }
  457.     }
  458.    
  459.     // draw meteor
  460.     for(int j = 0; j < meteorSize; j++) {
  461.       if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
  462.         setPixel(i-j, red, green, blue);
  463.       }
  464.     }
  465.    
  466.     showStrip();
  467.     delay(SpeedDelay);
  468.   }
  469. }
  470.  
  471. void fadeToBlack(int ledNo, byte fadeValue) {
  472.  #ifdef ADAFRUIT_NEOPIXEL_H
  473.     // NeoPixel
  474.     uint32_t oldColor;
  475.     uint8_t r, g, b;
  476.     int value;
  477.    
  478.     oldColor = strip.getPixelColor(ledNo);
  479.     r = (oldColor & 0x00ff0000UL) >> 16;
  480.     g = (oldColor & 0x0000ff00UL) >> 8;
  481.     b = (oldColor & 0x000000ffUL);
  482.  
  483.     r=(r<=10)? 0 : (int) r-(r*fadeValue/256);
  484.     g=(g<=10)? 0 : (int) g-(g*fadeValue/256);
  485.     b=(b<=10)? 0 : (int) b-(b*fadeValue/256);
  486.    
  487.     strip.setPixelColor(ledNo, r,g,b);
  488.  #endif
  489.  #ifndef ADAFRUIT_NEOPIXEL_H
  490.    // FastLED
  491.    leds[ledNo].fadeToBlackBy( fadeValue );
  492.  #endif  
  493. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement