int Data_pin = 2;
int Latch_pin = 4;//for 595 only
Int Clock_pin = 3;
int digits [10][8]{
{1,1,1,1,1,1,0,0}, //dig.0
{0,1,1,0,0,0,0,0}, //dig.1
{1,1,0,1,1,0,1,0}, //dig.2
{1,1,1,1,0,0,1,0}, //dig.3
{0,1,1,0,0,1,1,0}, //dig.4
{1,0,1,1,0,1,1,0}, //dig.5
{1,0,1,1,1,1,1,0}, //dig.6
{1,1,1,0,0,0,0,0}, //dig.7
{1,1,1,1,1,1,1,0}, //dig.8
{1,1,1,1,0,1,1,0}, //dig.9
};
void setup() {
pinMode(Data_pin, OUTPUT);
pinMode(Latch_pin, OUTPUT);
pinMode(Clock_pin, OUTPUT);
}
void DisplayDigit(int Digit){
// below line is needed for 74HC595
//digitalWrite(Latch_pin, LOW);
for (int i = 7; i>=0; i--){
digitalWrite(Clock_pin,LOW);
digitalWrite(Data_pin,!digits[Digit][i]);
digitalWrite(Clock_pin,HIGH);
delay(100);
}
// below line is needed for 74HC595
//digitalWrite(Latch_pin, HIGH);
}
void loop() {
for (int i=0;i<10;i++){
DisplayDigit(i);
delay(800);
}
}
Comments