/*
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// # # # # # ###### ####### ####### # #######
// ## ## # # ## # # # # # # # # #
// # # # # # # # # # # # # # # # # #
// # # # # # # # # # # # # # # # #####
// # # ####### # # # # # # # # ####### #
// # # # # # ## # # # # # # # #
// # # # # # # ###### ####### ####### # # #
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
// Stacker Game Code
#include <Adafruit_NeoPixel.h>
#define PIN_LED 9
#define TOTAL_LED 8
uint32_t waktu = 0;
uint16_t index_led = 0;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(TOTAL_LED, PIN_LED, NEO_GRB + NEO_KHZ800);
void setup()
{
Serial.begin(9600);
Serial.println("STACKER MATRIX MAX 7219");
strip.begin();
strip.setBrightness(255);
strip.show(); // Initialize all pixels to 'off
}
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if (WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if (WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
void loop()
{
rainbowCycle(20);
}
void rainbowCycle(uint8_t wait) {
static uint16_t j = 0; // Variabel indeks siklus warna
// Hanya update jika interval waktu telah berlalu
if (millis() - waktu >= wait) {
waktu = millis();
while (index_led < strip.numPixels()) {
strip.setPixelColor(index_led, Wheel(((index_led * 256 / strip.numPixels()) + j) & 255));
index_led++;
}
strip.show();
index_led =0;
j++; // Increment siklus
if (j >= 256 * 5) { // Reset setelah 5 siklus
j = 0;
}
}
}