arduino 电子时钟

# 1.七段数码管的电路连接如图:

a.
七段数码管的common极都为阴极,接至负极

b. 
Seg_Control_Pin[0][i]数组控制十位,
Seg_Control_Pin[1][i]数组控制个位


# 2.代码部分:



const uint8_t Seg_Code[10] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F};                                                   // Nixie tube truth tableconst

uint8_t Seg_Control_Pin[2][7] = {{0, 1, 2, 3, 4, 5, 6}, {7, 8, 9, 10, 11, 12, 13}};  // Nixie tube pin definition

uint8_t Timers_Count = 0; 


const使得七段数码管的引脚编号只能被检索,不能被改变

void setup()
{
    for (uint8_t i = 0; i < 7; i++) // Traverse the nixie tube control pin
    {
        pinMode(Seg_Control_Pin[0][i], OUTPUT);   // Set the nixie pin as the output
        pinMode(Seg_Control_Pin[1][i], OUTPUT);   // Set the nixie pin as the output
        digitalWrite(Seg_Control_Pin[0][i], LOW); // Quench digital tube
        digitalWrite(Seg_Control_Pin[1][i], LOW); // Quench digital tube
    }
}

for循环依次将两组引脚调整为output

void loop()
{
    delay(1000);                    // Wait for 1000 millisecond(s)
    Timers_Count++;                 // Count increment by 1
    if (Timers_Count >= 60)         // If the count is greater than or equal to 60
        Timers_Count = 0;           // Count returns 0
    for (uint8_t i = 0; i < 7; i++) // Traverse the nixie tube control pin
    {
        digitalWrite(Seg_Control_Pin[0][i], bitRead(Seg_Code[Timers_Count / 10], i));

// Get from the nixie tube truth table whether the nixie tube should belit or off based on the tens digit value of the counted value
       

digitalWrite(Seg_Control_Pin[1][i], bitRead(Seg_Code[Timers_Count % 10], i));

// Get whether the nixie tube should be lit up or off from the nixie tube truth table according to the bits value of the counted value
    }
}

在loop函数中,每次执行为每一秒钟的显示,当timerc大于60时,重新计零。


**一个核心函数:bitRead**

参数如下:
```
bitRead(x, n):
x: the number from which to read(用来读取的数字)
n: which bit to read, starting at 0 for the least-significant (rightmost) bit(该数字对应的二进制数的位数)
```
也就是说,bitRead从给定的参数中读取一个位,也就是读取一个0或1的值

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值