//We defin every pin of the ESP-32 with the segment of the display 7 segment.
const int a = 22;
const int b = 23;
const int c = 5;
const int d = 4;
const int e = 15;
const int f = 21;
const int g = 19;
const int dot = 18;
const int forward = 34;
const int backward = 35;
const int red = 32;
const int yallow = 33;
int counter;
void setup() {
// put your setup code here, to run once. In this way we say every pin is an OUTPUT
pinMode (a, OUTPUT);
pinMode (b, OUTPUT);
pinMode (c, OUTPUT);
pinMode (d, OUTPUT);
pinMode (e, OUTPUT);
pinMode (f,OUTPUT);
pinMode (g, OUTPUT);
pinMode (dot, OUTPUT);
pinMode(forward,INPUT);
pinMode(backward,INPUT);
pinMode(red, OUTPUT);
pinMode(yallow,OUTPUT);
}
//Every void is defining a number doing a HIGH or LOW to delay or not the segments
void zero()
{
digitalWrite(a,1);
digitalWrite(b,1);
digitalWrite(c,1);
digitalWrite(d,1);
digitalWrite(e,1);
digitalWrite(f,1);
digitalWrite(g,0);
digitalWrite(dot,1);
}
void one()
{
digitalWrite(a,0);
digitalWrite(b,1);
digitalWrite(c,1);
digitalWrite(d,0);
digitalWrite(e,0);
digitalWrite(f,0);
digitalWrite(g,0);
digitalWrite(dot,1);
}
void two()
{
digitalWrite(a,1);
digitalWrite(b,1);
digitalWrite(c,0);
digitalWrite(d,1);
digitalWrite(e,1);
digitalWrite(f,0);
digitalWrite(g,1);
digitalWrite(dot,1);
}
void three()
{
digitalWrite(a,1);
digitalWrite(b,1);
digitalWrite(c,1);
digitalWrite(d,1);
digitalWrite(e,0);
digitalWrite(f,0);
digitalWrite(g,1);
digitalWrite(dot,1);
}
void four()
{
digitalWrite(a,0);
digitalWrite(b,1);
digitalWrite(c,1);
digitalWrite(d,0);
digitalWrite(e,0);
digitalWrite(f,1);
digitalWrite(g,1);
digitalWrite(dot,1);
}
void five()
{
digitalWrite(a,1);
digitalWrite(b,0);
digitalWrite(c,1);
digitalWrite(d,1);
digitalWrite(e,0);
digitalWrite(f,1);
digitalWrite(g,1);
digitalWrite(dot,1);
}
void six()
{
digitalWrite(a,1);
digitalWrite(b,0);
digitalWrite(c,1);
digitalWrite(d,1);
digitalWrite(e,1);
digitalWrite(f,1);
digitalWrite(g,1);
digitalWrite(dot,1);
}
void seven()
{
digitalWrite(a,1);
digitalWrite(b,1);
digitalWrite(c,1);
digitalWrite(d,0);
digitalWrite(e,0);
digitalWrite(f,0);
digitalWrite(g,0);
digitalWrite(dot,1);
}
void eight()
{
digitalWrite(a,1);
digitalWrite(b,1);
digitalWrite(c,1);
digitalWrite(d,1);
digitalWrite(e,1);
digitalWrite(f,1);
digitalWrite(g,1);
digitalWrite(dot,1);
}
void nine()
{
digitalWrite(a,1);
digitalWrite(b,1);
digitalWrite(c,1);
digitalWrite(d,1);
digitalWrite(e,0);
digitalWrite(f,1);
digitalWrite(g,1);
digitalWrite(dot,1);
}
void swich(int a) //Defining the cases with numers to do an array in the "void loop()"
{
switch(a)
{
case 0:
zero ();
break;
case 1:
one ();
break;
case 2:
two();
break;
case 3:
three();
break;
case 4:
four();
break;
case 5:
five();
break;
case 6:
six();
break;
case 7:
seven ();
break;
case 8:
eight();
break;
case 9:
nine();
break;
}
}
void loop() {
if(counter >9){counter =0;}
if(digitalRead(forward)==1){counter ++;
digitalWrite(red,1);
delay(300);
digitalWrite(red,0);}
if (digitalRead(backward)== 1){counter --;
digitalWrite(yallow,1);
delay(300);
digitalWrite(yallow,0);}
switch(counter);
}
byte pin[] = {15,2,4,5,18,19,21}; // Seven segment pin is connected to Digital pin 15,2,4,5,18,19,21 to a,b,c,d,e,f,g
const byte count[10] = { // this is data code for Seven segment, defining every number in order with the letter.
//GFEDCBA
B00111111, //0
B00000110, // 1
B01011011, // 2
B01001111, //3
B01100110, //4
B01101101, //5
B01111101, //6
B00000111, //7
B01111111, //8
B01101111, //9
};
void setup() {
pinMode(pin[0], OUTPUT); // every pin is output. So we order the numbers to do an array
pinMode(pin[1], OUTPUT);
pinMode(pin[2], OUTPUT);
pinMode(pin[3], OUTPUT);
pinMode(pin[4], OUTPUT);
pinMode(pin[5], OUTPUT);
pinMode(pin[6], OUTPUT);
}
void loop() {
for(int i = 0; i < 10; i++){ // printing the number on seven segment
SevenSeg(count[i]);
delay(1000);
}
}
void SevenSeg(byte Bit) { // sending data on each pin
for(int i=0; i < 8; i++)
digitalWrite(pin[i],bitRead(Bit,i)); //Delay every segment
}