将上面图片中的LED1~LED8换成7段数码管(A~G,DP)。
|
代码如下:
#define DATA 6//数字6号脚,连在移位寄存器的14号针脚上,通过arduino传输数据
#define LATCH 8//digital 8 to pin 12 on the 74HC595
#define CLOCK 10//digital 10 to pin 11 on the 74HC595 for clock
int number_LSB[]={252,96,218,242,102,182,190,224,254,246,238,62,156,122,158,142 };
void setup()
{
// put your setup code here, to run once:
pinMode(LATCH,OUTPUT);
pinMode(CLOCK,OUTPUT);
pinMode(DATA,OUTPUT);
}
void loop()
{
// put your main code here, to run repeatedly:
int i;
for(i=0;
i<16;
i++)
{
digitalWrite(LATCH,LOW);
shiftOut(DATA,CLOCK,LSBFIRST,number_LSB[i]+1);
//+1让小数点显示
digitalWrite(LATCH,HIGH);
delay(500);
}
}
数码管将从0~9A~F循环显示
这个例子中只用到了Arduino的三个针脚!!!!
喜欢文章,欢迎大家转发!!!
|