#include "Arduino_LED_Matrix.h"
ArduinoLEDMatrix matrix;
const int buttonPin = 2; // Digital pin for the button
const int relayControlPin = 9; // Digital pin to control the relay module
const uint32_t happy[] = { //LED Matrix
0x19819,
0x80000001,
0x81f8000
};
const uint32_t heart[] = { //LED Matrix
0x3184a444,
0x44042081,
0x100a0040
};
const uint32_t onletter []= { //LED Matrix
0x7a24b,
0x24aa4ae4,
0xa27a2000,
66
};
const uint32_t offletter [] = { //LED Matrix
0xef7a8,
0x4ae7a84a,
0x84e84000,
66
};
const uint32_t rapid[] = { //LED Matrix
0xdddbbb77,
0x7eef777b,
0xbbdddeee,
66
};
unsigned long lastButtonPressTime = 0; // Variable to store the time of the last button press
unsigned long debounceTime = 500; // Debounce time in milliseconds
unsigned long relayInactiveTime = 3000; // Time in milliseconds to consider the button inactive
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
pinMode(relayControlPin, OUTPUT);
digitalWrite(relayControlPin, LOW); // Set initial state of the relay (OFF)
Serial.begin(115200); //LED Matrix
matrix.begin();
}
void loop() {
int buttonState = digitalRead(buttonPin);
// Check if the button is pressed (LOW state) with debounce
if (buttonState == LOW && millis() - lastButtonPressTime > debounceTime) {
// Button pressed, activate the relay
digitalWrite(relayControlPin, HIGH);
lastButtonPressTime = millis();
matrix.loadFrame(rapid); //LED Matrix
delay(0);
}
// Check if the button is not pressed for 5 seconds
if (millis() - lastButtonPressTime > relayInactiveTime) {
// Button not pressed for 5 seconds, activate the relay
digitalWrite(relayControlPin, HIGH);
matrix.loadFrame(onletter); //LED Matrix
delay(500);
} else {
// Button is being pressed, turn off the relay
digitalWrite(relayControlPin, LOW);
matrix.loadFrame(offletter); //LED Matrix
delay(500);
}
}