Untitled
import event, time, cyberpi, gamepad, mbot2, mbuild import time # initialize variables ok = 0 @event.start def on_start(): while True: if gamepad.is_key_pressed('R1'): cyberpi.display.show_label("RESET", 24, "center", index= 0) mbot2.servo_set(0,"S2") mbot2.servo_set(180,"S1") time.sleep(2) ok = 0 @event.start def on_start1(): mbot2.servo_set(180,"S1") mbot2.servo_set(0,"S2") while True: if gamepad.is_key_pressed('Up'): mbot2.forward(220, 0.2) if gamepad.is_key_pressed('Left'): mbot2.turn(-35) if gamepad.is_key_pressed('Right'): mbot2.turn(35) if gamepad.is_key_pressed('Down'): mbot2.backward(220, 0.2) if gamepad.is_key_pressed('N2'): mbot2.forward(50, 0.2) if gamepad.is_key_pressed('N1'): mbot2.turn(-15) if gamepad.is_key_pressed('N4'): mbot2.turn(15) if gamepad.is_key_pressed('N3'): mbot2.backward(50, 0.2) @event.start def on_start2(): while True: if mbuild.ultrasonic2.get(1) < 5 and ok == 0: cyberpi.display.show_label("PICKING UP", 24, "center", index= 0) mbot2.servo_set(135,"S1") time.sleep(0.5) mbot2.servo_set(20,"S2") time.sleep(0) mbot2.servo_set(180,"S1") cyberpi.console.clear() ok = 1
Leave a Comment