def simple_input(): print('up') PressKey(W) time.sleep(3) ReleaseKey(W) print('down') PressKey(S) time.sleep(2) ReleaseKey(S)
ser = serial.Serial( 'COM3', baudrate=9600, timeout=1) # change COM3 to your port in which arduino is connected while True: portdata = ser.readline().decode( 'ascii') # read the data comming from arduino if len(portdata) == 0: print("no data comming........", end="\n" ) # port is connected but no data is avaliable on serial port ser.flushInput() if len(portdata) != 0: # if data is avaliable on the serial port if portdata[0] == 'q': # check the data PressKey(W) #simulate key input PressKey(A) time.sleep(0.2) ReleaseKey(W) ReleaseKey(A) ser.flushInput( ) # clear the queues of data on Serial port that stored while simulating key input elif portdata[0] == 'e': PressKey(W) PressKey(D) time.sleep(0.2) ReleaseKey(W) ReleaseKey(D) ser.flushInput() elif portdata[0] == 'z': PressKey(S) PressKey(A) time.sleep(0.2) ReleaseKey(S)
x_current = x y_current = y w_current = w h_current = h cv2.line(frame, (x_init, (2 * y_init + h_init) // 2), (x_init + w_init, (2 * y_init + h_init) // 2), (0, 0, 255), thickness=1) cv2.line(frame, ((2 * x_init + w_init) // 2, y_init), ((2 * x_init + w_init) // 2, y_init + h_init), (0, 0, 255), thickness=1) cv2.rectangle(frame, (x_current, y_current), (x_current + w_current, y_current + h_current), (0, 255, 0), thickness=1) if (y_current - y_init > threshold_down) and (ARROW_DOWN == False): PressKey(DOWN) ReleaseKey(DOWN) ARROW_DOWN = True print("DOWN") if (y_init - y_current > threshold_up) and (ARROW_UP == False): PressKey(UP) ReleaseKey(UP) ARROW_UP = True print("UP") if (x_current - x_init > threshold) and (ARROW_RIGHT == False): PressKey(RIGHT) ReleaseKey(RIGHT) ARROW_RIGHT = True print("Right")
def right(): PressKey(W) PressKey(D) ReleaseKey(A) time.sleep(t_time) ReleaseKey(D)
def left(): PressKey(W) PressKey(A) ReleaseKey(D) time.sleep(t_time) ReleaseKey(A)
def straight(): PressKey(W) ReleaseKey(A) ReleaseKey(D)
def slow_ya_roll(): ReleaseKey(W) ReleaseKey(A) ReleaseKey(D)
def right(): PressKey(D) ReleaseKey(A) ReleaseKey(W) ReleaseKey(D)
def left(): PressKey(A) ReleaseKey(W) ReleaseKey(D) ReleaseKey(D)
def slow_down(): ReleaseKey(W) ReleaseKey(A) ReleaseKey(D)