Advertisement
claudiusmarius

SWITCH ON OFF POWER SAVING ARDUINO MOSFET

Aug 3rd, 2021
791
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.18 KB | None | 0 0
  1. #include <Adafruit_NeoPixel.h>
  2.  
  3.   #define LED_PIN         0  // or any other PWM capable pin
  4.   #define Nbre_LEDs      25
  5.   #define OUT1            1
  6.   #define BUZZER          2
  7.   #define BRIGHTNESS      40   // [1..255]
  8.   #define pause           5 // in milliseconds
  9.  
  10.   Adafruit_NeoPixel Matrice = Adafruit_NeoPixel(Nbre_LEDs, LED_PIN, NEO_RGB + NEO_KHZ800);
  11.  
  12.   void setup()
  13.   {
  14.   //delay(500);                                                           // Délai pour rechercher à combattre les aléas suite à une secousse trop énergique (non utilisé)
  15.   pinMode (OUT1, OUTPUT);
  16.   pinMode (BUZZER, OUTPUT);                                  
  17.   digitalWrite (OUT1, HIGH);
  18.   digitalWrite (BUZZER, LOW);
  19.   delay(20);
  20.   Matrice.begin();
  21.   digitalWrite (BUZZER, HIGH);                                            // Beep pour confirmer le démarrage
  22.   delay(10);
  23.   digitalWrite (BUZZER, LOW);
  24.   delay(10);
  25.   digitalWrite (BUZZER, HIGH);                                            
  26.   delay(10);
  27.   digitalWrite (BUZZER, LOW);
  28.   delay(10);
  29.   }
  30.  
  31.   void loop()
  32.   {
  33.   delay(1000);                                                            // Délai pour rechercher à combattre les aléas suite à une secousse trop énergique
  34.   //pinMode (OUT1, OUTPUT);                                                             // Repassage en mode OUT (au cas où la boucle devait tourner)
  35.   for (byte i = 0; i < Nbre_LEDs; i++) {
  36.   Matrice.setPixelColor(i, Matrice.Color(0, 0, 0));                       // début animation de la matrice 25 LEDs
  37.   Matrice.show();
  38.   delay(pause);
  39.  
  40.   Matrice.setPixelColor(i, Matrice.Color(BRIGHTNESS, 0, 0));
  41.   Matrice.show();
  42.   delay(pause);
  43.        
  44.   Matrice.setPixelColor(i, Matrice.Color(0, 0, 0));
  45.   Matrice.show();
  46.   delay(pause);
  47.  
  48.   Matrice.setPixelColor(i, Matrice.Color(0, BRIGHTNESS, 0));
  49.   Matrice.show();
  50.   delay(pause);
  51.  
  52.   Matrice.setPixelColor(i, Matrice.Color(0, 0, 0));
  53.   Matrice.show();
  54.   delay(pause);
  55.  
  56.   Matrice.setPixelColor(i, Matrice.Color(0, 0, BRIGHTNESS));
  57.   Matrice.show();
  58.   delay(pause);
  59.  
  60.   Matrice.setPixelColor(i, Matrice.Color(0, 0, 0));
  61.   Matrice.show();
  62.   delay(pause);
  63.  
  64.   Matrice.setPixelColor(i, Matrice.Color(BRIGHTNESS, BRIGHTNESS, 0));
  65.   Matrice.show();
  66.   delay(pause);
  67.  
  68.   Matrice.setPixelColor(i, Matrice.Color(0, 0, 0));
  69.   Matrice.show();
  70.   delay(pause);
  71.  
  72.   Matrice.setPixelColor(i, Matrice.Color(0, BRIGHTNESS, BRIGHTNESS));
  73.   Matrice.show();
  74.   delay(pause);
  75.  
  76.   Matrice.setPixelColor(i, Matrice.Color(0, 0, 0));
  77.   Matrice.show();
  78.   delay(pause);
  79.  
  80.   Matrice.setPixelColor(i, Matrice.Color(BRIGHTNESS, 0, BRIGHTNESS));
  81.   Matrice.show();
  82.   delay(pause);
  83.  
  84.   Matrice.setPixelColor(i, Matrice.Color(0, 0, 0));
  85.   Matrice.show();
  86.   delay(pause);
  87.    
  88.   Matrice.setPixelColor(i, Matrice.Color(0, 0, 0));
  89.   Matrice.show();
  90.   delay(pause);
  91.  
  92.   Matrice.setPixelColor(i, Matrice.Color(BRIGHTNESS, 0, 0));
  93.   Matrice.show();
  94.   delay(pause);
  95.  
  96.   Matrice.setPixelColor(i, Matrice.Color(0, 0, 0));
  97.   Matrice.show();
  98.   delay(pause);
  99.  
  100.   Matrice.setPixelColor(i, Matrice.Color(0, BRIGHTNESS, 0));
  101.   Matrice.show();
  102.   delay(pause);
  103.  
  104.   Matrice.setPixelColor(i, Matrice.Color(0, 0, 0));
  105.   Matrice.show();
  106.   delay(pause);
  107.  
  108.   Matrice.setPixelColor(i, Matrice.Color(0, 0, BRIGHTNESS));
  109.   Matrice.show();
  110.   delay(pause);
  111.  
  112.   Matrice.setPixelColor(i, Matrice.Color(0, 0, 0));
  113.   Matrice.show();
  114.   delay(pause);
  115.  
  116.   Matrice.setPixelColor(i, Matrice.Color(BRIGHTNESS, BRIGHTNESS, 0));
  117.   Matrice.show();
  118.   delay(pause);
  119.  
  120.   Matrice.setPixelColor(i, Matrice.Color(0, 0, 0));
  121.   Matrice.show();
  122.   delay(pause);
  123.  
  124.   Matrice.setPixelColor(i, Matrice.Color(0, BRIGHTNESS, BRIGHTNESS));
  125.   Matrice.show();
  126.   delay(pause);
  127.  
  128.   Matrice.setPixelColor(i, Matrice.Color(0, 0, 0));
  129.   Matrice.show();
  130.   delay(pause);
  131.  
  132.   Matrice.setPixelColor(i, Matrice.Color(BRIGHTNESS, 0, BRIGHTNESS));
  133.   Matrice.show();
  134.   delay(pause);
  135.    
  136.   Matrice.setPixelColor(i, Matrice.Color(0, 0, 0));
  137.   Matrice.show();
  138.   delay(pause);
  139.  
  140.   Matrice.setPixelColor(i, Matrice.Color(BRIGHTNESS, 0, 0));
  141.   Matrice.show();
  142.   delay(pause);
  143.  
  144.   Matrice.setPixelColor(i, Matrice.Color(0, 0, 0));
  145.   Matrice.show();
  146.   delay(pause);
  147.  
  148.   Matrice.setPixelColor(i, Matrice.Color(0, BRIGHTNESS, 0));
  149.   Matrice.show();
  150.   delay(pause);
  151.  
  152.   Matrice.setPixelColor(i, Matrice.Color(0, 0, 0));
  153.   Matrice.show();
  154.   delay(pause);
  155.  
  156.   Matrice.setPixelColor(i, Matrice.Color(0, 0, BRIGHTNESS));
  157.   Matrice.show();
  158.   delay(pause);
  159.  
  160.   Matrice.setPixelColor(i, Matrice.Color(0, 0, 0));
  161.   Matrice.show();
  162.   delay(pause);
  163.  
  164.   Matrice.setPixelColor(i, Matrice.Color(BRIGHTNESS, BRIGHTNESS, 0));
  165.   Matrice.show();
  166.   delay(pause);
  167.  
  168.   Matrice.setPixelColor(i, Matrice.Color(0, 0, 0));
  169.   Matrice.show();
  170.   delay(pause);
  171.  
  172.   Matrice.setPixelColor(i, Matrice.Color(0, BRIGHTNESS, BRIGHTNESS));
  173.   Matrice.show();
  174.   delay(pause);
  175.  
  176.   Matrice.setPixelColor(i, Matrice.Color(0, 0, 0));
  177.   Matrice.show();
  178.   delay(pause);
  179.  
  180.   Matrice.setPixelColor(i, Matrice.Color(BRIGHTNESS, 0, BRIGHTNESS));
  181.   Matrice.show();
  182.   delay(pause);
  183.    
  184.   Matrice.setPixelColor(i, Matrice.Color(0, 0, 0));
  185.   Matrice.show();
  186.   delay(pause);
  187.  
  188.   Matrice.setPixelColor(i, Matrice.Color(BRIGHTNESS, 0, 0));
  189.   Matrice.show();
  190.   delay(pause);
  191.  
  192.   Matrice.setPixelColor(i, Matrice.Color(0, 0, 0));
  193.   Matrice.show();
  194.   delay(pause);
  195.  
  196.   Matrice.setPixelColor(i, Matrice.Color(0, BRIGHTNESS, 0));
  197.   Matrice.show();
  198.   delay(pause);
  199.  
  200.   Matrice.setPixelColor(i, Matrice.Color(0, 0, 0));
  201.   Matrice.show();
  202.   delay(pause);
  203.  
  204.   Matrice.setPixelColor(i, Matrice.Color(0, 0, BRIGHTNESS));
  205.   Matrice.show();
  206.   delay(pause);
  207.  
  208.   Matrice.setPixelColor(i, Matrice.Color(0, 0, 0));
  209.   Matrice.show();
  210.   delay(pause);
  211.  
  212.   Matrice.setPixelColor(i, Matrice.Color(BRIGHTNESS, BRIGHTNESS, 0));
  213.   Matrice.show();
  214.   delay(pause);
  215.  
  216.   Matrice.setPixelColor(i, Matrice.Color(0, 0, 0));
  217.   Matrice.show();
  218.   delay(pause);
  219.  
  220.   Matrice.setPixelColor(i, Matrice.Color(0, BRIGHTNESS, BRIGHTNESS));
  221.   Matrice.show();
  222.   delay(pause);
  223.  
  224.   Matrice.setPixelColor(i, Matrice.Color(0, 0, 0));
  225.   Matrice.show();
  226.   delay(pause);
  227.  
  228.   Matrice.setPixelColor(i, Matrice.Color(BRIGHTNESS, 0, BRIGHTNESS));
  229.   Matrice.show();
  230.   delay(pause);
  231.  
  232.   Matrice.setPixelColor(i, Matrice.Color(0, 0, 0));
  233.   Matrice.show();
  234.   delay(pause);
  235.   }
  236.  
  237.   Matrice.clear ();                                                       // Fin de l'animation, on efface tout et on affiche
  238.   Matrice.show();
  239.   digitalWrite (BUZZER, HIGH);                                            // Beep - Beep - Beep pour avertir que l'on va couper couper l'alimentation
  240.   delay(100);
  241.   digitalWrite (BUZZER, LOW);
  242.   delay(100);
  243.   digitalWrite (BUZZER, HIGH);
  244.   delay(100);
  245.   digitalWrite (BUZZER, LOW);
  246.   delay(100);
  247.   digitalWrite (BUZZER, HIGH);
  248.   delay(100);
  249.   digitalWrite (BUZZER, LOW);
  250.   delay(700);
  251.    
  252.   digitalWrite (OUT1, LOW);                                                 // Front descendant pour désarmer l'alimentation
  253.   //pinMode (OUT1, INPUT_PULLUP);                                           // Mise en haute impédance : j'ai supprimé cette mise à haute impédance car elle perturbait le blocage du transistor ballast lorsque le montage aval comporte des capas chimiques
  254.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement