byte a = 3;
byte b = 4;
byte c = 5;
byte d = 6;
byte e = 7;
byte f = 8;
byte g = 9;
byte decimal = 2;
byte x = 12, y = 11, z = 10;
byte button_add, button_minus, button_off, asc, desc;
void setup() {
pinMode(x, INPUT);
pinMode(y, INPUT);
pinMode(z, INPUT);
pinMode(decimal, OUTPUT);
pinMode(a, OUTPUT);
pinMode(b, OUTPUT);
pinMode(c, OUTPUT);
pinMode(d, OUTPUT);
pinMode(e, OUTPUT);
pinMode(f, OUTPUT);
pinMode(g, OUTPUT);
}
void displayZero() { //to display 0;
digitalWrite(decimal, LOW);
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, HIGH);
}
void displayOne() { //to display 1
digitalWrite(decimal, LOW);
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
}
void displayTwo() { //to display 2
digitalWrite(decimal, LOW);
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
digitalWrite(g, LOW);
}
void displayThree() { //to display 3
digitalWrite(decimal, LOW);
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, LOW);
}
void displayFour() { //to display 4
digitalWrite(decimal, LOW);
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
}
void displayFive() { //to display 5
digitalWrite(decimal, LOW);
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, HIGH);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
}
void displaySix() { //to display 6
digitalWrite(decimal, LOW);
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
}
void displaySeven() { //to display 7
digitalWrite(decimal, LOW);
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
}
void displayEight() { //to display 8
digitalWrite(decimal, LOW);
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
}
void displayNine() { //to display 9
digitalWrite(decimal, LOW);
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, HIGH);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
}
void stop() { //to display nothing
digitalWrite(decimal, HIGH);
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
}
void loop() {
main:
stop();
asc = 0; //initialization
desc = 9; //initialization
button_add = digitalRead(x);
button_minus = digitalRead(y);
if (button_add == 0 || button_minus == 0) { //green button or blue button is pressed
goto red_button;
}
goto main;
red_button:
button_off = digitalRead(z);
if (digitalRead(button_off) == 0) { //red button is pressed
stop();
if (button_add == 0) { //green button is pressed from being stopped
goto ascending;
}
else { //blue button is pressed from being stopped
goto descending;
}
}
goto main;
delayLoopAsc:
for (int l1 = 0; l1 <= 499; l1++) { //500 milliseconds
button_off = digitalRead(z);
button_minus = digitalRead(y);
if (button_off == 0 || button_minus == 0) { //red button or blue button is pressed
goto main;
}
delay(1); //delay for 1ms
}
asc = asc + 1; //counter increment for every loop
goto ascending;
delayLoopDesc:
for (int l1 = 0; l1 <= 499; l1++) { //500 milliseconds
button_off = digitalRead(z);
button_add = digitalRead(x);
if (button_off == 0 || button_add == 0) { //red button or green button is pressed
goto main;
}
delay(1); //delay for 1ms
}
desc = desc - 1; //counter decrement for every loop
goto descending;
ascending: //tells what number will be displayed from 0 to 9
if (asc == 0) {
displayZero();
}
else if (asc == 1) {
displayOne();
}
else if (asc == 2) {
displayTwo();
}
else if (asc == 3) {
displayThree();
}
else if (asc == 4) {
displayFour();
}
else if (asc == 5) {
displayFive();
}
else if (asc == 6) {
displaySix();
}
else if (asc == 7) {
displaySeven();
}
else if (asc == 8) {
displayEight();
}
else if (asc == 9) {
displayNine();
asc = -1; //counter will reset to -1
}
goto delayLoopAsc; //will perform loop for ascending
descending: //tells what number will be displayed from 9 to 0
if (desc == 9) {
displayNine();
}
else if (desc == 8) {
displayEight();
}
else if (desc == 7) {
displaySeven();
}
else if (desc == 6) {
displaySix();
}
else if (desc == 5) {
displayFive();
}
else if (desc == 4) {
displayFour();
}
else if (desc == 3) {
displayThree();
}
else if (desc == 2) {
displayTwo();
}
else if (desc == 1) {
displayOne();
}
else if (desc == 0) {
displayZero();
desc = 10; //counter will reset to 10
}
goto delayLoopDesc; //will perform loop for descending
}