// https://forum.arduino.cc/t/digital-hourglass/1177746/
// https://arduinoplusplus.wordpress.com/2023/11/19/led-matrix-hourglass-timer/#more-11996
#include <FastLED.h>
#define DATA_PIN 2
#define NUM_LEDS 128
#define BTTN_PIN 3
int counter;
CRGB leds[NUM_LEDS];
void setup() {
Serial.begin(115200); // for debug
pinMode(BTTN_PIN, INPUT_PULLUP); // change direction
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
FastLED.show();
// randomSeed(analogRead(0)); // for future use
for (int i = 0; i < NUM_LEDS / 2; i++) { // only color top square
leds[i] = CRGB(CRGB::CRGB::DeepSkyBlue);
}
FastLED.show();
// pixels falling out of top square
for (int i = 0; i < NUM_LEDS / 2; i += 9) {
// counter++; // LED counter
leds[i] = CRGB(CRGB::Black);
FastLED.show();
delay(250); // visual
if (i > 0)
leds[i] = CRGB(CRGB::CRGB::DeepSkyBlue);
FastLED.show();
}
// pixels falling into bottom square
for (int i = NUM_LEDS / 2 + .5; i < NUM_LEDS; i += 9) {
// counter++; // LED counter
leds[i] = CRGB(CRGB::CRGB::DeepSkyBlue);
FastLED.show();
delay(250);
if ((i > 0) && (i < NUM_LEDS-1))
leds[i] = CRGB(CRGB::Black);
FastLED.show();
}
}
void loop() {}
/*
(line 1 has 1 LED)
LED #1 location in each square is 0,0
(line 2 has 2 LEDs)
LED 2 = 1, 0
LED 3 = 0, 1
(line 3 has 3 LEDs)
LED 4 = 2, 0
LED 5 = 1,1
LED 6 = 0, 2
(line 4)
7 = 3, 0
8 = 2, 1
9 = 1, 2
10 = 0, 3
See the pattern?
Next line number (L) increases by 1 (toward a MAX of 7)
First LED in line number is (L-1, 0)
Next LEDs - "x" decreases toward 0, "y" increases to L-1
Last LED in line number is (0, L-1)
After you get midway (7,0) (1, 6) (2, 5) (3, 4) (4, 3) (5, 2) ( (6, 1) (0,7)... decrease the number of "x,y" pairs
(line 14 has 2 LEDs (7, 6)(6, 7)
(line 15 has 1 LED (7,7)
Each time you set "x, y" to OFF on the top square, you set "x, y" ON on the bottom square.
*/