#include <IRremote.h>
#include <LedControl.h> // Include the library for MAX7219
int numDotsHorizontal = 0;
int numDotsVertical = 0;
#define IR_RECEIVE_PIN 5
#define IR_BUTTON_RIGHT_ARROW 144
#define IR_BUTTON_LEFT_ARROW 224
#define IR_BUTTON_UP_ARROW 145
#define IR_BUTTON_BOTTOM_ARROW 225
LedControl lc = LedControl(12, 11, 10, 1); // Initialize the MAX7219 with appropriate pins
const int numRows = 8; // Number of rows in the LED matrix
void setup() {
// Initialize MAX7219
lc.shutdown(0, false);
lc.setIntensity(0, 8);
lc.clearDisplay(0);
Serial.begin(9600);
// Initialize the IR receiver
IrReceiver.begin(IR_RECEIVE_PIN);
// Rest of your setup code...
}
void loop() {
if (IrReceiver.decode()) {
IrReceiver.resume();
int command = IrReceiver.decodedIRData.command;
processIRCommand(command);
}
}
void processIRCommand(int command) {
// Handle right arrow button
if (command == IR_BUTTON_RIGHT_ARROW) {
numDotsHorizontal++;
drawDots(numDotsHorizontal, true); // true for horizontal
Serial.println(numDotsHorizontal);
}
// Handle left arrow button
if (command == IR_BUTTON_LEFT_ARROW) {
numDotsHorizontal--;
if (numDotsHorizontal < 0)
numDotsHorizontal = 0;
drawDots(numDotsHorizontal, true); // true for horizontal
}
// Handle up arrow button
if (command == IR_BUTTON_UP_ARROW) {
numDotsVertical++;
drawDots(numDotsVertical, false); // false for vertical
}
// Handle bottom arrow button
if (command == IR_BUTTON_BOTTOM_ARROW) {
numDotsVertical--;
if (numDotsVertical < 0)
numDotsVertical = 0;
drawDots(numDotsVertical, false); // false for vertical
}
}
void drawDots(int num, bool isHorizontal) {
lc.clearDisplay(0);
// Draw dots based on the desired pattern
for (int i = 0; i < num; i++) {
if (isHorizontal) {
int middleRow = numRows / 2;
lc.setLed(0, middleRow, middleRow - i, true);
} else {
lc.setLed(0, i, i, true);
}
}
}