驴友花雕 发表于 2024-2-1 16:00:27

【花雕动手做】ASRPRO语音识别(60)---软件定时器控制变色灯

本例实验的WS2812B模块:



本例实验的WS2812B模块的电原理图



本例实验的LED模块:
1个电源LED,一个可控制LED(与KEY3共用引脚PA4)。

电原理图(红点处D5为可控制LED)



【花雕动手做】实验六十五:使用定时器控制板载LED灯闪烁和RGB灯延时变色
实验开源代码

#include "asr.h"
extern "C"{ void * __dso_handle = 0 ;}
#include "setup.h"
#include "myLib/asr_ws2812.h"

uint32_t snid;
void ASR_CODE();
void stimer_2(TimerHandle_t xTimer);
TimerHandle_t softtimer_2=NULL;
void stimer_1(TimerHandle_t xTimer);
TimerHandle_t softtimer_1=NULL;
void hardware_init();

//{ID:250,keyword:"命令词",ASR:"最大音量",ASRTO:"音量调整到最大"}
//{ID:251,keyword:"命令词",ASR:"中等音量",ASRTO:"音量调整到中等"}
//{ID:252,keyword:"命令词",ASR:"最小音量",ASRTO:"音量调整到最小"}
WS2812 ASR_WS2812_27(27);
/*描述该功能...
*/
void ASR_CODE(){
switch (snid) {
   case 1:
    xTimerStart(softtimer_1,0);
    break;
   case 2:
    xTimerStop(softtimer_1,0);
    digitalWrite(4,1);
    break;
   case 3:
    ASR_WS2812_27.setBrightness(30);
    ASR_WS2812_27.pixel_set_all_color(255,0,0);
    ASR_WS2812_27.pixel_show();
    xTimerStart(softtimer_2,0);
    break;
   case 4:
    ASR_WS2812_27.pixel_set_all_color(0,0,0);
    ASR_WS2812_27.pixel_show();
    xTimerStop(softtimer_2,0);
    break;
}

}

void sys_sleep_hook()
{
digitalWrite(4,1);

}

void stimer_2(TimerHandle_t xTimer){
ASR_WS2812_27.setBrightness(30);
ASR_WS2812_27.pixel_set_all_color(0,255,0);
ASR_WS2812_27.pixel_show();
}

void stimer_1(TimerHandle_t xTimer){
digitalWrite(4,!(digitalRead(4)));
}

void hardware_init(){
softtimer_1=xTimerCreate("stimer_1",100,1,0,stimer_1);
softtimer_2=xTimerCreate("stimer_2",1000,0,0,stimer_2);
vTaskDelete(NULL);
}

void setup()
{
//{speak:小蝶-清新女声,vol:20,speed:10,platform:haohaodada}
//{playid:10001,voice:欢迎使用人工智能AI语音助手,用智能管家唤醒我}
//{playid:10002,voice:我退下了,用智能管家唤醒我}
//{ID:0,keyword:"唤醒词",ASR:"智能管家",ASRTO:"我在"}
//{ID:1,keyword:"命令词",ASR:"打开灯光",ASRTO:"好的,马上打开,灯光在闪烁"}
//{ID:2,keyword:"命令词",ASR:"关闭灯光",ASRTO:"好的,马上关闭灯光"}
//{ID:3,keyword:"命令词",ASR:"打开红灯",ASRTO:"好的,打开RGB灯,一秒后变色"}
//{ID:4,keyword:"命令词",ASR:"关闭彩灯",ASRTO:"好的,马上关闭RGB灯"}
ASR_WS2812_27.pixel_init(3);
pinMode(4,output);
setPinFun(4,FIRST_FUNCTION);
pinMode(27,output);
xTaskCreate(hardware_init,"hardware_init",256,NULL,100,NULL);
}
生成模型与编译烧录





实验场景图






页: [1]
查看完整版本: 【花雕动手做】ASRPRO语音识别(60)---软件定时器控制变色灯