聚豐項(xiàng)目 > 基于AB32VG1的智能RGB補(bǔ)光燈
使用AB32VG1的三路PWM控制LED燈,改變其發(fā)光顏色。使用手機(jī)藍(lán)牙進(jìn)行控制拍照時(shí)的補(bǔ)光燈,根據(jù)手機(jī)端的設(shè)置,直接改變光的顏色
起個(gè)名字太難啊
分享起個(gè)名字太難啊
團(tuán)隊(duì)成員
起個(gè)名字太難啊 軟件
需要外接一塊有全彩LED燈陣組成的燈板,
1.目前開發(fā)完成使用串口控制燈光變化的功能,后期添加手機(jī)端的功能
/* * 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設(shè)備名稱 */ #define PWM_DEV_CHANNEL_R 1 /* PWM通道 */ #define PWM_DEV_NAME_G "lpwm0" /* PWM設(shè)備名稱 */ #define PWM_DEV_CHANNEL_G 1 /* PWM通道 */ #define PWM_DEV_NAME_B "lpwm1" /* PWM設(shè)備名稱 */ #define PWM_DEV_CHANNEL_B 3 /* PWM通道 */ struct rt_device_pwm *pwm_dev_r; /* PWM設(shè)備句柄 */ struct rt_device_pwm *pwm_dev_g; /* PWM設(shè)備句柄 */ struct rt_device_pwm *pwm_dev_b; /* PWM設(shè)備句柄 */ static rt_thread_t pwm_led_tid = RT_NULL; rt_mq_t pwm_led_mq_handler = RT_NULL; /* 線程 pwm_led_thread_entry 的入口函數(shù) */ /** * @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; /* 查找設(shè)備 */ 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); } /* 設(shè)置PWM周期和脈沖寬度默認(rèn)值 */ 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); /* 使能設(shè)備 */ 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) { /* 創(chuàng)建線程,名稱是 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); /* 如果獲得線程控制塊,啟動(dòng)這個(gè)線程 */ if (pwm_led_tid != RT_NULL) rt_thread_startup(pwm_led_tid); return 0; } /* 導(dǎo)出到 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> );