日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

arduino 电子时钟

發布時間:2023/12/8 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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的值

總結

以上是生活随笔為你收集整理的arduino 电子时钟的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。