电子工程师技术服务社区
公告
登录
|
注册
首页
技术问答
厂商活动
正点原子
板卡试用
资源库
下载
文章
社区首页
文章
给墙表添加夜灯,让它变成夜晚墙上最靓的物件
分 享
扫描二维码分享
给墙表添加夜灯,让它变成夜晚墙上最靓的物件
MAX7219
微波传感
gada8881
关注
发布时间: 2020-06-29
丨
阅读: 797
家里有个墙表,用了几年了没坏,也不想换。可是自己经常晚上起夜时候是半夜,从厕所回来就想看下时间了解下自己的起夜规律。但是老墙表由于没夜灯,所以都看不到时间。又迷迷糊糊的去睡了。但这个问题一直都想解决呀。于是想了好一阵子怎么去弄。用微波测距是早已经想好的主零件,然后就是灯的问题,这个选了好久,最初的想法是用几个LED串联一起,但是又觉得不好看,而且要焊接。用WS2812B led吧,可以是可以,就是怎么弄成圆形的呢。有点麻烦,而且有个要求是灯不必那么亮,刚刚看清表盘就好,而且还要灯平滑关闭。最后是想到了用点阵,也就是MAX7219模块,这个模块既经济又连线方便。 ![](https://cf01.ickimg.com/bbsimages/202006/e42140dbc693c351aaa0fbd700984d43.png) arduino uno ![](https://cf01.ickimg.com/bbsimages/202006/a5d84121956f0c8ad49aa50244142b28.png) 微波传感 ![](https://cf01.ickimg.com/bbsimages/202006/b0116e9f59aa1246a006dcd11b48693c.png) 点阵max7219 ![](https://cf01.ickimg.com/bbsimages/202006/0237ce51ff10c3029ba9013099d3d342.png) ![] ![](https://cf01.ickimg.com/bbsimages/202006/53886ce790a6a69e261bd91e222dafa7.png) 下面是连线图 ![](https://cf01.ickimg.com/bbsimages/202006/0741a717345d78c2be5bf57f825d917a.jpg) ```c /@@* 这个代码是gada888所做,2020-05-25 转载请注明出处 */ #include
//Timer interrupt function int pbIn = 0; // Define the interrupt PIN is 0, that is, digital pins 2 //int ledOut = 13; int count=0; volatile int state = LOW; //Define ledOut, default is off #include "LedControlMS.h" //pin 5 is connected to the DataIn // pin 4 is connected to the CLK //pin 3 is connected to LOAD #define NUM_MTX 1 //number of matrices attached is one LedControl lc=LedControl(5,4,3, NUM_MTX);// /////////////////SETUP///////////////// void setup() { Serial.begin(9600); //pinMode(ledOut, OUTPUT); attachInterrupt(pbIn, stateChange, FALLING); // Sets the interrupt function, falling edge triggered interrupts. MsTimer2::set(1000,process); // Set the timer interrupt time 1000ms MsTimer2::start();//Timer interrupt start lc.shutdown(0,true); lc.shutdown(1,true); lc.setIntensity(0,8); lc.clearDisplay(0); lc.setIntensity(1,8); lc.clearDisplay(1); } void loop() { Serial.println(count); // Printing times of 1000ms suspension delay(1); if(state == HIGH) //When moving objects are detected later, 2s shut down automatically after the ledout light is convenient. { delay(2000); state = LOW; Alloff(); } } void stateChange() //Interrupt function { count++; } void process() //Timer handler { if(count>1) //1000ms interrupt number greater than 1 is considered detected a moving object (this value can be adjusted according to the actual situation, equivalent to adjust the de { state = HIGH; Allon(); count=0; //Count zero } else count=0; //In 1000ms, interrupts does not reach set threshold value is considered not detect moving objects, interrupt the count number is cleared to zero. } void Allon() { lc.shutdown(1,true); lc.shutdown(0,false); for (int row=0; row<8; row++) { for (int col=0; col<8; col++) { lc.setLed(0,col,row,true); // turns on LED at col, row delay(10); } } } void Alloff() { lc.shutdown(1,true); lc.shutdown(0,false); for (int row=0; row<8; row++) { for (int col=0; col<8; col++) { lc.setLed(0,col,row,false); // turns on LED at col, row delay(10); } } }
原创作品,未经权利人授权禁止转载。详情见
转载须知
。
举报文章
点赞
(
0
)
gada8881
关注
评论
(0)
登录后可评论,请
登录
或
注册
相关文章推荐
MK-米客方德推出工业级存储卡
Beetle ESP32 C3 蓝牙数据收发
Beetle ESP32 C3 wifi联网获取实时天气信息
开箱测评Beetle ESP32-C3 (RISC-V芯片)模块
正点原子数控电源DP100测评
DP100试用评测-----开箱+初体验
Beetle ESP32 C3环境搭建
【花雕体验】16 使用Beetle ESP32 C3控制8X32位WS2812硬屏之二
X
你的打赏是对原创作者最大的认可
请选择打赏IC币的数量,一经提交无法退回 !
100IC币
500IC币
1000IC币
自定义
IC币
确定
X
提交成功 ! 谢谢您的支持
返回
我要举报该内容理由
×
广告及垃圾信息
抄袭或未经授权
其它举报理由
请输入您举报的理由(50字以内)
取消
提交