#include #define NUM_DOTSTAR 5 #define PROGRESS_NUM_STATES 10 Adafruit_DotStar pixels( NUM_DOTSTAR, PIN_DOTSTAR_DATA, PIN_DOTSTAR_CLOCK, DOTSTAR_BRG ); boolean ledsShowingProgress = false; int ledProgress = 0; const uint32_t PROGRESS_BLUE = pixels.Color(0, 0, 255), PROGRESS_GREEN = pixels.Color(255, 0, 0), PROGRESS_RED = pixels.Color(0, 255, 0); // Which LEDs should be lit up for a given position in the progress. // This could be calculated, but I have memory to spare, and this is // easier at the moment. uint16_t ledProgressMap[PROGRESS_NUM_STATES] = { 0b00000, 0b00001, 0b00011, 0b00111, 0b01111, 0b11111, 0b11110, 0b11100, 0b11000, 0b10000 }; void initLeds() { pixels.begin(); pixels.show(); pixels.setBrightness(2); hideProgress(); } // Update LEDs to show loading, such as connecting to wifi void showProgress(uint32_t colour) { if(!ledsShowingProgress) { // Reset the progress display ledProgress = 0; ledsShowingProgress = true; } ledProgress = (ledProgress + 1) % PROGRESS_NUM_STATES; for(byte i = 0; i < NUM_DOTSTAR; i++) { boolean on = ((1 << i) & ledProgressMap[ledProgress]) > 0; pixels.setPixelColor( i, on ? colour : 0 ); } pixels.show(); } // Turn off the LEDs void hideProgress() { ledsShowingProgress = false; for(byte i = 0; i < NUM_DOTSTAR; i++) { pixels.setPixelColor(i, 0); } pixels.show(); } void showError() { pixels.fill(PROGRESS_RED); pixels.show(); }