Electric car alarm based on Orange Piede
1 Overview
This small project is implemented based on the Orange Pi IO port to output high and low levels; the hardware modules used include Orange Pi, relays, 433M wireless modules, vibration sensors, and speakers.
2 code
#include<stdio.h>
#include<wiringPi.h>
#include<unistd.h>
#define D0_ON 14
#define D1_OFF 12
#define sw1 16
#define vibrate 9
#define J_OFF 0
#define J_ON 1
int main()
{
int mark=J_OFF;//代表此时不处于警报模式
if (wiringPiSetup() == -1)
{
printf("硬件接口初始化失败\n");
return -1;
}
pinMode(D0_ON,INPUT);
pinMode(D1_OFF,INPUT);
pinMode(sw1, OUTPUT);
pinMode(vibrate,INPUT);
digitalWrite(sw1, HIGH);
digitalWrite(D0_ON, LOW);
digitalWrite(D1_OFF, LOW);
digitalWrite(vibrate,HIGH);
while(1)
{
if(digitalRead(D0_ON)==1)
{
printf("长响\n");
digitalWrite(sw1,LOW);
sleep(2);
digitalWrite(sw1,HIGH);
mark=J_ON;
}
if(digitalRead(D1_OFF)==0)
{
printf("短响\n");
digitalWrite(sw1,HIGH);
usleep(500000);
digitalWrite(sw1,HIGH);
mark=J_OFF;
}
if(mark==J_ON)
{
if(digitalRead(vibrate)==0)
{
printf("喇叭响\n");
digitalWrite(sw1,LOW);
}
else
{
printf("喇叭不响\n");
digitalWrite(sw1,HIGH);
}
}
}
return 0;
}
3. Summarize
This small project is a small project done in the process of learning Orange Pie. I am looking for some fun in the process of learning; I hope everyone can give me corrections.