trigPin = 7
echoPin = 8
 
arduino = Runtime.createAndStart("arduino", "Arduino")
arduino.connect("COM15")
sr04 = Runtime.createAndStart("sr04", "UltrasonicSensor")
 
sr04.attach(arduino, trigPin, echoPin)
# blocking examples
duration = sr04.ping()
print duration
range = sr04.range()
print range
# non blocking - event example
sr04.startRanging()
 
References
 

beetlejuice

10 years 5 months ago

that work very well :-)