我想知道是否有可能让4位数的7段显示器更顺畅地显示数字,因为有时候它很难读取它(比图像显示的更难)。我可以在代码中执行某些操作吗?它来自中国的廉价展示,这是为什么?我使用移位寄存器(74hc595n)和显示器。感谢任何回复:)
我的4位7段显示器的图片
用于显示数字的arduino代码:
void loop() {
turnOnDigit(1);
displayNumber(firstDigitReceived);
delayMicroseconds(2000);
turnOnDigit(2);
displayNumber(secondDigitReceived);
delayMicroseconds(2000);
turnOnDigit(3);
displayNumber(thirdDigitReceived);
delayMicroseconds(2000);
turnOnDigit(4);
displayNumber(fourthDigitReceived);
delayMicroseconds(2000);
}
int displayNumber(int number) {
switch(number) {
case 0:
updateShiftRegister(126);
break;
case 1:
updateShiftRegister(48);
break;
case 2:
updateShiftRegister(109);
break;
case 3:
updateShiftRegister(121);
break;
case 4:
updateShiftRegister(51);
break;
case 5:
updateShiftRegister(91);
break;
case 6:
updateShiftRegister(95);
break;
case 7:
updateShiftRegister(112);
break;
case 8:
updateShiftRegister(127);
break;
case 9:
updateShiftRegister(123);
break;
}
}
void turnOnDigit(int digit) {
switch(digit){
case 1:
digitalWrite(digit1, LOW);
digitalWrite(digit2, HIGH);
digitalWrite(digit3, HIGH);
digitalWrite(digit4, HIGH);
digitalWrite(segP, LOW);
break;
case 2:
digitalWrite(digit1, HIGH);
digitalWrite(digit2, LOW);
digitalWrite(digit3, HIGH);
digitalWrite(digit4, HIGH);
digitalWrite(segP, HIGH);
break;
case 3:
digitalWrite(digit1, HIGH);
digitalWrite(digit2, HIGH);
digitalWrite(digit3, LOW);
digitalWrite(digit4, HIGH);
digitalWrite(segP, LOW);
break;
case 4:
digitalWrite(digit1, HIGH);
digitalWrite(digit2, HIGH);
digitalWrite(digit3, HIGH);
digitalWrite(digit4, LOW);
digitalWrite(segP, LOW);
break;
}
}
注意:我已尝试更改延迟,但只会在更短的微秒内变得更糟
答案 0 :(得分:0)
您的问题是您正在更改数字,然后在几微秒后更新您的数字。因此,当您打开每个数字一小段时间时,最后一位数字会显示在那里。更新移位寄存器时应关闭数字,然后打开要显示的数字。