// LM - LED Progress Bar - Test Rig // https://www.amazon.com/gp/product/B07BJ8ZGP7/ref=oh_aui_detailpage_o01_s00?ie=UTF8&psc=1 // // Lloyd Milligan, September 2018 // Progress bar LED pins - R, R, Y, Y, Y, G, G, G, G, G const int LED[10] = {12, 11, 10, 9, 8, 7, 6, 5, 4, 3}; // Timing - const int T1 = 100; // Delay between each LED const int T2 = 500; // Delay between each sequence const int T3 = 0; // Stay-on time for brightness adjustment void setup() { initDisplay(); displayOff(); } void loop() { // Scroll up and down, cumulatively and discretely int i; for (i=1; i<=10; i++) { displayCumulative(i); delay(T1); } delay(T3); for (i=10; i>0; i--) { displayCumulative(i); delay(T1); } pause(T2); for (i=1; i<=10; i++) { displayDiscrete(i); delay(T1); } for (i=10; i>0; i--) { displayDiscrete(i); delay(T1); } pause(T2); } void initDisplay() { for (int i=0; i<10; i++) pinMode(LED[i], OUTPUT); } void displayOff() { for (int i=0; i<10; i++) digitalWrite(LED[i], LOW); } void displayCumulative(int value) { // value = 0 means OFF // value = 1 to 10 causes LEDs to illuminate cumulatively from red end displayOff(); if (value < 0) value = 0; if (value == 0) return; if (value > 10) value = 10; for (int i=0; i 10) value = 10; digitalWrite(LED[--value], HIGH); } void pause(int ms) { displayOff(); delay(ms); }