const int a = 23; // For displaying segment "a"
const int b = 22; // For displaying segment "b"
const int c = 4; // For displaying segment "c"
const int d = 5; // For displaying segment "d"
const int e = 18; // For displaying segment "e"
const int f = 2; // For displaying segment "f"
const int g = 21; // For displaying segment "g"
bool bPress = false;
const int buttonPin = 27;
//Variables will change
int buttonPushCounter = 0;
int buttonState = 0;
int lastButtonState = 0;
void setup()
{
pinMode(a,OUTPUT); // A
pinMode(b,OUTPUT); // B
pinMode(c,OUTPUT); // C
pinMode(d,OUTPUT); // D
pinMode(e,OUTPUT); // E
pinMode(f,OUTPUT); // F
pinMode(g,OUTPUT); // G
pinMode(buttonPin,INPUT_PULLUP);
Serial.begin(9600);
displayDigit(buttonPushCounter);
}
void loop()
{
buttonState = digitalRead(buttonPin);
//compare the buttonState to its previous state
if(buttonState != lastButtonState)
{
//if the state has changed,increment the counter
if(buttonState == LOW)
{
//if the current state is HIGH then the button went from off to on
bPress = true;
buttonPushCounter++;
if(buttonPushCounter>9) buttonPushCounter = 0;
Serial.println("on");
}
else{
//if the current state is LOW then the button went from on to off
Serial.println("off");
}
//Delay a little bit to avoid bouncing
delay(50);
}
//save the current state as the last state,for ext time through the loop
lastButtonState = buttonState;
if(bPress ){
turnoff();
displayDigit(buttonPushCounter);
}
}
void displayDigit(int digit)
{
//condition for displaying segment a
if(digit != 1 && digit !=4)
digitalWrite(a,HIGH);
//condition for displaying segment b
if(digit != 5 && digit != 6)
digitalWrite(b,HIGH);
//condition for displaying segment c
if(digit != 2)
digitalWrite(c,HIGH);
//condition for displaying segment d
if(digit != 1 && digit !=4 && digit != 7)
digitalWrite(d,HIGH);
//condition for displaying segment e
if(digit == 2 || digit ==6 || digit ==8 || digit == 0)
digitalWrite(e,HIGH);
//condition for displaying segment f
if(digit != 1 && digit !=2 && digit != 3 && digit != 7)
digitalWrite(f,HIGH);
//condition for displaying segment g
if(digit != 0 && digit !=1 && digit!= 7)
digitalWrite(g,HIGH);
}
void turnoff()
{
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
}
esp:VIN
esp:GND.2
esp:D13
esp:D12
esp:D14
esp:D27
esp:D26
esp:D25
esp:D33
esp:D32
esp:D35
esp:D34
esp:VN
esp:VP
esp:EN
esp:3V3
esp:GND.1
esp:D15
esp:D2
esp:D4
esp:RX2
esp:TX2
esp:D5
esp:D18
esp:D19
esp:D21
esp:RX0
esp:TX0
esp:D22
esp:D23
sevseg1:COM.1
sevseg1:COM.2
sevseg1:A
sevseg1:B
sevseg1:C
sevseg1:D
sevseg1:E
sevseg1:F
sevseg1:G
sevseg1:DP
btn1:1.l
btn1:2.l
btn1:1.r
btn1:2.r