const int dataPin = 9; // 数据引脚 (DS)
const int clockPin = 10; // 时钟引脚 (SH_CP)
const int latchPin = 11; // 锁存引脚 (ST_CP)
const byte disNum[11] = {
// 数码管各段状态定义(共阴极:1=亮,0=灭)
// abcdefgdp
0b11111100, //0
0b01100000, //1
0b11011010, //2
0b11110010, //3
0b01100110, //4
0b10110110, //5
0b10111110, //6
0b11100000, //7
0b11111110, //8
0b11110110, //9
0b00000001 //.
};
void setup() {
// put your setup code here, to run once:
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(latchPin, OUTPUT);
byte duan = 0b10110110;//5 //0表示选中
byte wei = 0b00000010;//位 1表示选中
digitalWrite(clockPin, LOW);
digitalWrite(latchPin, LOW);
}
void disPlayNumber(int n) { //1234
byte wei = 0b00000001;
while (n != 0) {
shiftOut(dataPin, clockPin, MSBFIRST, wei);
shiftOut(dataPin, clockPin, LSBFIRST, ~disNum[n%10]);
digitalWrite(latchPin, LOW); // 开始传输
digitalWrite(latchPin, HIGH); // 锁存数据
wei = (wei<<1);
n/=10;
delay(2);//可以不写 1~2
}
}
void loop() {
// put your main code here, to run repeatedly:
disPlayNumber(1234);
}
