const int digitPins[] = { 2, 15, 14 }; // Common anode digit pins
const int segmentPins[] = { 12, 4, 19, 26, 27, 13, 18, 25 }; // 7-segment segment pins
// Define common anode 7-segment patterns for digits 0-9
const byte digitPatterns[] = {
B00111111, // 0
B00000110, // 1
B01011011, // 2
B01001111, // 3
B01100110, // 4
B01101101, // 5
B01111101, // 6
B00000111, // 7
B01111111, // 8
B01101111, // 9
B00111001, // C 10
B01110011, // P 11
B00111110, // U 12
B00111111, // O 13
B01110001, // F 14
B01111001, // E 15
B00111000, // L 16
};
const int displayInterval = 1000; // Update every 1000 milliseconds (1 second)
unsigned long previousMillis = 0;
int count = 1;
int hundreds = 0;
int tens = 0;
int ones = 0;
int message = 0;
void setup() {
Serial.begin(96000);
for (int i = 0; i < 3; i++) {
pinMode(digitPins[i], OUTPUT);
digitalWrite(digitPins[i], LOW); // Common anode, so set LOW initially to turn off
}
for (int i = 0; i < 8; i++) {
pinMode(segmentPins[i], OUTPUT);
digitalWrite(segmentPins[i], HIGH); // Turn off all segments initially
}
}
void loop() {
unsigned long currentMillis = millis();
displayMessage(message);
if (currentMillis - previousMillis >= displayInterval) {
previousMillis = currentMillis;
displayMessage(message);
message++;
if (message > 2)
message = 0;
}
}
void displayCount(int count) {
hundreds = count / 100;
tens = (count / 10) % 10;
ones = count % 10;
displayDigit(0, ones);
delay(1);
displayDigit(1, tens);
delay(1);
displayDigit(2, hundreds);
delay(1);
}
void displayMessage(int message) {
const int messagePatterns[][3] = {
{12, 11, 10}, // Message 0: "CPU"
{14, 14, 13}, // Message 1: "FEL"
{16, 15, 14} // Message 2: "OFF"
};
for (int digit = 0; digit < 3; digit++) {
displayDigit(digit, messagePatterns[message][digit]);
delay(1);
}
}
void displayDigit(int digit, int value) {
for (int i = 0; i < 3; i++)
digitalWrite(digitPins[i], LOW);
for (int segment = 0; segment < 8; segment++)
digitalWrite(segmentPins[segment], HIGH);
digitalWrite(digitPins[digit], HIGH);
for (int segment = 0; segment < 8; segment++) {
if (bitRead(digitPatterns[value], segment)) {
digitalWrite(segmentPins[segment], LOW);
}
}
}