// Pin mapping for 7-segment display (for common cathode)
const int segmentPins[] = {2, 3, 4, 5, 6, 7, 8}; // A, B, C, D, E, F, G
const int digitPins[] = {9, 10, 11}; // DIG1, DIG2, DIG3
// Segment patterns for numbers 0-9
const byte digits[10] = {
B00111111, // 0
B00000110, // 1
B01011011, // 2
B01001111, // 3
B01100110, // 4
B01101101, // 5
B01111101, // 6
B00000111, // 7
B01111111, // 8
B01101111 // 9
};
void setupDisplay();
void displayNumber(int number);
//Different number for each digits------------------
/*
// Array to hold the numbers to display on each digit
int displayNumbers[4] = {1, 7, 9, 3}; // Change these numbers to whatever you want to display
void setup() {
setupDisplay(); // Call the setup function for the display
}
void loop() {
// Continuously display the numbers on each digit
displayNumbersOnAllDigits();
}
// Function to setup the display
void setupDisplay() {
// Set segment pins as output
for (int i = 0; i < 7; i++) {
pinMode(segmentPins[i], OUTPUT);
}
// Set digit pins as output
for (int i = 0; i < 4; i++) {
pinMode(digitPins[i], OUTPUT);
}
// Turn off all digits initially
for (int i = 0; i < 4; i++) {
digitalWrite(digitPins[i], HIGH); // HIGH turns off the digit (for common cathode)
}
}
// Function to display different numbers on each digit without turning off
void displayNumbersOnAllDigits() {
for (int i = 0; i < 4; i++) { // Loop through each digit
int number = displayNumbers[i]; // Get the number for the current digit
byte segments = digits[number]; // Get segment pattern for the number
// Set the segments for the current number
for (int j = 0; j < 7; j++) {
digitalWrite(segmentPins[j], (segments >> j) & 0x01); // Set segments
}
// Activate only the current digit
digitalWrite(digitPins[i], LOW); // LOW to turn on the current digit (for common cathode)
// Short delay to allow the digit to stay on (but very quick to simulate being always on)
delay(2); // 2ms delay should make it fast enough to appear as if all digits are on
// Turn off the current digit before moving to the next
digitalWrite(digitPins[i], HIGH); // HIGH turns off the digit
}
}
*/
//Set all digits to same number------------------
/*
// Variable to hold the number to display
int displayNumberToShow = 7; // Change this to the number you want to display
void setup() {
setupDisplay(); // Call the setup function for the display
}
void loop() {
// Display the specific number on all digits
displayNumber(displayNumberToShow);
delay(1000); // Delay for a second to see the number
}
// Function to setup the display
void setupDisplay() {
// Set segment pins as output
for (int i = 0; i < 7; i++) {
pinMode(segmentPins[i], OUTPUT);
}
// Set digit pins as output
for (int i = 0; i < 4; i++) {
pinMode(digitPins[i], OUTPUT);
}
// Turn off all digits initially
for (int i = 0; i < 4; i++) {
digitalWrite(digitPins[i], HIGH);
}
}
// Function to display the same number across all digits
void displayNumber(int number) {
byte segments = digits[number]; // Get segment pattern for the number
// Set the segments for the current number
for (int j = 0; j < 7; j++) {
digitalWrite(segmentPins[j], (segments >> j) & 0x01); // Set segments
}
// Activate all digits simultaneously to show the number
for (int i = 0; i < 4; i++) { // Display on all four digits
digitalWrite(digitPins[i], LOW); // LOW to turn on the current digit (for common cathode)
}
}
*/
//Count 1-9------------------
/*
// Variables to hold the count value
int count = 0;
void setup() {
// Set segment pins as output
for (int i = 0; i < 7; i++) {
pinMode(segmentPins[i], OUTPUT);
}
// Set digit pins as output
for (int i = 0; i < 4; i++) {
pinMode(digitPins[i], OUTPUT);
}
// Turn off all digits initially
for (int i = 0; i < 4; i++) {
digitalWrite(digitPins[i], HIGH);
}
}
void loop() {
// Display the count value on all digits
displayNumber(count);
// Wait for 1 second before updating the display
delay(1000);
// Increment the count and wrap around from 0 to 9
count = (count + 1) % 10;
}
// Function to display the same number across all digits
void displayNumber(int number) {
byte segments = digits[number]; // Get segment pattern for the number
// Turn off all digits before updating the current one
for (int j = 0; j < 4; j++) {
digitalWrite(digitPins[j], HIGH); // Turn off all digits
}
// Set the segments for the current number
for (int j = 0; j < 7; j++) {
digitalWrite(segmentPins[j], (segments >> j) & 0x01); // Set segments
}
// Activate all digits simultaneously to show the number
for (int i = 0; i < 4; i++) {
digitalWrite(digitPins[i], LOW); // LOW to turn on the current digit (for common cathode)
}
// Small delay to allow the display to be visible
delay(5);
}
*/