-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkeyboardinput.py
executable file
·82 lines (68 loc) · 1.6 KB
/
keyboardinput.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/python3
import curses
from curses import wrapper
from gpiozero import LED
from time import sleep
# Constants
motor1F = LED(23) # pin 16 on rpi0
motor2F = LED(24) # pin 18
motor1R = LED(27) # pin 13
motor2R = LED(17) # pin 11
def Forward():
motor1F.on()
motor2R.on()
sleep(0.1)
motor1F.off()
motor2R.off()
sleep(0)
def Back():
motor2F.on()
motor1R.on()
sleep(0.1)
motor2F.off()
motor1R.off()
sleep(0)
def Clockwise():
motor1F.on()
motor1R.on()
sleep(0.1)
motor1F.off()
motor1R.off()
sleep(0)
def Anticlockwise():
motor2F.on()
motor2R.on()
sleep(0.1)
motor2F.off()
motor2R.off()
sleep(0)
def main(screen):
screen = curses.initscr()
curses.noecho()
curses.cbreak()
screen.keypad(True)
screen.addstr("Hello World!!!")
screen.addstr("PRESS THE ARROW KEYS TO MOVE THE CAR")
while True:
c = screen.getch()
if c == curses.KEY_LEFT:
screen.addstr(5,10, 'left key pressed')
Anticlockwise()
screen.refresh()
elif c == curses.KEY_RIGHT:
screen.addstr(5,50, 'right key pressed')
Clockwise()
screen.refresh()
elif c == curses.KEY_UP:
screen.addstr(2,30,'UP key pressed')
Forward()
screen.refresh()
elif c == curses.KEY_DOWN:
screen.addstr(9,30,'Down key pressed')
Back()
screen.refresh()
curses.nobreak()
screen.keypad(False) # Enable keypad Mode
curses.echo()
curses.endwin()
wrapper(main)