功能如下:
1、通過按鍵調(diào)節(jié)燈的亮度(1-10檔位);
2、通過藍(lán)牙遠(yuǎn)程控制燈的亮度和開關(guān);
3、感應(yīng),根據(jù)附近是否有人自動進(jìn)行開關(guān)燈。
部分程序:
#include
#include
#include "sys_define.h"
#include "pwm.h"
#include "uart.h"
uchar Lamp_OnOff = 1; //臺燈開關(guān)標(biāo)志位
uchar Reaction_OnOff = 0; //人體感應(yīng)開關(guān)標(biāo)志位
sbit Key2 = P2^6;
sbit Key4 = P2^5;
sbit Key5 = P2^4;
sbit Key6 = P2^3;
sbit Reaction = P2^7;
void delay_ms(uint z)
{
uint x,y;
for(x = z; x > 0; x--)
for(y = 114; y > 0 ; y--);
}
uchar Key_Scan()
{
static uchar Key_up = 1;
uchar i;
if(Key_up && ( Key5 == 0 ||Key4 == 0 ))
{
Key_up = 0;
// delay_ms(10);
// if(Key6 == 0) i = 6;
if(Key5 == 0) i = 5;
if(Key4 == 0) i = 4;
// if(Key2 == 0) i = 2;
Uart_SendByte(i+'0');
return i;
}
else if( Key5 == 1 && Key4 == 1)
{
Key_up = 1;
}
}
/* Key2 亮度加
* Key4 亮度減
* Key5 開啟自動感應(yīng)功能
* Key6 臺燈開關(guān) */
void Function()
{
uchar Key = 0;
Key = Key_Scan();
if(Key)
{
// if(Key == 6)
// {
// if(Lamp_OnOff)
// {
// Lamp_Off();
// Lamp_OnOff = 0;
// }
// else
// {
// Lamp_On();
// Lamp_OnOff = 1;
// }
// }
// if(Lamp_OnOff)
// {
if(Key == 4)
PWM++;
if(Key == 5)
PWM--;
if(PWM > 10)
PWM = 10;
else if(PWM < 1)
PWM = 1;
Uart_SendByte(PWM+'0');
// if(Key == 5)
// Reaction_OnOff = ~Reaction_OnOff;
// }
}
審核編輯:湯梓紅
-
藍(lán)牙
+關(guān)注
關(guān)注
116文章
6035瀏覽量
173196 -
51單片機(jī)
+關(guān)注
關(guān)注
277文章
5710瀏覽量
126602
發(fā)布評論請先 登錄
如何實(shí)現(xiàn)基于51單片機(jī)的智能臺燈的設(shè)計?
基于51單片機(jī)的藍(lán)牙臺燈設(shè)計資料分享
51單片機(jī)藍(lán)牙串口從機(jī)與手機(jī)藍(lán)牙主機(jī)及手機(jī)藍(lán)牙軟件配合使用的說明
基于51單片機(jī)的智能臺燈設(shè)計

評論