#include <LedControl.h>
const int numberOfMatrices = 1; // Change this if you have more matrices
const int dataPin = 12; // Connect to the DIN pin on the module
const int clkPin = 11; // Connect to the CLK pin on the module
const int csPin = 10; // Connect to the CS pin on the module
LedControl lc = LedControl(dataPin, clkPin, csPin, numberOfMatrices);
void setup() {
lc.shutdown(0, false); // Wake up the display
lc.setIntensity(0, 8); // Set brightness (adjust as needed)
lc.clearDisplay(0); // Clear the display initially
}
void loop() {
simulateLightning();
delay(random(2000, 5000)); // Adjust delay between lightning flashes
}
void simulateLightning() {
int flashCount = random(2, 5); // Adjust the number of flashes per lightning
for (int i = 0; i < flashCount; i++) {
lc.clearDisplay(0); // Clear the display
delay(random(50, 200)); // Delay for a short time
displayRandomPixels(); // Display random pixels to simulate lightning
delay(random(50, 200)); // Delay again
lc.clearDisplay(0); // Clear the display
delay(random(200, 800)); // Delay between flashes
}
}
void displayRandomPixels() {
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
if (random(2) == 1) {
lc.setLed(0, i, j, true); // Turn on a random LED
}
}
}
}