stm32(声音传感器控制LED)
生活随笔
收集整理的這篇文章主要介紹了
stm32(声音传感器控制LED)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
BLED.h:
#ifndef __BLED_H #define __BLED_Hvoid BLED_Init(void); void BLED1_ON(void); void BLED1_OFF(void);void BLED1_Turn(void);#endifBLED.c:
#include "stm32f10x.h" // Device header //led初始化 void BLED_Init(void){RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);//ctrl alt konggeGPIO_InitTypeDef GPIO_InitStructure;GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;GPIO_InitStructure.GPIO_Pin=GPIO_Pin_12;GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;GPIO_Init(GPIOB,&GPIO_InitStructure);GPIO_SetBits(GPIOB,GPIO_Pin_12); } //led1亮 void BLED1_ON(void){GPIO_ResetBits(GPIOB,GPIO_Pin_12); } //led1滅 void BLED1_OFF(void){GPIO_SetBits(GPIOB,GPIO_Pin_12); } //led1狀態反轉 void BLED1_Turn(void){if(GPIO_ReadOutputDataBit(GPIOB,GPIO_Pin_12)==0){GPIO_SetBits(GPIOB,GPIO_Pin_12);}else{GPIO_ResetBits(GPIOB,GPIO_Pin_12);} }Voice.h:
#ifndef __VOICE_H #define __VOICE_H//聲音傳感器初始化 void VoiceSensor_Init(void); //獲取傳感器狀態 uint8_t VoiceSensor_Get(void);#endifVoice.c:
#include "stm32f10x.h" // Device headervoid VoiceSensor_Init(void) {RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);GPIO_InitTypeDef GPIO_InitStructure;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init(GPIOB, &GPIO_InitStructure); }uint8_t VoiceSensor_Get(void) {return GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_13); }main.c:
#include "stm32f10x.h" // Device header #include "Delay.h" #include "BLED.h" #include "voice.h" //uint8_t KeyNum; int main(void) {BLED_Init();VoiceSensor_Init();while (1){if (VoiceSensor_Get() == 1){BLED1_ON();}else{BLED1_OFF();}} }寫博客為了記錄筆記,不怕丟
總結
以上是生活随笔為你收集整理的stm32(声音传感器控制LED)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux删除带用户的群组,Linux账
- 下一篇: 简单易懂的P2P通信原理