Advertisement
Guest User

ESP32 LED Code

a guest
Oct 8th, 2019
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 15.37 KB | None | 0 0
  1. #include <Arduino.h>
  2. #include <FastLED.h>
  3.  
  4. FASTLED_USING_NAMESPACE
  5. using namespace std;
  6.  
  7. #define LED_TYPE    WS2812B
  8. #define COLOR_ORDER GRB
  9.  
  10. #define MIN_BRIGHTNESS 20
  11. #define MAX_BRIGHTNESS 170
  12.  
  13. #define CURRENT_COLOR CRGB(225, 202, 0)
  14. #define CURRENT_HUE 54
  15.  
  16. #define LED_PIN_SOCKET_HOOD 2
  17. #define LED_PIN_HOOD_KLE_AC 4
  18. #define LED_PIN_HOOD_KLE_DC 16
  19. #define LED_PIN_KLE_AC_KLE_DC 17
  20.  
  21. #define LED_PIN_KLE_EME_DC 5
  22. #define LED_PIN_KLE_EME_AC 18
  23.  
  24. #define LED_PIN_EME_BATTERY 19
  25. #define LED_PIN_EME_EDH 21
  26. #define LED_PIN_EME_EKK 3
  27. #define LED_PIN_EME_EM 22
  28. #define LED_PIN_CHASSIS 23
  29.  
  30. const uint16_t NUM_LEDS_SOCKET_HOOD = 60; // 300
  31. const uint16_t NUM_LEDS_HOOD_KLE_AC = 60; // 60
  32. const uint16_t NUM_LEDS_HOOD_KLE_DC = 10; // 60
  33. const uint16_t NUM_LEDS_KLE_AC_KLE_DC = 10; // 48
  34.  
  35. const uint16_t NUM_LEDS_KLE_EME_DC = 10; // 84
  36. const uint16_t NUM_LEDS_KLE_EME_AC = 10; // 29
  37.  
  38. const uint16_t NUM_LEDS_EME_BATTERY = 10; // 60
  39. const uint16_t NUM_LEDS_EME_EDH = 10; // 96
  40. const uint16_t NUM_LEDS_EME_EKK = 10; // 66
  41. const uint16_t NUM_LEDS_EME_EM = 10; // 18
  42. const uint16_t NUM_LEDS_CHASSIS = 10; // 120
  43.  
  44. #define BUTTON_PIN_CHARGE_AC1 13
  45. #define BUTTON_PIN_CHARGE_AC3 12
  46. #define BUTTON_PIN_CHARGE_DC 14
  47. #define BUTTON_PIN_ACC 27
  48. #define BUTTON_PIN_RECU_HIGH 26
  49. #define BUTTON_PIN_RECU_LOW 25
  50. #define BUTTON_PIN_COOL 33
  51. #define BUTTON_PIN_HEAT 32
  52.  
  53. #define BUTTON_PIN_RESET 15
  54.  
  55. CRGB socket_hood[NUM_LEDS_SOCKET_HOOD];
  56. CRGB hood_KLE_AC[NUM_LEDS_HOOD_KLE_AC];
  57. CRGB hood_KLE_DC[NUM_LEDS_HOOD_KLE_DC];
  58. CRGB KLE_AC_KLE_DC[NUM_LEDS_KLE_AC_KLE_DC];
  59.  
  60. CRGB KLE_EME_DC[NUM_LEDS_KLE_EME_DC];
  61. CRGB KLE_EME_AC[NUM_LEDS_KLE_EME_AC];
  62.  
  63. CRGB EME_Battery[NUM_LEDS_EME_BATTERY];
  64. CRGB EME_EDH[NUM_LEDS_EME_EDH];
  65. CRGB EME_EKK[NUM_LEDS_EME_EKK];
  66. CRGB EME_EM[NUM_LEDS_EME_EM];
  67. CRGB CHASSIS[NUM_LEDS_CHASSIS];
  68.  
  69. void sinusWave(CRGB leds[], uint16_t num_leds, uint16_t current_led);
  70. void IRAM_ATTR registerButtonPress(void* arg);
  71. void clearLEDs(CRGB leds[], uint16_t num_leds);
  72. void clearAllLEDs();
  73.  
  74. void chargeAC1(uint16_t wait_ms);
  75. void chargeAC3(uint16_t wait_ms);
  76. void chargeDC(uint16_t wait_ms);
  77. void accelerate(uint16_t wait_ms);
  78. void recu(uint16_t wait_ms);
  79. void heat(uint16_t wait_ms);
  80. void cool(uint16_t wait_ms);
  81.  
  82. const float pi = 6.28;
  83.  
  84. byte BRIGHTNESS = 30;
  85. uint16_t DEFAULT_INTERVAL_MS = 25;
  86.  
  87. struct Button
  88. {
  89.   const uint8_t Pin;
  90.   bool IsPressed;
  91. };
  92.  
  93. Button button_charge_AC1 =  { BUTTON_PIN_CHARGE_AC1,  false };
  94. Button button_charge_AC3 =  { BUTTON_PIN_CHARGE_AC3,  false };
  95. Button button_charge_DC =   { BUTTON_PIN_CHARGE_DC,   false };
  96. Button button_acc =         { BUTTON_PIN_ACC,         false };
  97. Button button_recu_high =   { BUTTON_PIN_RECU_HIGH,   false };
  98. Button button_recu_low =    { BUTTON_PIN_RECU_LOW,    false };
  99. Button button_heating =     { BUTTON_PIN_HEAT,     false };
  100. Button button_cooling =     { BUTTON_PIN_COOL,     false };
  101.  
  102. Button button_reset =       { BUTTON_PIN_RESET,       false };
  103.  
  104. enum class LEDState: int8_t
  105. {
  106.   IDLE,
  107.   AC_1,
  108.   AC_3,
  109.   DC,
  110.   ACC,
  111.   RECU_HIGH,
  112.   RECU_LOW,
  113.   HEATING,
  114.   COOLING
  115. };
  116.  
  117. LEDState currentLEDState = LEDState::IDLE;
  118. LEDState previousLEDState = LEDState::IDLE;
  119.  
  120. uint16_t currentLED = 0;
  121. uint16_t currentLED_AC = 0;
  122.  
  123. void setup() {
  124.   Serial.begin(115200);
  125.   delay(3000); // 3 second delay for recovery
  126.   Serial.println("Starting Controller...");
  127.  
  128.    // tell FastLED about the LED strip configuration
  129.   FastLED.addLeds<LED_TYPE, LED_PIN_SOCKET_HOOD, COLOR_ORDER>(socket_hood, NUM_LEDS_SOCKET_HOOD).setCorrection(TypicalLEDStrip);
  130.   FastLED.addLeds<LED_TYPE, LED_PIN_HOOD_KLE_AC, COLOR_ORDER>(hood_KLE_AC, NUM_LEDS_HOOD_KLE_AC).setCorrection(TypicalLEDStrip);
  131.   FastLED.addLeds<LED_TYPE, LED_PIN_HOOD_KLE_DC, COLOR_ORDER>(hood_KLE_DC, NUM_LEDS_HOOD_KLE_DC).setCorrection(TypicalLEDStrip);  
  132.   FastLED.addLeds<LED_TYPE, LED_PIN_KLE_AC_KLE_DC, COLOR_ORDER>(KLE_AC_KLE_DC, NUM_LEDS_KLE_AC_KLE_DC).setCorrection(TypicalLEDStrip);
  133.  
  134.   FastLED.addLeds<LED_TYPE, LED_PIN_KLE_EME_DC, COLOR_ORDER>(KLE_EME_DC, NUM_LEDS_KLE_EME_DC).setCorrection(TypicalLEDStrip);
  135.   FastLED.addLeds<LED_TYPE, LED_PIN_KLE_EME_AC, COLOR_ORDER>(KLE_EME_AC, NUM_LEDS_KLE_EME_AC).setCorrection(TypicalLEDStrip);
  136.  
  137.   FastLED.addLeds<LED_TYPE, LED_PIN_EME_BATTERY, COLOR_ORDER>(EME_Battery, NUM_LEDS_EME_BATTERY).setCorrection(TypicalLEDStrip);
  138.   FastLED.addLeds<LED_TYPE, LED_PIN_EME_EDH, COLOR_ORDER>(EME_EDH, NUM_LEDS_EME_EDH).setCorrection(TypicalLEDStrip);
  139.   FastLED.addLeds<LED_TYPE, LED_PIN_EME_EKK, COLOR_ORDER>(EME_EKK, NUM_LEDS_EME_EKK).setCorrection(TypicalLEDStrip);
  140.   FastLED.addLeds<LED_TYPE, LED_PIN_EME_EM, COLOR_ORDER>(EME_EM, NUM_LEDS_EME_EM).setCorrection(TypicalLEDStrip);
  141.   FastLED.addLeds<LED_TYPE, LED_PIN_CHASSIS, COLOR_ORDER>(CHASSIS, NUM_LEDS_CHASSIS).setCorrection(TypicalLEDStrip);
  142.  
  143.   // clamp brightness between min and max
  144.   BRIGHTNESS = constrain(BRIGHTNESS, MIN_BRIGHTNESS, MAX_BRIGHTNESS);
  145.  
  146.   clearAllLEDs();
  147.  
  148.   // set master brightness control
  149.   FastLED.setBrightness(BRIGHTNESS);
  150.   FastLED.setDither( 0 );
  151.   FastLED.show();
  152.  
  153.   pinMode(button_charge_AC1.Pin, INPUT_PULLUP);
  154.   pinMode(button_charge_AC3.Pin, INPUT_PULLUP);
  155.   pinMode(button_charge_DC.Pin, INPUT_PULLUP);
  156.   pinMode(button_acc.Pin, INPUT_PULLUP);
  157.   pinMode(button_recu_high.Pin, INPUT_PULLUP);
  158.   pinMode(button_recu_low.Pin, INPUT_PULLUP);
  159.   pinMode(button_heating.Pin, INPUT_PULLUP);
  160.   pinMode(button_cooling.Pin, INPUT_PULLUP);
  161.  
  162.   pinMode(button_reset.Pin, INPUT_PULLUP);
  163.  
  164.   attachInterruptArg(digitalPinToInterrupt(button_charge_AC1.Pin), registerButtonPress, &button_charge_AC1, FALLING);
  165.   attachInterruptArg(digitalPinToInterrupt(button_charge_AC3.Pin), registerButtonPress, &button_charge_AC3, FALLING);
  166.   attachInterruptArg(digitalPinToInterrupt(button_charge_DC.Pin), registerButtonPress, &button_charge_DC, FALLING);
  167.   attachInterruptArg(digitalPinToInterrupt(button_acc.Pin), registerButtonPress, &button_acc, FALLING);
  168.   attachInterruptArg(digitalPinToInterrupt(button_recu_high.Pin), registerButtonPress, &button_recu_high, FALLING);
  169.   attachInterruptArg(digitalPinToInterrupt(button_recu_low.Pin), registerButtonPress, &button_recu_low, FALLING);
  170.   attachInterruptArg(digitalPinToInterrupt(button_heating.Pin), registerButtonPress, &button_heating, FALLING);
  171.   attachInterruptArg(digitalPinToInterrupt(button_cooling.Pin), registerButtonPress, &button_cooling, FALLING);
  172.  
  173.   attachInterruptArg(button_reset.Pin, registerButtonPress, &button_reset, FALLING);
  174.  
  175.   Serial.println("Controller initialization successful.");
  176.  
  177. }
  178.  
  179. void loop() {
  180.   updateState();
  181.   executeState();
  182.   FastLED.show();
  183.  
  184. }
  185.  
  186. void executeState()
  187. {
  188.   switch(currentLEDState)
  189.   {
  190.     case LEDState::IDLE:
  191.       //clearAllLEDs();
  192.       break;
  193.     case LEDState::AC_1:
  194.       chargeAC1(DEFAULT_INTERVAL_MS);      
  195.       break;
  196.     case LEDState::AC_3:      
  197.       break;
  198.     case LEDState::DC:
  199.       chargeDC(DEFAULT_INTERVAL_MS);
  200.       break;
  201.     case LEDState::ACC:
  202.       accelerate(DEFAULT_INTERVAL_MS);
  203.       break;
  204.     case LEDState::RECU_HIGH:
  205.       recu(DEFAULT_INTERVAL_MS);
  206.       break;
  207.     case LEDState::RECU_LOW:
  208.       recu(DEFAULT_INTERVAL_MS * 4);
  209.       break;
  210.     case LEDState::HEATING:
  211.       heat(DEFAULT_INTERVAL_MS);
  212.       break;
  213.     case LEDState::COOLING:
  214.       cool(DEFAULT_INTERVAL_MS);
  215.       break;
  216.     default:
  217.       break;
  218.   }
  219. }
  220.  
  221. void updateState()
  222. {
  223.   if(button_charge_AC1.IsPressed)
  224.   {
  225.     Serial.println("AC_1");
  226.     button_charge_AC1.IsPressed = false;
  227.     currentLEDState = LEDState::AC_1;
  228.     if(previousLEDState != currentLEDState)
  229.     {
  230.       clearAllLEDs();
  231.       previousLEDState = currentLEDState;
  232.     }      
  233.   }
  234.   if(button_charge_AC3.IsPressed)
  235.   {
  236.     button_charge_AC3.IsPressed = false;
  237.     Serial.println("AC_3");
  238.     currentLEDState = LEDState::AC_3;
  239.     if(previousLEDState != currentLEDState)
  240.     {
  241.       clearAllLEDs();
  242.       previousLEDState = currentLEDState;
  243.     }      
  244.   }
  245.   if(button_charge_DC.IsPressed)
  246.   {
  247.     button_charge_DC.IsPressed = false;
  248.     Serial.println("DC");
  249.     currentLEDState = LEDState::DC;
  250.     if(previousLEDState != currentLEDState)
  251.     {
  252.       clearAllLEDs();
  253.       previousLEDState = currentLEDState;
  254.     }      
  255.   }
  256.   if(button_acc.IsPressed)
  257.   {
  258.     button_acc.IsPressed = false;
  259.     Serial.println("Acc");
  260.     currentLEDState = LEDState::ACC;
  261.     if(previousLEDState != currentLEDState)
  262.     {
  263.       clearAllLEDs();
  264.       previousLEDState = currentLEDState;
  265.     }      
  266.   }
  267.   if(button_recu_high.IsPressed)
  268.   {
  269.     button_recu_high.IsPressed = false;
  270.     Serial.println("Recu High");
  271.     currentLEDState = LEDState::RECU_HIGH;
  272.     if(previousLEDState != currentLEDState)
  273.     {
  274.       clearAllLEDs();
  275.       previousLEDState = currentLEDState;
  276.     }      
  277.   }
  278.   if(button_recu_low.IsPressed)
  279.   {
  280.     button_recu_low.IsPressed = false;
  281.     Serial.println("Recu_Low");
  282.     currentLEDState = LEDState::RECU_LOW;
  283.     if(previousLEDState != currentLEDState)
  284.     {
  285.       clearAllLEDs();
  286.       previousLEDState = currentLEDState;
  287.     }    
  288.   }
  289.   if(button_heating.IsPressed)
  290.   {
  291.     button_heating.IsPressed = false;
  292.     Serial.println("Heating");
  293.     currentLEDState = LEDState::HEATING;
  294.     if(previousLEDState != currentLEDState)
  295.     {
  296.       clearAllLEDs();
  297.       previousLEDState = currentLEDState;
  298.     }    
  299.   }
  300.   if(button_cooling.IsPressed)
  301.   {
  302.     button_cooling.IsPressed = false;
  303.     Serial.println("Cooling");
  304.     currentLEDState = LEDState::COOLING;
  305.     if(previousLEDState != currentLEDState)
  306.     {
  307.       clearAllLEDs();
  308.       previousLEDState = currentLEDState;
  309.     }      
  310.   }
  311.   if(button_reset.IsPressed)
  312.   {
  313.     button_reset.IsPressed = false;
  314.     Serial.println("Reset");
  315.     /*currentLEDState = LEDState::IDLE;
  316.     if(previousLEDState != currentLEDState)
  317.     {
  318.       //clearAllLEDs();
  319.       previousLEDState = currentLEDState;
  320.     }*/  
  321.   }
  322. }
  323.  
  324. void IRAM_ATTR registerButtonPress(void* arg) {
  325.     Button* s = static_cast<Button*>(arg);
  326.     s->IsPressed = true;
  327. }
  328.  
  329. /*CRGB socket_hood[NUM_LEDS_SOCKET_HOOD];
  330. CRGB hood_KLE_AC[NUM_LEDS_HOOD_KLE_AC];
  331. CRGB hood_KLE_DC[NUM_LEDS_HOOD_KLE_DC];
  332. CRGB KLE_AC_KLE_DC[NUM_LEDS_KLE_AC_KLE_DC];
  333.  
  334. CRGB KLE_EME_DC[NUM_LEDS_KLE_EME_DC];
  335. CRGB KLE_EME_AC[NUM_LEDS_KLE_EME_AC];
  336.  
  337. CRGB EME_Battery[NUM_LEDS_EME_BATTERY];
  338. CRGB EME_EDH[NUM_LEDS_EME_EDH];
  339. CRGB EME_EKK[NUM_LEDS_EME_EKK];
  340. CRGB EME_EM[NUM_LEDS_EME_EM];
  341. CRGB CHASSIS[NUM_LEDS_CHASSIS];
  342. */
  343.  
  344. // restart from last pos instead of first to avoid "jump" in animation
  345. void sinusWave(CRGB leds[], uint16_t num_leds, uint16_t current_led)
  346. {
  347.     Serial.println(current_led);
  348.     byte brightness;
  349.     byte phase = 2;
  350.     for(uint16_t i=0; i<num_leds; i++) {
  351.       brightness = (pow(sin(((current_led + i) % num_leds) / (float)num_leds * pi * phase),8) * 255);
  352.       if(brightness < MIN_BRIGHTNESS)
  353.       {
  354.         brightness = 0;
  355.       }
  356.       leds[i] = CHSV(CURRENT_HUE, 255, brightness);
  357.     }
  358. }
  359.  
  360. void chargeAC1(uint16_t wait_ms)
  361. {
  362.   // sinus
  363.   if(currentLED_AC < NUM_LEDS_SOCKET_HOOD + NUM_LEDS_HOOD_KLE_AC + NUM_LEDS_KLE_AC_KLE_DC)
  364.   {
  365.     sinusWave(socket_hood, NUM_LEDS_SOCKET_HOOD, currentLED_AC % NUM_LEDS_SOCKET_HOOD);
  366.     sinusWave(hood_KLE_AC, NUM_LEDS_HOOD_KLE_AC, currentLED_AC % NUM_LEDS_HOOD_KLE_AC);
  367.     sinusWave(KLE_AC_KLE_DC, NUM_LEDS_KLE_AC_KLE_DC, currentLED_AC % NUM_LEDS_KLE_AC_KLE_DC);
  368.   }
  369.   else
  370.   {
  371.     currentLED_AC = -1;
  372.   }
  373.  
  374.   // gradual
  375.   if(currentLED < NUM_LEDS_KLE_EME_DC)
  376.   {
  377.     KLE_EME_DC[currentLED] = CURRENT_COLOR;
  378.   }
  379.   else if(currentLED < NUM_LEDS_KLE_EME_DC + NUM_LEDS_EME_BATTERY)
  380.   {
  381.     EME_Battery[currentLED - NUM_LEDS_KLE_EME_DC] = CURRENT_COLOR;
  382.   }
  383.   else
  384.   {
  385.     currentLED = -1;
  386.     clearLEDs(KLE_EME_DC, NUM_LEDS_KLE_EME_DC);
  387.     clearLEDs(EME_Battery, NUM_LEDS_EME_BATTERY);
  388.   }
  389.   currentLED_AC++;
  390.   currentLED++;
  391.   delay(wait_ms);
  392. }
  393.  
  394. void chargeDC(uint16_t wait_ms)
  395. {
  396.   if(currentLED < NUM_LEDS_SOCKET_HOOD)
  397.   {
  398.     socket_hood[currentLED] = CURRENT_COLOR;
  399.   }
  400.   else if(currentLED < NUM_LEDS_SOCKET_HOOD + NUM_LEDS_HOOD_KLE_DC)
  401.   {
  402.     hood_KLE_DC[currentLED - NUM_LEDS_SOCKET_HOOD] = CURRENT_COLOR;
  403.   }
  404.   else if(currentLED < NUM_LEDS_SOCKET_HOOD + NUM_LEDS_HOOD_KLE_DC + NUM_LEDS_KLE_EME_DC)
  405.   {
  406.     KLE_EME_DC[currentLED - NUM_LEDS_SOCKET_HOOD - NUM_LEDS_HOOD_KLE_DC] = CURRENT_COLOR;
  407.   }
  408.   else if(currentLED < NUM_LEDS_SOCKET_HOOD + NUM_LEDS_HOOD_KLE_DC + NUM_LEDS_KLE_EME_DC + NUM_LEDS_EME_BATTERY)
  409.   {
  410.     EME_Battery[currentLED - NUM_LEDS_SOCKET_HOOD - NUM_LEDS_HOOD_KLE_DC - NUM_LEDS_KLE_EME_DC] = CURRENT_COLOR;
  411.   }
  412.   else
  413.   {
  414.     clearAllLEDs();
  415.     currentLED = -1;
  416.   }
  417.   currentLED++;
  418.   delay(wait_ms);
  419. }
  420.  
  421. void accelerate(uint16_t wait_ms)
  422. {
  423.   uint16_t actualLED = currentLED;
  424.   // Bat -> EME -> EM
  425.   if(currentLED < NUM_LEDS_EME_BATTERY)
  426.   {
  427.     //Serial.println("EME_Battery");
  428.     actualLED = NUM_LEDS_EME_BATTERY - currentLED - 1;
  429.     EME_Battery[NUM_LEDS_EME_BATTERY - currentLED - 1] = CURRENT_COLOR;
  430.   }
  431.   else if(currentLED < NUM_LEDS_EME_BATTERY + NUM_LEDS_EME_EM)
  432.   {
  433.     //Serial.println("EME_EM");
  434.     actualLED = currentLED - NUM_LEDS_EME_BATTERY;
  435.     EME_EM[currentLED - NUM_LEDS_EME_BATTERY] = CURRENT_COLOR;
  436.   }
  437.   else
  438.   {
  439.     clearAllLEDs();
  440.     currentLED = -1;
  441.   }
  442.   currentLED++;
  443.   delay(wait_ms);
  444. }
  445.  
  446. void recu(uint16_t wait_ms)
  447. {
  448.   if(currentLED < NUM_LEDS_EME_EM)
  449.   {
  450.     EME_EM[NUM_LEDS_EME_EM - currentLED - 1] = CURRENT_COLOR;
  451.   }
  452.   else if(currentLED < NUM_LEDS_EME_EM + NUM_LEDS_EME_BATTERY)
  453.   {
  454.     EME_Battery[currentLED - NUM_LEDS_EME_EM - 1] = CURRENT_COLOR;
  455.   }
  456.   else
  457.   {
  458.     clearAllLEDs();
  459.     currentLED = -1;
  460.   }
  461.   currentLED++;
  462.   delay(wait_ms);
  463. }
  464.  
  465. void heat(uint16_t wait_ms)
  466. {
  467.   // Bat -> EME -> EM
  468.   if(currentLED < NUM_LEDS_EME_BATTERY)
  469.   {
  470.     EME_Battery[NUM_LEDS_EME_BATTERY - currentLED - 1] = CURRENT_COLOR;
  471.   }
  472.   else if(currentLED < NUM_LEDS_EME_BATTERY + NUM_LEDS_EME_EM)
  473.   {
  474.     EME_EM[currentLED - NUM_LEDS_EME_BATTERY] = CURRENT_COLOR;
  475.   }
  476.   else if(currentLED < NUM_LEDS_EME_BATTERY + NUM_LEDS_EME_EM + NUM_LEDS_EME_EDH)
  477.   {
  478.     EME_EDH[currentLED - NUM_LEDS_EME_BATTERY - NUM_LEDS_EME_EM] = CURRENT_COLOR;
  479.   }
  480.   else
  481.   {
  482.     clearAllLEDs();
  483.     currentLED = -1;
  484.   }
  485.   currentLED++;
  486.   delay(wait_ms);
  487. }
  488.  
  489. void cool(uint16_t wait_ms)
  490. {
  491.   // Bat -> EME -> EM
  492.   if(currentLED < NUM_LEDS_EME_BATTERY)
  493.   {
  494.     EME_Battery[NUM_LEDS_EME_BATTERY - currentLED - 1] = CURRENT_COLOR;
  495.   }
  496.   else if(currentLED < NUM_LEDS_EME_BATTERY + NUM_LEDS_EME_EM)
  497.   {
  498.     EME_EM[currentLED - NUM_LEDS_EME_BATTERY] = CURRENT_COLOR;
  499.   }
  500.   else if(currentLED < NUM_LEDS_EME_BATTERY + NUM_LEDS_EME_EM + NUM_LEDS_EME_EKK)
  501.   {
  502.     EME_EKK[currentLED - NUM_LEDS_EME_BATTERY - NUM_LEDS_EME_EM] = CURRENT_COLOR;
  503.   }
  504.   else
  505.   {
  506.     clearAllLEDs();
  507.     currentLED = -1;
  508.   }
  509.   currentLED++;
  510.   delay(wait_ms);
  511. }
  512.  
  513.  
  514.  
  515. void clearLEDs(CRGB leds[], uint16_t num_leds)
  516. {
  517.   for(uint16_t i=0; i  < num_leds; i++)
  518.   {
  519.     leds[i] = CRGB::Black;
  520.   }
  521. }
  522.  
  523. void clearAllLEDs()
  524. {  
  525.   clearLEDs(socket_hood, NUM_LEDS_SOCKET_HOOD);
  526.   clearLEDs(hood_KLE_AC, NUM_LEDS_HOOD_KLE_AC);
  527.   clearLEDs(KLE_AC_KLE_DC, NUM_LEDS_KLE_AC_KLE_DC);
  528.   clearLEDs(hood_KLE_DC, NUM_LEDS_HOOD_KLE_DC);
  529.  
  530.   clearLEDs(KLE_EME_DC, NUM_LEDS_KLE_EME_DC);
  531.   clearLEDs(KLE_EME_AC, NUM_LEDS_KLE_EME_AC);
  532.  
  533.   clearLEDs(EME_Battery, NUM_LEDS_EME_BATTERY);
  534.   clearLEDs(EME_EDH, NUM_LEDS_EME_EDH);
  535.   clearLEDs(EME_EKK, NUM_LEDS_EME_EKK);
  536.   clearLEDs(EME_EM, NUM_LEDS_EME_EM);
  537.   clearLEDs(CHASSIS, NUM_LEDS_CHASSIS);
  538. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement