V1.0
This commit is contained in:
@@ -0,0 +1,372 @@
|
||||
#include "pwm.h"
|
||||
#include "xc_drv_pwm.h"
|
||||
#include "rgblight.h"
|
||||
#include "mode.h"
|
||||
#include "timer.h"
|
||||
#include "math.h"
|
||||
#include "timeslice.h"
|
||||
#include "RF433.h"
|
||||
#include "usr_server.h"
|
||||
|
||||
|
||||
uint16_t time_1[11]={8,10,12,14,16,18,20,22,24,26,26};
|
||||
uint16_t time_2[11]={100,200,300,400,500,600,700,800,900,1000,1000};
|
||||
uint16_t time_3[11]={200, 350, 450, 550, 650, 750, 850, 950, 1200,1500,1500};
|
||||
|
||||
uint8_t deviceStatus=POWERON; //开机标志位
|
||||
uint8_t Mode=mode0; //mode0 1 2 3 4
|
||||
uint8_t Speed=5; //速度
|
||||
uint8_t direction = 1; // 呼吸灯的亮度变化方向,1表示增加,0表示减小
|
||||
|
||||
uint8_t choose_mode_falsg=0; //模式值
|
||||
uint8_t choose_mode_bh=0; //模式变化
|
||||
|
||||
uint16_t Color_table_static[3][2]={
|
||||
{10,0}, //暖光
|
||||
{4,4}, //中性光
|
||||
{0,10}, //冷光
|
||||
};
|
||||
|
||||
|
||||
uint16_t Color_table[3][2]={ //动态时候的数组
|
||||
{100,0}, //暖光
|
||||
{40,40}, //中性光
|
||||
{0,100}, //冷光
|
||||
};
|
||||
|
||||
//设置定时
|
||||
void Set_timing(){
|
||||
if(is_time==1){
|
||||
if(flag_1h>0){ //定时一个小时
|
||||
flag_1h--;
|
||||
if(flag_1h==0){
|
||||
Stop_PWM();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void Start_PWM(){
|
||||
deviceStatus=POWERON;
|
||||
startTimer(&timer1,1);
|
||||
}
|
||||
|
||||
|
||||
void Stop_PWM(){
|
||||
deviceStatus=POWEROFF;
|
||||
xc_gpio_write_pin(IO_PWM_W, GPIO_PIN_RESET);
|
||||
xc_gpio_write_pin(IO_PWM_C, GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
|
||||
void set_mode(){
|
||||
if(choose_mode_bh==0){
|
||||
choose_mode_bh=1;
|
||||
switch(choose_mode_falsg){
|
||||
//
|
||||
case 0:
|
||||
//暖光
|
||||
W_PWM=Color_table_static[0][0];
|
||||
C_PWM=Color_table_static[0][1];
|
||||
driveMode=1;//切换为暖光的底层输出
|
||||
Mode=mode0;
|
||||
break;
|
||||
case 1:
|
||||
//冷光
|
||||
W_PWM=Color_table_static[2][0];
|
||||
C_PWM=Color_table_static[2][1];
|
||||
driveMode=2;//切换为冷光的底层输出
|
||||
Mode=mode0;
|
||||
break;
|
||||
case 2:
|
||||
//中性光
|
||||
W_PWM=Color_table_static[1][0];
|
||||
C_PWM=Color_table_static[1][1];
|
||||
driveMode=0;//切换为中性光的底层输出
|
||||
Mode=mode0;
|
||||
break;
|
||||
case 3:
|
||||
//暖光呼吸
|
||||
W_PWM=Color_table[0][0];
|
||||
C_PWM=Color_table[0][1];
|
||||
driveMode=1;//切换为暖光的底层输出
|
||||
direction=1;//呼吸方向恢复默认值
|
||||
Mode=mode1;
|
||||
break;
|
||||
case 4:
|
||||
//冷光呼吸
|
||||
W_PWM=Color_table[2][0];
|
||||
C_PWM=Color_table[2][1];
|
||||
driveMode=2;//切换为中性光的底层输出
|
||||
direction=1;//呼吸方向恢复默认值
|
||||
Mode=mode1;
|
||||
break;
|
||||
case 5:
|
||||
//三个色温轮询呼吸//先从暖光开始呼吸
|
||||
W_PWM=Color_table[0][0];
|
||||
C_PWM=Color_table[0][1];
|
||||
driveMode=1;//切换为暖光的底层输出
|
||||
direction=1;//呼吸方向恢复默认值
|
||||
|
||||
Mode=mode1;
|
||||
break;
|
||||
case 6:
|
||||
//暖光跳变
|
||||
W_PWM=Color_table[0][0];
|
||||
C_PWM=Color_table[0][1];
|
||||
driveMode=1;//切换为暖光的底层输出
|
||||
direction=1;//呼吸方向恢复默认值
|
||||
Mode=mode2;
|
||||
break;
|
||||
case 7:
|
||||
//中性光跳变
|
||||
W_PWM=Color_table[1][0];
|
||||
C_PWM=Color_table[1][1];
|
||||
driveMode=0;//切换为中性光的底层输出
|
||||
Mode=mode2;
|
||||
break;
|
||||
case 8:
|
||||
//冷光跳变
|
||||
W_PWM=Color_table[2][0];
|
||||
C_PWM=Color_table[2][1];
|
||||
driveMode=2;//切换为中性光的底层输出
|
||||
direction=1;//呼吸方向恢复默认值
|
||||
Mode=mode2;
|
||||
break;
|
||||
case 9:
|
||||
//暖光中性光冷交替跳变,先从暖光跳变
|
||||
W_PWM=Color_table[0][0];
|
||||
C_PWM=Color_table[0][1];
|
||||
driveMode=1;//切换为暖光的底层输出
|
||||
direction=1;//呼吸方向恢复默认值
|
||||
Mode=mode2;
|
||||
break;
|
||||
|
||||
case 10://圆环模式
|
||||
Mode=mode0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
void Mode0(){ //常量
|
||||
UpdateDisplay();
|
||||
}
|
||||
|
||||
|
||||
static uint8_t breathespeed_flag=0; //该变量只是用来处理三种颜色呼吸时候,对中性光的速度变大
|
||||
static void breathe_fun(uint16_t *PWM_1, uint16_t *PWM_2, uint8_t flag) {
|
||||
if (flag == 0) {
|
||||
*PWM_1 = 0;
|
||||
if (direction == 1) {
|
||||
(*PWM_2)--;
|
||||
if (*PWM_2 <= 1) {
|
||||
*PWM_2 = 1;
|
||||
direction = 0;
|
||||
}
|
||||
} else if (direction == 0) {
|
||||
(*PWM_2)++;
|
||||
if (*PWM_2 >= 100) {
|
||||
direction = 1;
|
||||
}
|
||||
|
||||
}
|
||||
} else if (flag == 2) {//丢弃
|
||||
// if (direction == 1) {
|
||||
// (*PWM_1)--;
|
||||
// (*PWM_2)--;
|
||||
// if (*PWM_1 <= 1) {
|
||||
// *PWM_1 = 1;
|
||||
// *PWM_2 = 1;
|
||||
// direction = 0;
|
||||
// }
|
||||
// } else if (direction == 0) {
|
||||
// (*PWM_1)++;
|
||||
// (*PWM_2)++;
|
||||
// if (*PWM_1 >= 4) {
|
||||
// *PWM_1 = 4;
|
||||
// *PWM_2 = 4;
|
||||
// direction = 1;
|
||||
// if(flag==2){choose_breathe=0;driveMode=1;}
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
void Mode1(){ //呼吸
|
||||
if(choose_mode_falsg==3){ //暖光呼吸
|
||||
breathe_fun(&C_PWM,&W_PWM,0);
|
||||
}else if(choose_mode_falsg==4){//冷光呼吸
|
||||
breathe_fun(&W_PWM,&C_PWM,0);
|
||||
}else if(choose_mode_falsg==5){
|
||||
switch (direction) {
|
||||
case 0:
|
||||
breathespeed_flag=0;
|
||||
W_PWM += 1;
|
||||
C_PWM = 0;
|
||||
|
||||
if (W_PWM >= 100) {
|
||||
direction = 1;
|
||||
}
|
||||
|
||||
break;
|
||||
case 1:
|
||||
breathespeed_flag=0;
|
||||
W_PWM -= 1;
|
||||
C_PWM = 0;
|
||||
if (W_PWM <= 1) {
|
||||
direction = 2;
|
||||
driveMode=0;
|
||||
W_PWM = 1;
|
||||
C_PWM = 0;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
breathespeed_flag=1;
|
||||
W_PWM += 1;
|
||||
C_PWM += 1;
|
||||
if (W_PWM >= 40) {
|
||||
W_PWM=40;
|
||||
C_PWM=40;
|
||||
direction = 3;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
breathespeed_flag=1;
|
||||
W_PWM -= 1;
|
||||
C_PWM -= 1;
|
||||
if (W_PWM <=1) {
|
||||
driveMode=2;
|
||||
direction = 4;
|
||||
W_PWM = 1;
|
||||
C_PWM = 1;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
breathespeed_flag=0;
|
||||
W_PWM = 0;
|
||||
C_PWM += 1;
|
||||
|
||||
if (C_PWM >= 100) {
|
||||
direction = 5;
|
||||
}
|
||||
break;
|
||||
|
||||
case 5:
|
||||
breathespeed_flag=0;
|
||||
W_PWM = 0;
|
||||
C_PWM -= 1;
|
||||
if (C_PWM <=1){
|
||||
direction = 0;
|
||||
driveMode=1;
|
||||
W_PWM = 1;
|
||||
C_PWM = 1;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
//UpdateDisplay();
|
||||
UpdateDisplay_1();
|
||||
}
|
||||
|
||||
|
||||
void jump_fun(uint16_t *PWM_1, uint16_t *PWM_2, uint8_t flag){
|
||||
if(flag==0){
|
||||
*PWM_1 = 0;
|
||||
if (!direction){
|
||||
*PWM_2 = 100;
|
||||
direction = 1;
|
||||
} else {
|
||||
*PWM_2 = 0;
|
||||
direction = 0;
|
||||
}
|
||||
}else if(flag==1){
|
||||
if (!direction){
|
||||
*PWM_1 = 40;
|
||||
*PWM_2 = 40;
|
||||
direction = 1;
|
||||
} else {
|
||||
*PWM_1 = 0;
|
||||
*PWM_2 = 0;
|
||||
direction = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Mode2(){ //跳变
|
||||
//printf("dd=%d--%d\r\n",W_PWM,W_PWM);
|
||||
if(choose_mode_falsg==6){
|
||||
jump_fun(&C_PWM,&W_PWM,0); //暖光跳变
|
||||
}else if(choose_mode_falsg==7){
|
||||
jump_fun(&W_PWM,&C_PWM,1); //中光跳变
|
||||
}else if(choose_mode_falsg==8){
|
||||
jump_fun(&W_PWM,&C_PWM,0); //冷光跳变
|
||||
}else if(choose_mode_falsg==9){
|
||||
switch (direction) {
|
||||
case 1:
|
||||
W_PWM =100;
|
||||
C_PWM = 0;
|
||||
direction = 2;
|
||||
break;
|
||||
case 2:
|
||||
W_PWM = 0;
|
||||
C_PWM = 0;
|
||||
direction = 3;
|
||||
driveMode=0;
|
||||
break;
|
||||
case 3:
|
||||
W_PWM =40;
|
||||
C_PWM =40;
|
||||
direction = 4;
|
||||
break;
|
||||
case 4:
|
||||
W_PWM =0;
|
||||
C_PWM =0;
|
||||
direction = 5;
|
||||
driveMode=2;
|
||||
break;
|
||||
case 5:
|
||||
W_PWM = 0;
|
||||
C_PWM = 100;
|
||||
direction = 6;
|
||||
break;
|
||||
|
||||
case 6:
|
||||
W_PWM = 0;
|
||||
C_PWM = 0;
|
||||
direction = 1;
|
||||
driveMode=1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
UpdateDisplay_1();
|
||||
}
|
||||
|
||||
void Mode3(){ //爆闪 //无
|
||||
|
||||
UpdateDisplay();
|
||||
}
|
||||
pfunc modefunctin[] = { //模式切换,一共15个模式
|
||||
Mode0,
|
||||
Mode1,
|
||||
Mode2,
|
||||
Mode3,
|
||||
};
|
||||
void choice_mode(){
|
||||
if (!timer1.active && timer1.count == 0){
|
||||
if(Mode==mode0){
|
||||
startTimer(&timer1,1);
|
||||
}else if(Mode==mode1){
|
||||
if(breathespeed_flag==0){
|
||||
startTimer(&timer1,time_1[Speed]);
|
||||
}else {
|
||||
startTimer(&timer1,time_1[Speed]+10);
|
||||
}
|
||||
|
||||
}else if(Mode==mode2){
|
||||
startTimer(&timer1,time_2[Speed]);
|
||||
}else if(Mode==mode3){
|
||||
startTimer(&timer1,time_3[Speed]);//
|
||||
}
|
||||
|
||||
modefunctin[Mode]();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user