//Ali Al-Ghazw
#include "SevSeg.h"
#define RED 11 // Assuming RED LED is connected to GP11
#define YELLOW 12 // Assuming YELLOW LED is connected to GP12
#define GREEN 13 // Assuming GREEN LED is connected to GP13
#define DIGIT1 9 // Assuming DIGIT1 pin is connected to GP9 (if required)
SevSeg sevseg; // Create an instance of the SevSeg object
void setup() {
// Initialize the 7-segment display
byte numDigits = 1;
byte digitPins[] = {DIGIT1}; // Connect DIGIT1 pin to GP9 (if required)
byte segmentPins[] = {2, 3, 4, 5, 6, 7, 8}; // Segment pins: A, B, C, D, E, F, G
sevseg.begin(COMMON_ANODE, numDigits, digitPins, segmentPins);
sevseg.setBrightness(90);
pinMode(RED, OUTPUT); // Set the RED LED pin as output
pinMode(YELLOW, OUTPUT); // Set the YELLOW LED pin as output
pinMode(GREEN, OUTPUT); // Set the GREEN LED pin as output
pinMode(DIGIT1, OUTPUT); // Set the DIGIT1 pin as output (if required)
digitalWrite(DIGIT1, HIGH); // Activate the digit (if required) - for common anode, use HIGH
}
void displayCountdown(int seconds) {
for (int i = seconds; i >= 0; i--) {
unsigned long startMillis = millis();
while (millis() - startMillis < 1000) {
sevseg.setNumber(i);
sevseg.refreshDisplay(); // Must run repeatedly to display numbers correctly
delay(1); // Small delay to prevent locking up the processor
}
}
}
void loop() {
digitalWrite(GREEN, HIGH); // Turn on GREEN LED
displayCountdown(3); // Countdown from 3
digitalWrite(GREEN, LOW); // Turn off GREEN LED
digitalWrite(YELLOW, HIGH); // Turn on YELLOW LED
displayCountdown(1); // Countdown from 1
digitalWrite(YELLOW, LOW); // Turn off YELLOW LED
digitalWrite(RED, HIGH); // Turn on RED LED
displayCountdown(2); // Countdown from 2
digitalWrite(RED, LOW); // Turn off RED LED
digitalWrite(YELLOW, HIGH); // Turn on YELLOW LED
displayCountdown(1); // Countdown from 1
digitalWrite(YELLOW, LOW); // Turn off YELLOW LED
}