#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW // Use PAROLA_HW for 8x8 matrix
#define MAX_DEVICES 4
#define CLK_PIN 13
#define DATA_PIN 11
#define CS_PIN 10
#define PIR_PIN 2 // PIR sensor pin
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
bool lastMotionState = false; // Flag to track the last motion state
void setup() {
Serial.begin(9600);
// Initialize LED Matrix
P.begin();
P.setIntensity(5); // Adjust brightness level (0-15)
P.displayClear(); // Clear the display at startup
// Initialize PIR sensor
pinMode(PIR_PIN, INPUT);
// Initially display "No Motion Detected"
P.displayText("No Motion", PA_CENTER, 50, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT); // Smooth scroll once
delay(2000); // Wait for a brief period before detecting motion
}
void loop() {
// Read PIR sensor state
int motionDetected = digitalRead(PIR_PIN);
if (motionDetected == HIGH && !lastMotionState) {
// Motion has been detected, update display to "Motion Detected"
Serial.println("Motion Detected!");
P.displayClear(); // Clear previous message
P.displayText("Motion Detected", PA_CENTER, 50, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT); // Smooth fast scroll
lastMotionState = true; // Update the state to motion detected
}
else if (motionDetected == LOW && lastMotionState) {
// No motion, update display to "No Motion"
Serial.println("No Motion");
P.displayClear(); // Clear previous message
P.displayText("No Motion", PA_CENTER, 50, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT); // Smooth fast scroll
lastMotionState = false; // Update the state to no motion detected
}
// Allow enough time for the display to update
if (P.displayAnimate()) {
// No reset needed here, let the text scroll naturally
}
delay(100); // Short delay for smooth performance
}