Herunterladen Inhalt Inhalt Diese Seite drucken

SunFounder Da Vinci Kit Bedienungsanleitung Seite 255

Für den raspberry pi 4 modell b, 3 modell a +, 3 modell b +, 3 modell b, 2 modell b, 1 modell b +, 1 modell a +, zero w and zero
Inhaltsverzeichnis

Werbung

}
float
disMeasure(void)
{
struct
timeval tv1;
struct
timeval tv2;
time1, time2;
long
float
dis;
digitalWrite(Trig, LOW);
delayMicroseconds(2);
digitalWrite(Trig, HIGH);
delayMicroseconds(10);
digitalWrite(Trig, LOW);
while(!(digitalRead(Echo)
gettimeofday(&tv1, NULL);
while(!(digitalRead(Echo)
gettimeofday(&tv2, NULL);
time1
=
tv1.tv_sec
time2
=
tv2.tv_sec
dis
=
(float)(time2
return
dis;
}
int
main(void)
{
float
dis;
if(wiringPiSetup()
printf("setup wiringPi failed
return
1;
}
ultraInit();
while(1){
dis
=
disMeasure();
printf("%0.2f
delay(300);
}
return
0;
}
Code Erklärung
void
ultraInit(void)
{
pinMode(Echo, INPUT);
pinMode(Trig, OUTPUT);
}
1.8. 2 Eingabe
==
1));
==
0));
1000000
+
tv1.tv_usec;
*
1000000
+
tv2.tv_usec;
*
-
time1)
/
1000000
==
-1){
//when initialize wiring failed,print message to screen
!");
cm\n\n",dis);
34000
/
2;
*
SunFounder Da Vinci Kit
(Fortsetzung der vorherigen Seite)
251

Werbung

Inhaltsverzeichnis
loading

Verwandte Produkte für SunFounder Da Vinci Kit

Diese Anleitung auch für:

Davinci-kit-for-raspberry-pi

Inhaltsverzeichnis