2020-5-30 15:02:09 [显示全部楼层]
1860浏览
查看: 1860|回复: 3

[项目] 给墙表添加夜灯,让它变成夜晚墙上最靓的物件

[复制链接]
本帖最后由 gada888 于 2020-5-30 15:19 编辑

家里有个墙表,用了几年了没坏,也不想换。可是自己经常晚上起夜时候是半夜,从厕所回来就想看下时间了解下自己的起夜规律。但是老墙表由于没夜灯,所以都看不到时间。又迷迷糊糊的去睡了。但这个问题一直都想解决呀。于是想了好一阵子怎么去弄。用微波测距是早已经想好的主零件,然后就是灯的问题,这个选了好久,最初的想法是用几个LED串联一起,但是又觉得不好看,而且要焊接。用WS2812B led吧,可以是可以,就是怎么弄成圆形的呢。有点麻烦,而且有个要求是灯不必那么亮,刚刚看清表盘就好,而且还要灯平滑关闭。最后是想到了用点阵,也就是MAX7219模块,这个模块既经济又连线方便。
给墙表添加夜灯,让它变成夜晚墙上最靓的物件图1

经过几天的密集测试,未发现Bug,准备把主控换成Arduino nano,并配上外壳,让它正式服役。

--------------物料清单如下-------------
元件除了点阵均来自DFRobot,具体参数参考商城的产品WIKI,点阵有配专门的介绍,购自某宝
给墙表添加夜灯,让它变成夜晚墙上最靓的物件图2
微波传感
给墙表添加夜灯,让它变成夜晚墙上最靓的物件图3
arduino UNO Romeo
给墙表添加夜灯,让它变成夜晚墙上最靓的物件图4
给墙表添加夜灯,让它变成夜晚墙上最靓的物件图5

--------------连线图如下-------------
给墙表添加夜灯,让它变成夜晚墙上最靓的物件图6
-----------------代码如下-------------
[mw_shl_code=applescript,false]/*

这个代码是gada888所做,2020-05-25
转载请注明出处

*/
#include <MsTimer2.h> //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);
      }
  }
}
[/mw_shl_code]

首先本人并没有逐行注释的习惯,但为了让阅读者顺利读码,特意在关键的地方打上了注释,

给墙表添加夜灯,让它变成夜晚墙上最靓的物件图7

给墙表添加夜灯,让它变成夜晚墙上最靓的物件图8




LuckyE  学徒

发表于 2020-5-30 16:01:24

你就是最靓的仔
回复

使用道具 举报

gada888  版主
 楼主|

发表于 2020-6-2 07:49:09

LuckyE 发表于 2020-5-30 16:01
你就是最靓的仔

可不敢当
回复

使用道具 举报

hnyzcj  版主

发表于 2020-6-2 17:16:46

果然很闪亮
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail