//using 8-channel relay board to control 7-segment display. Pin 1&5 are common ground.
//Decimal Point on SSD unused.
int Relay1 = 12; //pin 7 of SSD (A - topmost segment)
int Relay2 = 11; //pin 6 of SSD (B - topright segment)
int Relay3 = 10; //pin 4 of SSD (C - bottomright segment)
int Relay4 = 9; //pin 3 of SSD (D - bottommost segment)
int Relay5 = 8; //pin 2 of SSD (E - bottomleft segment)
int Relay6 = 7; //pin 9 of SSD (F - topleft segment)
int Relay7 = 6; //pin 10 of SSD (G - middle segment)
int Relay8 = 5; //for Pushbutton LED
int Buzz = 3; //onBoard Buzzer (PWM capable)
int LED = 13; //simulate Pushbutton LED
int Pushbutton = 2; //Big red pushbutton
void one()
{
digitalWrite(Relay1, HIGH);
digitalWrite(Relay2, LOW);
digitalWrite(Relay3, LOW);
digitalWrite(Relay4, HIGH);
digitalWrite(Relay5, HIGH);
digitalWrite(Relay6, HIGH);
digitalWrite(Relay7, HIGH);
}
void two()
{
digitalWrite(Relay1, LOW);
digitalWrite(Relay2, LOW);
digitalWrite(Relay3, HIGH);
digitalWrite(Relay4, LOW);
digitalWrite(Relay5, LOW);
digitalWrite(Relay6, HIGH);
digitalWrite(Relay7, LOW);
}
void three()
{
digitalWrite(Relay1, LOW);
digitalWrite(Relay2, LOW);
digitalWrite(Relay3, LOW);
digitalWrite(Relay4, LOW);
digitalWrite(Relay5, HIGH);
digitalWrite(Relay6, HIGH);
digitalWrite(Relay7, LOW);
}
void four()
{
digitalWrite(Relay1, HIGH);
digitalWrite(Relay2, LOW);
digitalWrite(Relay3, LOW);
digitalWrite(Relay4, HIGH);
digitalWrite(Relay5, HIGH);
digitalWrite(Relay6, LOW);
digitalWrite(Relay7, LOW);
}
void five()
{
digitalWrite(Relay1, LOW);
digitalWrite(Relay2, HIGH);
digitalWrite(Relay3, LOW);
digitalWrite(Relay4, LOW);
digitalWrite(Relay5, HIGH);
digitalWrite(Relay6, LOW);
digitalWrite(Relay7, LOW);
}
void six()
{
digitalWrite(Relay1, LOW);
digitalWrite(Relay2, HIGH);
digitalWrite(Relay3, LOW);
digitalWrite(Relay4, LOW);
digitalWrite(Relay5, LOW);
digitalWrite(Relay6, LOW);
digitalWrite(Relay7, LOW);
}
void seven()
{
digitalWrite(Relay1, LOW);
digitalWrite(Relay2, LOW);
digitalWrite(Relay3, LOW);
digitalWrite(Relay4, HIGH);
digitalWrite(Relay5, HIGH);
digitalWrite(Relay6, HIGH);
digitalWrite(Relay7, HIGH);
}
void eight()
{
digitalWrite(Relay1, LOW);
digitalWrite(Relay2, LOW);
digitalWrite(Relay3, LOW);
digitalWrite(Relay4, LOW);
digitalWrite(Relay5, LOW);
digitalWrite(Relay6, LOW);
digitalWrite(Relay7, LOW);
}
void nine()
{
digitalWrite(Relay1, LOW);
digitalWrite(Relay2, LOW);
digitalWrite(Relay3, LOW);
digitalWrite(Relay4, LOW);
digitalWrite(Relay5, HIGH);
digitalWrite(Relay6, LOW);
digitalWrite(Relay7, LOW);
}
void zero()
{
digitalWrite(Relay1, LOW);
digitalWrite(Relay2, LOW);
digitalWrite(Relay3, LOW);
digitalWrite(Relay4, LOW);
digitalWrite(Relay5, LOW);
digitalWrite(Relay6, LOW);
digitalWrite(Relay7, HIGH);
}
void dash()
{
digitalWrite(Relay1, HIGH);
digitalWrite(Relay2, HIGH);
digitalWrite(Relay3, HIGH);
digitalWrite(Relay4, HIGH);
digitalWrite(Relay5, HIGH);
digitalWrite(Relay6, HIGH);
digitalWrite(Relay7, LOW);
digitalWrite(Buzz, HIGH);
delay(50);
digitalWrite(Buzz, LOW);
delay(100);
digitalWrite(Buzz, HIGH);
delay(50);
digitalWrite(Buzz, LOW);
}
void setup()
{
pinMode(Relay1, OUTPUT);
pinMode(Relay2, OUTPUT);
pinMode(Relay3, OUTPUT);
pinMode(Relay4, OUTPUT);
pinMode(Relay5, OUTPUT);
pinMode(Relay6, OUTPUT);
pinMode(Relay7, OUTPUT);
pinMode(Relay8, OUTPUT);
pinMode(Buzz, OUTPUT);
pinMode(LED, OUTPUT);
pinMode(Pushbutton, INPUT);
digitalWrite(Pushbutton, HIGH);
digitalWrite(Relay1, LOW);
digitalWrite(Relay2, LOW);
digitalWrite(Relay3, LOW);
digitalWrite(Relay4, LOW);
digitalWrite(Relay5, LOW);
digitalWrite(Relay6, LOW);
digitalWrite(Relay7, LOW);
digitalWrite(Relay8, HIGH);
}
void loop(){
dash();
delay(5000);
if (digitalRead(Pushbutton) == LOW){
nine();
digitalWrite(Relay8, LOW);
digitalWrite(Buzz, HIGH);
delay(1000);
digitalWrite(Buzz, LOW);
delay(3600000);
digitalWrite(Relay8, HIGH);
} else{
nine();
digitalWrite(Buzz, HIGH);
delay(50);
digitalWrite(Buzz, LOW);
delay(500);
}
if (digitalRead(Pushbutton) == LOW){
nine();
digitalWrite(Relay8, LOW);
digitalWrite(Buzz, HIGH);
delay(1000);
digitalWrite(Buzz, LOW);
delay(3600000);
digitalWrite(Relay8, HIGH);
} else{
nine();
delay(500);
}
if (digitalRead(Pushbutton) == LOW){
eight();
digitalWrite(Relay8, LOW);
digitalWrite(Buzz, HIGH);
delay(1000);
digitalWrite(Buzz, LOW);
delay(3600000);
digitalWrite(Relay8, HIGH);
} else{
eight();
digitalWrite(Buzz, HIGH);
delay(50);
digitalWrite(Buzz, LOW);
delay(500);
}
if (digitalRead(Pushbutton) == LOW){
eight();
digitalWrite(Relay8, LOW);
digitalWrite(Buzz, HIGH);
delay(1000);
digitalWrite(Buzz, LOW);
delay(3600000);
digitalWrite(Relay8, HIGH);
} else{
eight();
delay(500);
}
if (digitalRead(Pushbutton) == LOW){
seven();
digitalWrite(Relay8, LOW);
digitalWrite(Buzz, HIGH);
delay(1000);
digitalWrite(Buzz, LOW);
delay(3600000);
digitalWrite(Relay8, HIGH);
} else{
seven();
digitalWrite(Buzz, HIGH);
delay(50);
digitalWrite(Buzz, LOW);
delay(500);
}
if (digitalRead(Pushbutton) == LOW){
seven();
digitalWrite(Relay8, LOW);
digitalWrite(Buzz, HIGH);
delay(1000);
digitalWrite(Buzz, LOW);
delay(3600000);
digitalWrite(Relay8, HIGH);
} else{
seven();
delay(500);
}
if (digitalRead(Pushbutton) == LOW){
six();
digitalWrite(Relay8, LOW);
digitalWrite(Buzz, HIGH);
delay(1000);
digitalWrite(Buzz, LOW);
delay(3600000);
digitalWrite(Relay8, HIGH);
} else{
six();
digitalWrite(Buzz, HIGH);
delay(50);
digitalWrite(Buzz, LOW);
delay(500);
}
if (digitalRead(Pushbutton) == LOW){
six();
digitalWrite(Relay8, LOW);
digitalWrite(Buzz, HIGH);
delay(1000);
digitalWrite(Buzz, LOW);
delay(3600000);
digitalWrite(Relay8, HIGH);
} else{
six();
delay(500);
}
if (digitalRead(Pushbutton) == LOW){
five();
digitalWrite(Relay8, LOW);
digitalWrite(Buzz, HIGH);
delay(1000);
digitalWrite(Buzz, LOW);
delay(3600000);
digitalWrite(Relay8, HIGH);
} else{
five();
digitalWrite(Buzz, HIGH);
delay(50);
digitalWrite(Buzz, LOW);
delay(500);
}
if (digitalRead(Pushbutton) == LOW){
five();
digitalWrite(Relay8, LOW);
digitalWrite(Buzz, HIGH);
delay(1000);
digitalWrite(Buzz, LOW);
delay(3600000);
digitalWrite(Relay8, HIGH);
} else{
five();
delay(500);
}
if (digitalRead(Pushbutton) == LOW){
four();
digitalWrite(Relay8, LOW);
digitalWrite(Buzz, HIGH);
delay(1000);
digitalWrite(Buzz, LOW);
delay(3600000);
digitalWrite(Relay8, HIGH);
} else{
four();
digitalWrite(Buzz, HIGH);
delay(50);
digitalWrite(Buzz, LOW);
delay(500);
}
if (digitalRead(Pushbutton) == LOW){
four();
digitalWrite(Relay8, LOW);
digitalWrite(Buzz, HIGH);
delay(1000);
digitalWrite(Buzz, LOW);
delay(3600000);
digitalWrite(Relay8, HIGH);
} else{
four();
delay(500);
}
if (digitalRead(Pushbutton) == LOW){
three();
digitalWrite(Relay8, LOW);
digitalWrite(Buzz, HIGH);
delay(1000);
digitalWrite(Buzz, LOW);
delay(3600000);
digitalWrite(Relay8, HIGH);
} else{
three();
digitalWrite(Buzz, HIGH);
delay(50);
digitalWrite(Buzz, LOW);
delay(500);
}
if (digitalRead(Pushbutton) == LOW){
three();
digitalWrite(Relay8, LOW);
digitalWrite(Buzz, HIGH);
delay(1000);
digitalWrite(Buzz, LOW);
delay(3600000);
digitalWrite(Relay8, HIGH);
} else{
three();
delay(500);
}
if (digitalRead(Pushbutton) == LOW){
two();
digitalWrite(Relay8, LOW);
digitalWrite(Buzz, HIGH);
delay(1000);
digitalWrite(Buzz, LOW);
delay(3600000);
digitalWrite(Relay8, HIGH);
} else{
two();
digitalWrite(Buzz, HIGH);
delay(50);
digitalWrite(Buzz, LOW);
delay(500);
}
if (digitalRead(Pushbutton) == LOW){
two();
digitalWrite(Relay8, LOW);
digitalWrite(Buzz, HIGH);
delay(1000);
digitalWrite(Buzz, LOW);
delay(3600000);
digitalWrite(Relay8, HIGH);
} else{
two();
delay(500);
}
if (digitalRead(Pushbutton) == LOW){
one();
digitalWrite(Relay8, LOW);
digitalWrite(Buzz, HIGH);
delay(1000);
digitalWrite(Buzz, LOW);
delay(3600000);
digitalWrite(Relay8, HIGH);
} else{
one();
digitalWrite(Buzz, HIGH);
delay(50);
digitalWrite(Buzz, LOW);
delay(500);
}
if (digitalRead(Pushbutton) == LOW){
one();
digitalWrite(Relay8, LOW);
digitalWrite(Buzz, HIGH);
delay(1000);
digitalWrite(Buzz, LOW);
delay(3600000);
digitalWrite(Relay8, HIGH);
} else{
one();
delay(500);
}
if (digitalRead(Pushbutton) == LOW){
one();
digitalWrite(Relay8, LOW);
digitalWrite(Buzz, HIGH);
delay(1000);
digitalWrite(Buzz, LOW);
delay(3600000);
digitalWrite(Relay8, HIGH);
} else{
zero();
digitalWrite(Buzz, HIGH);
delay(1000);
digitalWrite(Buzz, LOW);
}
delay(900000);
}
Comments