#include "LedControl.h"
// Define the pin for the potentiometer input
const int potPin = A0;
// Define the threshold value for determining high or low
const int threshold = 512; // Adjust this value based on your needs
// Define the pins for the LED matrix
const int DIN = 12;
const int CS = 10;
const int CLK = 11;
// Create a LedControl object
LedControl lc = LedControl(DIN, CLK, CS, 1);
void setup() {
// Initialize serial communication at 9600 bits per second
Serial.begin(9600);
// Initialize the LED matrix
lc.shutdown(0, false); // Wake up the display
lc.setIntensity(0, 8); // Set brightness level (0 is min, 15 is max)
lc.clearDisplay(0); // Clear display register
}
void loop() {
// Read the value from the potentiometer
int potValue = analogRead(potPin);
// Print the potentiometer value for debugging (optional)
Serial.print("Potentiometer Value: ");
Serial.println(potValue);
// Determine if the input is high or low based on the threshold
if (potValue > threshold) {
displayNumber(1); // Display 1 if the input is high
} else {
displayNumber(2); // Display 2 if the input is low
}
// Add a small delay to stabilize the readings
delay(1);
}
// Function to display a number on the LED matrix
void displayNumber(int num) {
lc.clearDisplay(0); // Clear display register
byte num1[8] = {
B00011000,
B00111000,
B00011000,
B00011000,
B00011000,
B00011000,
B00111100,
B00000000
};
byte num2[8] = {
B00111100,
B01100110,
B00000110,
B00001100,
B00110000,
B01100000,
B01111110,
B00000000
};
byte *pattern;
if (num == 1) {
pattern = num1;
} else if (num == 2) {
pattern = num2;
}
for (int row = 0; row < 8; row++) {
lc.setRow(0, row, pattern[row]);
}
}