Advertisement
claudiusmarius

Nano In ANO 04 .01

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