188数码管驱动代码

参考188数码管驱动案方案_Jack.Q的博客-CSDN博客

进行了部分优化

// =========================================================================
// Created by NYIDE.
// User: ZHANG
// Date: 2021/9/22
// Description:
// ========================================================================
  • 4
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
抱歉,作为语言模型AI,无法提供代码。 但是,下面是共阳极数码管的基本驱动方式: 1. 定义数码管引脚和对应的控制信号 2. 设置引脚为输出模式 3. 循环发送控制信号,使每个数码管显示相应的数字 以下是示例代码: ``` #include <Arduino.h> // 定义数码管引脚 const int DIGIT_1 = 2; const int DIGIT_2 = 3; const int DIGIT_3 = 4; const int DIGIT_4 = 5; const int SEG_A = 6; const int SEG_B = 7; const int SEG_C = 8; const int SEG_D = 9; const int SEG_E = 10; const int SEG_F = 11; const int SEG_G = 12; const int SEG_DP = 13; // 定义数字对应的控制信号 const int DIGIT_0[] = { SEG_A, SEG_B, SEG_C, SEG_D, SEG_E, SEG_F }; const int DIGIT_1[] = { SEG_B, SEG_C }; const int DIGIT_2[] = { SEG_A, SEG_B, SEG_D, SEG_E, SEG_G }; const int DIGIT_3[] = { SEG_A, SEG_B, SEG_C, SEG_D, SEG_G }; const int DIGIT_4[] = { SEG_B, SEG_C, SEG_F, SEG_G }; const int DIGIT_5[] = { SEG_A, SEG_C, SEG_D, SEG_F, SEG_G }; const int DIGIT_6[] = { SEG_A, SEG_C, SEG_D, SEG_E, SEG_F, SEG_G }; const int DIGIT_7[] = { SEG_A, SEG_B, SEG_C }; const int DIGIT_8[] = { SEG_A, SEG_B, SEG_C, SEG_D, SEG_E, SEG_F, SEG_G }; const int DIGIT_9[] = { SEG_A, SEG_B, SEG_C, SEG_D, SEG_F, SEG_G }; // 定义数字数组 const int DIGITS[][7] = { DIGIT_0, DIGIT_1, DIGIT_2, DIGIT_3, DIGIT_4, DIGIT_5, DIGIT_6, DIGIT_7, DIGIT_8, DIGIT_9 }; void setup() { // 设置引脚模式为输出 pinMode(DIGIT_1, OUTPUT); pinMode(DIGIT_2, OUTPUT); pinMode(DIGIT_3, OUTPUT); pinMode(DIGIT_4, OUTPUT); pinMode(SEG_A, OUTPUT); pinMode(SEG_B, OUTPUT); pinMode(SEG_C, OUTPUT); pinMode(SEG_D, OUTPUT); pinMode(SEG_E, OUTPUT); pinMode(SEG_F, OUTPUT); pinMode(SEG_G, OUTPUT); pinMode(SEG_DP, OUTPUT); } void loop() { // 循环显示数字 for (int i = 0; i < 10; i++) { digitalWrite(DIGIT_1, HIGH); digitalWrite(DIGIT_2, LOW); digitalWrite(DIGIT_3, LOW); digitalWrite(DIGIT_4, LOW); displayDigit(i); delay(1000); } } // 显示数字 void displayDigit(int digit) { for (int i = 0; i < 7; i++) { digitalWrite(DIGITS[digit][i], HIGH); } digitalWrite(SEG_DP, LOW); } // 清除数码管 void clearDisplay() { for (int i = 0; i < 7; i++) { digitalWrite(DIGITS[0][i], LOW); } digitalWrite(SEG_DP, LOW); } ```
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值