Question: will this run? const int segmentPins [ ] = { 2 , 3 , 4 , 5 , 6 , 7 , 8 , 1

will this run? const int segmentPins[]={2,3,4,5,6,7,8,10}; // Pins for segments (A to G, DP)
const int digitPins[]={9,11,12,13}; // Pins for digit control
const int countdownDuration =10; // Set the countdown duration in seconds
void setup(){
// Set all segment and digit pins as OUTPUT
for (int i =0; i <8; i++){
pinMode(segmentPins[i], OUTPUT);
}
for (int i =0; i <4; i++){
pinMode(digitPins[i], OUTPUT);
}
}
void loop(){
// Countdown loop
for (int count = countdownDuration; count >=0; count--){
displayNumber(count);
delay(1000); //1-second delay
}
}
void displayNumber(int num){
// Display a number on the 7-segment display
const byte numMap[]={
B11111100,//0
B01100000,//1
B11011010,//2
B11110010,//3
B01100110,//4
B10110110,//5
B10111110,//6
B11100000,//7
B11111110,//8
B11110110//9
};
for (int i =0; i <4; i++){
// Enable the corresponding digit
digitalWrite(digitPins[i], LOW);
// Set the segments based on the number to be displayed
for (int j =0; j <8; j++){
digitalWrite(segmentPins[j], bitRead(numMap[num], j));
}
delay(1); // A short delay to make the display stable
// Turn off the segments for the next iteration
for (int j =0; j <8; j++){
digitalWrite(segmentPins[j], HIGH);
}
// Disable the digit for the next iteration
digitalWrite(digitPins[i], HIGH);
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!