You are on page 1of 2

//code điều khiển led 7 đoạn bằng nút nhấn

const int Pins[8]= {8,9,11,12,13,7,6,10};


int buttonPin = 3;
int i=0;
const byte numberal[10]={
B00111111,
B00000110,
B01011011,
B01001111,
B01100110,
B01101101,
B01111101,
B00000111,
B01111111,
B01101111};
void setup()
{
for (int vitri =0; vitri <8; vitri++)
{
pinMode(Pins[vitri],OUTPUT);
digitalWrite(Pins[vitri],LOW);
}
pinMode(buttonPin, INPUT_PULLUP);
Hienthiso(0);
}
void loop()
{
if(digitalRead(buttonPin)==LOW)
{
i=i+1;
while(digitalRead(buttonPin)==0)
delay(200);
if(i==10)
i=0;
}
Hienthiso(i);
}
void Hienthiso(int number)
{
bool x;
for(int s = 0; s<8; s++)
{
x= bitRead(numberal[number],s);
digitalWrite(Pins[s],x);
}
}

You might also like