mich29800

taches_clignotement

Jul 24th, 2021
1,049
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include <Wire.h>
  3. #include <Adafruit_PWMServoDriver.h>
  4. Adafruit_PWMServoDriver ledB = Adafruit_PWMServoDriver(0x40);
  5. #define pinledR 5 // sortie led rouge en 5 (exemple)
  6. unsigned long oldtime[10];
  7. int delai[10];
  8. uint16_t lumled[10];
  9. uint8_t nled=1;
  10.  
  11. void setup() {
  12.  
  13. ledB.begin();
  14. ledB.setPWMFreq(100);  //fréquence PWM de 100Hz
  15. pinMode(pinledR,OUTPUT);
  16. oldtime[0]=0;
  17. for (byte i=1;i<9;i++)
  18. {oldtime[i]=0;lumled[i]=0;}
  19. // ledB.setPWM(i-1,0,0);}
  20. delai[0]=500;
  21. delai[1]=2;
  22. delai[2]=2;
  23. delai[3]=2;
  24. delai[4]=2;
  25. delai[5]=2;
  26. delai[6]=2;
  27. delai[7]=2;
  28. delai[8]=2;
  29. }
  30.  
  31. void loop() {
  32.   // clignotement led rouge
  33.   if ((millis()-oldtime[0])>delai[0])
  34.   {digitalWrite(pinledR,!digitalRead(pinledR));
  35.    oldtime[0]=millis();}
  36.    
  37.   // chenillard leds blanches à luminosité progressive
  38.  
  39.    if ((millis()-oldtime[nled])>delai[nled])
  40.    {if (lumled[nled]<4096){lumled[nled]=lumled[nled]+16;}
  41.     else {lumled[nled]=0;nled++;}
  42.    if (nled==9){nled=1;}    
  43.    ledB.setPWM(nled,0,lumled[nled]);
  44.    oldtime[nled]=millis();}
  45.  
  46. }
RAW Paste Data