日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

stm32(声音传感器控制LED)

發布時間:2024/3/12 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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);#endif

BLED.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);#endif

Voice.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)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。