#ifndef __INFRARED_H__
#define __INFRARED_H__
#include <stdio.h>
#include <wiringPi.h>
#include <sys/time.h>
/*使用C语言GPIO库wiringPi约定的编号
*/
#define ObstaclePin_left 7 //红外传感器的信号传输口
#define ObstaclePin_right 0
int Obstacle_left;
int Obstacle_right;
void IO_InfraInit()
{
printf("Infrarouge Init begin\n");
pinMode(ObstaclePin_left, INPUT); //红外传感器的信号传输口,信号从红外传感器进入RaspberryPi。
pinMode(ObstaclePin_right, INPUT);
printf("Infrarouge Init end\n");
}
int obsMeasure_left() // 红外传感器检测两侧障碍物是否在安全距离以外
// 安全距离的设定,通过红外传感器上面的可调旋钮调节。
{
Obstacle_left = digitalRead(ObstaclePin_left);
if(Obstacle_left == HIGH)
{
printf("LEFT NORMAL...\n");
delay(1000);
}
else
{
printf("LEFT OBSTACLE!!!...OBSTACLE!!!...\n");
delay(1000);
}
return Obstacle_left;
}
int obsMeasure_right()
{
Obstacle_right = digitalRead(ObstaclePin_right);
if(Obstacle_right == HIGH)
{
printf("RIGHT NORMAL...\n");
delay(1000);
}
else
{
printf("RIGHT OBSTACLE!!!...OBSTACLE!!!...\n");
delay(1000);
}
return Obstacle_right;
}
/*int main(void)
{
wiringPiSetup();
if (-1 == wiringPiSetup())
{
printf("Setup wiringPi failed!");
return 1;
}
IO_InfraInit();
obsMeasure_left();
obsMeasure_right();
return 0;
}*/
#endif