聚丰项目 > 基于AB32VG1的智能RGB补光灯
使用AB32VG1的三路PWM控制LED灯,改变其发光颜色。使用手机蓝牙进行控制拍照时的补光灯,根据手机端的设置,直接改变光的颜色
起个名字太难啊
分享起个名字太难啊
团队成员
起个名字太难啊 软件
需要外接一块有全彩LED灯阵组成的灯板,
1.目前开发完成使用串口控制灯光变化的功能,后期添加手机端的功能
/* * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2021-12-13 Administrator the first version */ #include <rtthread.h> #include "board.h" #define THREAD_PRIORITY 7 #define THREAD_STACK_SIZE 512 #define THREAD_TIMESLICE 3 #define PWM_DEV_NAME_R "t5pwm" /* PWM设备名称 */ #define PWM_DEV_CHANNEL_R 1 /* PWM通道 */ #define PWM_DEV_NAME_G "lpwm0" /* PWM设备名称 */ #define PWM_DEV_CHANNEL_G 1 /* PWM通道 */ #define PWM_DEV_NAME_B "lpwm1" /* PWM设备名称 */ #define PWM_DEV_CHANNEL_B 3 /* PWM通道 */ struct rt_device_pwm *pwm_dev_r; /* PWM设备句柄 */ struct rt_device_pwm *pwm_dev_g; /* PWM设备句柄 */ struct rt_device_pwm *pwm_dev_b; /* PWM设备句柄 */ static rt_thread_t pwm_led_tid = RT_NULL; rt_mq_t pwm_led_mq_handler = RT_NULL; /* 线程 pwm_led_thread_entry 的入口函数 */ /** * @brief pwm_led_thread_entry * @param parameter * @retval None */ static void pwm_led_thread_entry(void *parameter) { rt_uint32_t period, pulse_r,pulse_g,pulse_b, dir_r,dir_g,dir_b; period = 655360; /* 周期为0.5ms,单位为纳秒ns */ pulse_r = 0; /* PWM脉冲宽度值,单位为纳秒ns */ pulse_g = 0; pulse_b = 0; pwm_led_t pwm_mq; /* 查找设备 */ pwm_dev_r = (struct rt_device_pwm *)rt_device_find(PWM_DEV_NAME_R); if (pwm_dev_r == RT_NULL) { rt_kprintf("pwm led r run failed! can't find %s device!\n", PWM_DEV_NAME_G); } pwm_dev_g = (struct rt_device_pwm *)rt_device_find(PWM_DEV_NAME_G); if (pwm_dev_g == RT_NULL) { rt_kprintf("pwm led g run failed! can't find %s device!\n", PWM_DEV_NAME_G); } pwm_dev_b = (struct rt_device_pwm *)rt_device_find(PWM_DEV_NAME_B); if (pwm_dev_b == RT_NULL) { rt_kprintf("pwm led b run failed! can't find %s device!\n", PWM_DEV_NAME_B); } /* 设置PWM周期和脉冲宽度默认值 */ rt_pwm_set(pwm_dev_r, PWM_DEV_CHANNEL_R, period, pulse_r); rt_pwm_set(pwm_dev_g, PWM_DEV_CHANNEL_G, period, pulse_g); rt_pwm_set(pwm_dev_b, PWM_DEV_CHANNEL_B, period, pulse_b); /* 使能设备 */ rt_pwm_enable(pwm_dev_r, PWM_DEV_CHANNEL_R); rt_pwm_enable(pwm_dev_g, PWM_DEV_CHANNEL_G); rt_pwm_enable(pwm_dev_b, PWM_DEV_CHANNEL_B); while (1) { if(rt_mq_recv(pwm_led_mq_handler,&pwm_mq,sizeof(pwm_led_t),RT_WAITING_FOREVER) == RT_EOK) { rt_pwm_set(pwm_dev_r, PWM_DEV_CHANNEL_R, period, pwm_mq.pulse_r); rt_pwm_set(pwm_dev_g, PWM_DEV_CHANNEL_G, period, pwm_mq.pulse_g); rt_pwm_set(pwm_dev_b, PWM_DEV_CHANNEL_B, period, pwm_mq.pulse_b); rt_kprintf("pulse_r:%d pulse_g:%d pulse_b:%d\n", pwm_mq.pulse_r,pwm_mq.pulse_g,pwm_mq.pulse_b); rt_thread_mdelay(10); } } } /* 线程初始化*/ int thread_init(void) { /* 创建线程,名称是 pwm_led_thread,入口是 pwm_led_thread*/ pwm_led_tid = rt_thread_create("pwm_led_thread", pwm_led_thread_entry, RT_NULL, THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE); pwm_led_mq_handler = rt_mq_create("pwm_led_messagequeue", sizeof(pwm_led_t), 6, RT_IPC_FLAG_FIFO); /* 如果获得线程控制块,启动这个线程 */ if (pwm_led_tid != RT_NULL) rt_thread_startup(pwm_led_tid); return 0; } /* 导出到 msh 命令列表中 */ INIT_APP_EXPORT(thread_init);
/* * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2021-12-13 Administrator the first version */ #include <rtthread.h> #include "board.h" #include <stdlib.h> #define THREAD_PRIORITY 10 #define THREAD_STACK_SIZE 512 #define THREAD_TIMESLICE 5 extern rt_mq_t pwm_led_mq_handler; static void cmd_led(int argc, char **argv) { pwm_led_t pwm_mq; if(argc != 4) { rt_kprintf("please input'pulse_rgb <pulse_r & pulse_g & pulse_b>'!\n"); }else{ pwm_mq.pulse_r = strtoul(argv[1],0, 10); pwm_mq.pulse_g = strtoul(argv[2],0, 10); pwm_mq.pulse_b = strtoul(argv[3],0, 10); rt_mq_send(pwm_led_mq_handler, &pwm_mq, sizeof(pwm_led_t)); } } //FINSH_FUNCTION_EXPORT(uart_cmd_led, led cmd); MSH_CMD_EXPORT( cmd_led, cmd sample:pulse_rgb <pulse_r & pulse_g & pulse_b> );