#include <MD_MAX72xx.h>
#include <ezButton.h>
#include "animations.h"
// Define the number of devices we have in the chain and the hardware interface
#define MAX_DEVICES 4
#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
#define CLK_PIN 18 // or SCK
#define DATA_PIN 23 // or MOSI
#define CS_PIN 5 // or SS
ezButton btnPlay(2);
void playAnimation();
// Create a new instance of the MD_MAX72XX library
MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
bool animationPlaying = false;
unsigned long lastMillis = 0;
const unsigned int frameRate = (25); // How fast animation plays (lower = faster)
bool btnToggle = false;
void setup() {
btnPlay.setDebounceTime(50);
mx.begin();
mx.control(MD_MAX72XX::INTENSITY, 1); // Set intensity level (0-15)
mx.clear();
}
void loop() {
btnPlay.loop();
unsigned long now = millis();
delay(10);
if(btnPlay.isPressed()) {
btnToggle = !btnToggle;
}
if (btnToggle == true) {
if (now - lastMillis >= frameRate){
animationPlaying = true;
lastMillis = now;
playAnimation();
} else {
animationPlaying = false;
}
}
}
void playAnimation() {
static byte currentFrame = 0;
if (animationPlaying == true) {
for (int ii = 0; ii < 32; ii++) {
mx.setColumn(ii, animation_01[currentFrame][ii]);
}
currentFrame++;
if (currentFrame >= sizeof(animation_01) / sizeof(animation_01[0])) {
currentFrame = 0;
}
}
}
Loading
esp32-devkit-v1
esp32-devkit-v1