Пример #1
0
def main():
	wm=wimote.connect(Led)
	while True:
		button=wimote.whichbutton(wm)
		time.sleep(0.05)
		wm.rumble=False
	
			
		#Moving Forwards		
		if button==3:
			distance_front = usonic.reading(Trigger_front,Echo_front)
			print distance_front
			if distance_front < Collision:
				wm.rumble=True
				#led.off(Led)
				motor.stop()
			elif distance_front >= Collision:
				#led.on(Led)
				motor.forward()
		#Reverse
		if button==4:
			motor.reverse()
		if button==7:
			motor.cleanup()
			led.cleanup()
			usonic.cleanup()
			sys.exit()
		if button==None:
			led.off(Led)
			motor.stop()
Пример #2
0
import usonic

# Create new sensor object
front_sensor = usonic.newSensor(19, 26)

# Get reading until interrupted (ctrl-c)
try:
	while True:
		dist = front_sensor.getDist()

		# Output the details
		print("Distance reads", dist)
finally:
	# Clean up sensors
	usonic.cleanup()