创作过程及功能演示:
基于stm32的DIY作品——表情包盒_哔哩哔哩_bilibili
(三连三连三连0^0重要的话说三遍)
部分代码:
main.c
#include "stm32f10x.h" // Device header
#include "OLED.H"
#include "PWM.H"
#include "Delay.h"
#include "Servo.h"
#include "key.h"
#include "Timer.h"
#include "Servo.h"
uint8_t i;
uint8_t time;
uint8_t KeyNum;
uint8_t Servo_time;
int main(void)
{
OLED_Init();
PWM_Init();
Timer_Init();
key_Init();
OLED_Clear();
Servo_SetAngle(78);
//Servo_SetAngle(115);
while(1)
{
if(i == 0)
{
if(KeyNum == 1)
{
Servo_SetAngle(115);
OLED_BMP(7);
Delay_ms(500);
OLED_Clear();
Delay_ms(500);
OLED_BMP(7);
Delay_ms(500);
OLED_Clear();
Delay_ms(500);
OLED_BMP(7);
Delay_ms(1000);
Servo_Control_Speed(115,78);
OLED_Clear();
i++;
}
}
else if(i == 1)
{
if(KeyNum == 1)
{
Servo_SetAngle(115);
OLED_BMP(7);
Delay_ms(300);
OLED_Clear();
Delay_ms(300);
OLED_BMP(7);
Delay_ms(1500);
OLED_BMP(8);
Delay_ms(1500);
Servo_SetAngle(78);
OLED_Clear();
i ++;
}
}
else if(i == 2)
{
if(KeyNum == 1)
{
Servo_SetAngle(115);
OLED_BMP(5);
Delay_ms(3000);
Servo_Control_Speed(115,78);
OLED_Clear();
i = 0;
}
}
}
}
//void Servo_Delay(uint8_t TIME)
//{
// Servo_time++;
// if(Servo_time==5)
// {
// Servo_SetAngle(i);
// Servo_time=0;
// }
//}
void TIM3_IRQHandler(void)//定时器的中断,不是编码器的中断,编码器的要自己测速
{
if(TIM_GetITStatus(TIM3,TIM_IT_Update)==SET)
{
time++;
if(time==5)
{
KeyNum = keynum_get();
time=0;
}
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
}
}
全套资源:
百度网盘链接:https://pan.baidu.com/s/14wJvLBdRrVVYME2wJ0vKCQ?pwd=pjlm
提取码:pjlm