/* USER CODE BEGIN 3 */
/*按键判断函数,flag_shu在程序下面有*/
flag = flag_shu();
switch(flag)
{
case 1:
flag_key = 1;
break;
case 2:
flag_key = 2;
break;
case 3:
flag_key = 3;
break;
case 4:
flag_key = 4;
break;
case 5:
flag_key = 5;
break;
case 6:
flag_key = 6;
break;
case 7:
flag_key = 7;
break;
case 8:
flag_key = 8;
break;
}
/*陀螺仪工作模式*/
if(flag_key==1)
{
OLED_Clear();
sprintf(str,"gyroscope");
OLED_ShowString(0,0,str);
MPU6050ReadGyro(Gyro);
sprintf(str,"tuo: %4d",Gyro[0]);
OLED_ShowString(0,2,str);
sprintf(str,"tuo: %4d",Gyro[1]);
OLED_ShowString(0,4,str);
sprintf(str,"tuo: %4d",Gyro[2]);
OLED_ShowString(0,6,str);
delay_ms(100);
}
if(flag_key==2)
{
OLED_Clear();
sprintf(str,"accelerate");
OLED_ShowString(0,0,str);
MPU6050ReadGyro(Accel);
sprintf(str,"a1: %4d",Accel[0]);
OLED_ShowString(0,2,str);
sprintf(str,"a2: %4d",Accel[1]);
OLED_ShowString(0,4,str);
sprintf(str,"a3: %4d",Accel[2]);
OLED_ShowString(0,6,str);
delay_ms(100);
}
if(flag_key==3)
{
OLED_Clear();
sprintf(str,"tempture");
OLED_ShowString(0,0,str);
MPU6050_ReturnTemp(&Temp);
sprintf(str,"t:%d C",Temp);
OLED_ShowString(0,2,str);
delay_ms(100);
}
/*电机控制模式*/
if(flag_key==4)
{
if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_13) == GPIO_PIN_SET)
{
OLED_Clear();
sprintf(str,"Sevor");
OLED_ShowString(0,0,str);
cnt = ((float)(ZhuPin))/((float)(Fenpin))/((float)(ZhouQi))/((float)(Dianji_Fenpin));
sprintf(str,"n: %.3f r/s",cnt);
OLED_ShowString(0,2,str);
sprintf(str,"FX:shunshizhen");
OLED_ShowString(0,4,str);
}
if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_13) == GPIO_PIN_RESET)
{
OLED_Clear();
sprintf(str,"Sevor");
OLED_ShowString(0,0,str);
cnt = ((float)(ZhuPin))/((float)(Fenpin))/((float)(ZhouQi))/((float)(Dianji_Fenpin));
sprintf(str,"n: %.3f r/s",cnt);
OLED_ShowString(0,2,str);
sprintf(str,"FX:nishizhen");
OLED_ShowString(0,4,str);
}
delay_ms(100);
}
if(flag_key==5)
{
OLED_Clear();
sprintf(str,"SevorMoshiTiaoZheng");
OLED_ShowString(0,0,str);
cnt = ((float)(ZhuPin))/((float)(Fenpin))/((float)(ZhouQi))/((float)(Dianji_Fenpin));
sprintf(str,"n: %.3f r/s",cnt);
OLED_ShowString(0,2,str);
sprintf(str,"FX:shunshizhen");
OLED_ShowString(0,4,str);
GPIO_SetBits(GPIOB,GPIO_PIN_13);
delay_ms(200);
}
if(flag_key==6)
{
OLED_Clear();
sprintf(str,"SevorMoshi");
OLED_ShowString(0,0,str);
cnt = ((float)(ZhuPin))/((float)(Fenpin))/((float)(ZhouQi))/((float)(Dianji_Fenpin));
sprintf(str,"n: %.3f r/s",cnt);
OLED_ShowString(0,2,str);
sprintf(str,"FX:nishizhen");
OLED_ShowString(0,4,str);
GPIO_ResetBits(GPIOB,GPIO_PIN_13);
delay_ms(200);
}
if(flag_key==7)
{
OLED_Clear();
sprintf(str,"SevorMoshi");
OLED_ShowString(0,0,str);
cnt = ((float)(ZhuPin))/((float)(Fenpin))/((float)(ZhouQi))/((float)(Dianji_Fenpin));
sprintf(str,"n: %.3f r/s",cnt);
OLED_ShowString(0,2,str);
if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_13) == GPIO_PIN_SET)
{
sprintf(str,"FX:shunshizhen");
OLED_ShowString(0,4,str);
}
if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_13) == GPIO_PIN_RESET)
{
sprintf(str,"FX:nishizhen");
OLED_ShowString(0,4,str);
}
OLED_ShowString(0,4,str);
delay_ms(100);
}
if(flag_key==8)
{
OLED_Clear();
sprintf(str,"SevorMoshi");
OLED_ShowString(0,0,str);
cnt = ((float)(ZhuPin))/((float)(Fenpin))/((float)(ZhouQi))/((float)(Dianji_Fenpin));
sprintf(str,"n: %.3f r/s",cnt);
OLED_ShowString(0,2,str);
if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_13) == GPIO_PIN_SET)
{
sprintf(str,"FX:shunshizhen");
OLED_ShowString(0,4,str);
}
if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_13) == GPIO_PIN_RESET)
{
sprintf(str,"FX:nishizhen");
OLED_ShowString(0,4,str);
}
OLED_ShowString(0,4,str);
delay_ms(100);
}
全部资料51hei下载地址:
c8按键控制步进电机+陀螺仪.7z
(3.02 MB, 下载次数: 41)
|