码迷,mamicode.com
首页 > 其他好文 > 详细

Arduino 数码管LED屏驱动

时间:2014-10-21 21:25:46      阅读:337      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   ar   sp   div   2014   on   art   

今天測试数码管LED屏驱动,用某产品的一个共阴极的LED屏,依据电路图做数码管LED屏的检測。

代码写得有些冗长,有好几种驱动的方法,这里仅仅是当中一种最直接的方案,抽出时间要做个更有效率的调用和驱动的方案。


bubuko.com,布布扣


bubuko.com,布布扣


//设置阴极接口
int d1 = 1;
int d2 = 2;
int d3 = 3;
int d4 = 4;
int d5 = 5;
int d6 = 6;
int d7 = 7;
//设置阳极接口
int a = 8;
int b = 9;
int c = 10;
int d = 11;
int e = 12;
int f = 13;
int g = A0;
int h = A1;

void setup()
{
pinMode(d1, OUTPUT);
pinMode(d2, OUTPUT);
pinMode(d3, OUTPUT);
pinMode(d4, OUTPUT);
pinMode(d5, OUTPUT);
pinMode(d6, OUTPUT);
pinMode(d7, OUTPUT);
pinMode(a, OUTPUT);
pinMode(b, OUTPUT);
pinMode(c, OUTPUT);
pinMode(d, OUTPUT);
pinMode(e, OUTPUT);
pinMode(f, OUTPUT);
pinMode(g, OUTPUT);
pinMode(h, OUTPUT);
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
digitalWrite(h, LOW);
digitalWrite(d1, HIGH);
digitalWrite(d2, HIGH);
digitalWrite(d3, HIGH);
digitalWrite(d4, HIGH);
digitalWrite(d5, HIGH);
digitalWrite(d6, HIGH);
digitalWrite(d7, HIGH);
}

void loop()
{
//缺水
digitalWrite(d7, LOW);
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
delay(500);
//低水位
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
delay(500);
//定时关机
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
delay(500);
//温度十位8
digitalWrite(d7, HIGH);
digitalWrite(d1, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
digitalWrite(a, HIGH);
delay(300);
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
delay(300);
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
delay(300);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
delay(300);
digitalWrite(d, LOW);
digitalWrite(e, HIGH);
delay(300);
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
delay(300);
digitalWrite(f, LOW);
digitalWrite(g, HIGH);
delay(300);
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
delay(300);
//温度个位8
digitalWrite(d1, HIGH);
digitalWrite(d2, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
digitalWrite(a, HIGH);
delay(300);
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
delay(300);
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
delay(300);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
delay(300);
digitalWrite(d, LOW);
digitalWrite(e, HIGH);
delay(300);
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
delay(300);
digitalWrite(f, LOW);
digitalWrite(g, HIGH);
delay(300);
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
delay(300);
//温符号度
digitalWrite(d2, HIGH);
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
digitalWrite(h, HIGH);
digitalWrite(d1, LOW);
delay(500);
//睡眠符号
digitalWrite(d1, HIGH);
digitalWrite(d2, LOW);
delay(500);
//小时十位8
digitalWrite(d2, HIGH);
digitalWrite(d3, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
digitalWrite(a, HIGH);
delay(300);
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
delay(300);
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
delay(300);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
delay(300);
digitalWrite(d, LOW);
digitalWrite(e, HIGH);
delay(300);
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
delay(300);
digitalWrite(f, LOW);
digitalWrite(g, HIGH);
delay(300);
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
delay(300);
//小时个位8
digitalWrite(d3, HIGH);
digitalWrite(d4, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
digitalWrite(h, LOW);
digitalWrite(a, HIGH);
delay(300);
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
delay(300);
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
delay(300);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
delay(300);
digitalWrite(d, LOW);
digitalWrite(e, HIGH);
delay(300);
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
delay(300);
digitalWrite(f, LOW);
digitalWrite(g, HIGH);
delay(300);
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
delay(300);
//冒号
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
digitalWrite(h, HIGH);
delay(500);
//分钟十位8
digitalWrite(d4, HIGH);
digitalWrite(d5, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
digitalWrite(a, HIGH);
delay(300);
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
delay(300);
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
delay(300);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
delay(300);
digitalWrite(d, LOW);
digitalWrite(e, HIGH);
delay(300);
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
delay(300);
digitalWrite(f, LOW);
digitalWrite(g, HIGH);
delay(300);
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
delay(300);
//分钟个位8
digitalWrite(d5, HIGH);
digitalWrite(d6, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
digitalWrite(a, HIGH);
delay(300);
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
delay(300);
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
delay(300);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
delay(300);
digitalWrite(d, LOW);
digitalWrite(e, HIGH);
delay(300);
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
delay(300);
digitalWrite(f, LOW);
digitalWrite(g, HIGH);
delay(300);
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
delay(300);
//全亮
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
digitalWrite(h, HIGH);
digitalWrite(d1, LOW);
digitalWrite(d2, LOW);
digitalWrite(d3, LOW);
digitalWrite(d4, LOW);
digitalWrite(d5, LOW);
digitalWrite(d6, LOW);
digitalWrite(d7, LOW);
delay(500);
//全灭
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
digitalWrite(h, LOW);
digitalWrite(d1, HIGH);
digitalWrite(d2, HIGH);
digitalWrite(d3, HIGH);
digitalWrite(d4, HIGH);
digitalWrite(d5, HIGH);
digitalWrite(d6, HIGH);
digitalWrite(d7, HIGH);
delay(500);
}

bubuko.com,布布扣


计划採用机器视觉来检測,自己主动鉴别出断笔,笔段亮度差异较大等质量检验问题

Arduino 数码管LED屏驱动

标签:style   blog   http   ar   sp   div   2014   on   art   

原文地址:http://www.cnblogs.com/lcchuguo/p/4041422.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!