当前位置:网站首页>STM32 - vibration sensor control relay on
STM32 - vibration sensor control relay on
2022-07-03 01:36:00 【Spade fish】
STM32—— The vibration sensor controls the relay to turn on the light
List of articles
Environmental Overview :
Windows10 pro
MDK—Lite 5.25
Hardware list :
1、 Relay
2、USB The lamp
3、SW-1801P Vibration sensors
4、STM32f103c8t6
Be careful :
stay User Folder create related folders and xx.c and xx.h file , Include related header files ,
Some basic operations have been written in previous articles
The experimental steps :
1、 Can make APB2 Medium GPIOA The clock turns on
Where to find relevant functions , It is also written in the previous article
//1、 Can make APB2 Medium GPIOA The clock turns on
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE);
2、 To configure GPIOA Structural content
Before that , In defining structures
GPIO_InitTypeDef Shake_GPIO_Init;
// Drop down input
Shake_GPIO_Init.GPIO_Mode = GPIO_Mode_IPD;
// Set pin to A1
Shake_GPIO_Init.GPIO_Pin = GPIO_Pin_1;
Shake_GPIO_Init.GPIO_Speed = GPIO_Speed_10MHz;
3、 initialization
GPIO_Init(GPIOA,&Shake_GPIO_Init);
Code :
#include "stm32f10x.h"
#include "shake.h"
void Shake_Init()
{
// Defining structure
GPIO_InitTypeDef Shake_GPIO_Init;
//1、 Can make APB2 Medium GPIOA The clock turns on
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE);
//2、 To configure GPIOA Structural content
// Drop down input
Shake_GPIO_Init.GPIO_Mode = GPIO_Mode_IPD;
// Set pin to A1
Shake_GPIO_Init.GPIO_Pin = GPIO_Pin_1;
Shake_GPIO_Init.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_Init(GPIOA,&Shake_GPIO_Init);
}
main.c file
By reading the level of the sensor , To judge and control the light on
If the reading sensor is low , Then turn on the light
Code :
#include "stm32f10x.h"
#include "led.h"
#include "Relay.h"
#include "Shake.h"
int main(void)
{
LED_Init();// The lamp
Relay_Init();// Relay
Shake_Init();// Vibration sensors
GPIO_SetBits(GPIOA, GPIO_Pin_3);// It's pins 3j Relay high level —— Turn off the lights
while(1){
//1、 By reading the level of the sensor , To judge and control the light on
//
if(GPIO_ReadOutputDataBit(GPIOA,GPIO_Pin_1 == 0)){
// If the reading sensor is low , Then turn on the light
GPIO_ResetBits(GPIOA, GPIO_Pin_3);// turn on the light
delayTime(1000);// Time delay
GPIO_SetBits(GPIOA, GPIO_Pin_3);// Turn off the lights
}else{
GPIO_SetBits(GPIOA, GPIO_Pin_3);// Turn off the lights
}
}
}
summary :
Practice over and over again , Remember the code , Remember the principle , More practice .
边栏推荐
- Qtablewidget lazy load remaining memory, no card!
- Kivy tutorial - example of using Matplotlib in Kivy app
- Arduino DY-SV17F自动语音播报
- Learn the five skills you need to master in cloud computing application development
- Database SQL language 02 connection query
- [C language] detailed explanation of pointer and array written test questions
- JDBC courses
- C#应用程序界面开发基础——窗体控制(1)——Form窗体
- The difference between tail -f, tail -f and tail
- Vim 9.0正式发布!新版脚本执行速度最高提升100倍
猜你喜欢
软考信息系统项目管理师_历年真题_2019下半年错题集_上午综合知识题---软考高级之信息系统项目管理师053
[QT] encapsulation of custom controls
SSL flood attack of DDoS attack
【QT】自定义控件的封装
C#应用程序界面开发基础——窗体控制(3)——文件类控件
Why can't the start method be called repeatedly? But the run method can?
Pytest learning notes (12) -allure feature · @allure Step () and allure attach
[FPGA tutorial case 6] design and implementation of dual port RAM based on vivado core
[androd] module dependency replacement of gradle's usage skills
[technology development-23]: application of DSP in future converged networks
随机推荐
Using tensorboard to visualize the model, data and training process
2022 coal mine gas drainage examination question bank and coal mine gas drainage examination questions and analysis
What operations need attention in the spot gold investment market?
【數據挖掘】任務6:DBSCAN聚類
Button wizard play strange learning - automatic return to the city route judgment
C语言课程信息管理系统
MySQL foundation 04 MySQL architecture
SSL flood attack of DDoS attack
看完这篇 教你玩转渗透测试靶机Vulnhub——DriftingBlues-9
Three core issues of concurrent programming - "deep understanding of high concurrent programming"
leetcode刷题_两数之和 II - 输入有序数组
【第29天】给定一个整数,请你求出它的因子数
给你一个可能存在 重复 元素值的数组 numbers ,它原来是一个升序排列的数组,并按上述情形进行了一次旋转。请返回旋转数组的最小元素。【剑指Offer】
Type expansion of non ts/js file modules
Telecom Customer Churn Prediction challenge
[day 29] given an integer, please find its factor number
[C language] detailed explanation of pointer and array written test questions
[error record] the shutter component reports an error (no directionality widget found. | richtext widgets require a directionality)
d. LDC build shared library
C language course information management system