Skillnad mellan versioner av "Grove - Ultrasonic Ranger"
Rad 34: | Rad 34: | ||
delay(250); | delay(250); | ||
} | } | ||
− | <syntaxhighlight> | + | </syntaxhighlight> |
=== Raspberry Pi === | === Raspberry Pi === | ||
Rad 53: | Rad 53: | ||
except IOError: | except IOError: | ||
print "Error" | print "Error" | ||
− | <syntaxhighlight> | + | </syntaxhighlight> |
== Mer information == | == Mer information == |
Versionen från 26 oktober 2018 kl. 21.19
Ultrasonic Ranger är en mätmodul utan kontakt. Utgången mäts i antingen cm eller tum, (motsvarar PWM bredden på signalen).
Innehåll
Kompatibilitet
- Arduino
- Raspberry Pi
Port
Digital
Bibliotek
https://github.com/Seeed-Studio/Grove_Ultrasonic_Ranger/archive/master.zip
Exempelkod
Arduino
#include "Ultrasonic.h"
Ultrasonic ultrasonic(5);
void setup() {
Serial.begin(9600);
}
void loop() {
long RangeCm;
long RangeInch;
Serial.println("Range, cm: ");
RangeCm = ultrasonic.MeasureInCentimeters();
Serial.print(RangeCm);
Serial.println(" cm");
delay(250);
RangeInch = ultrasonic.MeasureInInches();
Serial.println("Range, inch: ");
Serial.print(RangeInch);
Serial.println(" inch");
delay(250);
}
Raspberry Pi
from grovepi import *
# Connect the Grove Ultrasonic Ranger to digital port D4
ultrasonic_ranger = 4
while True:
try:
# Read distance value from Ultrasonic
print ultrasonicRead(ultrasonic_ranger)
except TypeError:
print "Error"
except IOError:
print "Error"