raspberrypi/gpio/info_ultrasound.c
aixiao 084f378a18 20180911
增加 dth11 温度湿度传感器
目前工作的有DS18B20温度传感、DTH11温度湿度传感器
未测试的有info_sound、info_ultrasound、info_infrared二进制程序

	修改:     gpio/Makefile
	新文件:   gpio/conf/info.conf
	新文件:   gpio/dth11.c
	删除:     gpio/info_infrared
	修改:     gpio/info_infrared.c
	删除:     gpio/info_light
	修改:     gpio/info_light.c
	删除:     gpio/info_pin
	修改:     gpio/info_pin.c
	删除:     gpio/info_sound
	修改:     gpio/info_sound.c
	删除:     gpio/info_ultrasound
	修改:     gpio/info_ultrasound.c
	修改:     gpio/log/light.pid
	修改:     gpio/log/wind.pid
	新文件:   gpio/log/wind_daemon.pid
	删除:     gpio/wind
	修改:     gpio/wind.c
2018-09-11 14:35:16 +00:00

42 lines
934 B
C

#include <wiringPi.h>
#include <sys/time.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char * argv[])
{
if( argc != 3) {
exit(0);
}
int pin_tring = atol(argv[1]);
int pin_echo = atol(argv[2]);
struct timeval tv1;
struct timeval tv2;
long start_time, stop_time;
float distance;
if(wiringPiSetup() == -1) {
exit(0);
return 0;
}
digitalWrite(pin_tring, LOW);
digitalWrite(pin_tring, HIGH);
delayMicroseconds(10);
digitalWrite(pin_tring, LOW);
while(!(digitalRead(pin_echo) == 1));
gettimeofday(&tv1, NULL);
while(!(digitalRead(pin_echo) == 0));
gettimeofday(&tv2, NULL);
start_time = tv1.tv_sec * 1000000 + tv1.tv_usec;
stop_time = tv2.tv_sec * 1000000 + tv2.tv_usec;
distance = (float)(stop_time - start_time) / 1000000 * 34000 / 2;
printf("%0.0f\n", distance);
return distance;
}