提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
前言
使用一个新的开发板,最基础简单的点灯。
一、懒人版台灯是什么?
冬天,当你躺在床上躲在被窝里刷视频困了想睡觉,最纠结的是要从暖和的被窝里起来关灯,现在我们使用两个TL8258做控制接收,躲在被窝里就可以开关灯。
二、使用步骤
1.控制端
该芯片深度休眠uA级别,控制端并没有设置电源开关,5秒钟没有操作就自动进入深度休眠。电池使用2032,电压3v,22mAh。不知道能用多久?
PCB如下图:
并做了3D打印外壳:
实物图片:
代码如下(示例):
if(cur_conn_device_hdl == 0 && waitup_sleep == 1 && connet_once == 0){
connet_once = 1;
unsigned char pbuf[] = "xxxxxxxxxxxx";
ble_Connect((char *)pbuf,strlen(pbuf));
}
if(waitup_sleep == 0){
waitup_sleep = 1;
}
//每100毫秒计数一个,限定最少相隔1秒钟才检测
if(timer0_irq_cnt >= 10 && cur_conn_device_hdl != 0 && waitup_sleep == 1){
timer0_irq_cnt = 0;
if((key_stop == 0 || swith_value == 1) && cur_conn_device_hdl != 0){
//at_data_process((char *)send_on, strlen(send_on));
unsigned char send_on[]="5,LEDON";
ble_send((char *)send_on, strlen(send_on));
key_stop = 1;
}else if((key_stop != 0 || swith_value == 1) && cur_conn_device_hdl != 0){
//at_data_process((char *)send_off, strlen(send_off));
unsigned char send_off[]="6,LEDOFF";
ble_send((char *)send_off, strlen(send_off));
key_stop = 0;
}
}
2.接收端
代码如下(示例):
int module_onReceiveData(rf_packet_att_write_t *p)
{
u8 len = p->l2capLen - 3;//有效数据长度
u8 *pbuf[20]={0};
unsigned char key='honyudeng';
memcpy(pbuf, (char*)&p->value, len);
printf("|%s|\r\n",pbuf);
if(device_mode == 0){
if(strcmp(pbuf,"LEDON") == 0){
//gpio_write(GPIO_MOTO_PIN, 0);
gpio_toggle(GPIO_MOTO_PIN);
}
if(strcmp(pbuf,"LEDOFF") == 0){
//gpio_write(GPIO_MOTO_PIN, 1);
gpio_toggle(GPIO_MOTO_PIN);
}
}
return 0;
}
总结
制作的整个过程,程序使用了gpio中断,硬件定时器… …
画了一个简单的板子和3D外壳