Skillnad mellan versioner av "Grove - Ultrasonic Ranger"
Rad 60: | Rad 60: | ||
[[Category:Grove]] | [[Category:Grove]] | ||
+ | [[Category:Grove-Sensor]] | ||
+ | |||
[[Category:Kna-Wiki]] | [[Category:Kna-Wiki]] |
Nuvarande version från 4 februari 2021 kl. 07.31
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"