stm32 pwm 呼吸灯OLED显示数字
时间: 2024-02-17 13:56:56 浏览: 109
stm32呼吸灯
以下是使用STM32的PWM实现呼吸灯和OLED显示数字的代码:
```c
#include "stm32f10x.h"
#include "Delay.h"
#include "Buzzer.h"
#include "Key.h"
#include "Light_Seror.h"
#include "OLED.h"
#include "PWM.h"
int main(void)
{
uint16_t i, j;
char str[20];
OLED_Init();
PWM_Init();
while(1)
{
// PWM实现呼吸灯
for(i = 0; i <= 100; i++){
PWM_SetCompare1(i);
Delay_ms(10);
}
for(i = 0; i <= 100; i++){
PWM_SetCompare1(100-i);
Delay_ms(10);
}
// OLED显示数字
OLED_Clear();
sprintf(str, "Count: %d", j++);
OLED_ShowString(0, 0, (uint8_t*)str);
Delay_ms(1000);
}
}
```
阅读全文