Birdset: bepaal de minimale en maximale coördinaten van de birdzap laser

Gepubliceerd door Robot One op

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
from gpiozero import LED
from adafruit_servokit import ServoKit
import tty, sys, termios
kit = ServoKit(channels=16)
laser = LED(17)
filedescriptors = termios.tcgetattr(sys.stdin)
tty.setcbreak(sys.stdin)
x = 0
y = 0
print (chr(12)) # dit is een truc die we nog uit Basic kennen (cls)
print ("BIRDZAPPER 0.2")
print ("______________")
print ()
print ()
print ("Gebruik de pijltjestoetsen om de laser te positioneren")
print ("Noteer de minimum an maximum waarden van x en y")
print ()
x = 0
y = 0
while True:
print ("Waarde X = " + str(x) + " Y = " + str(y))
print ()
kit.servo[0].angle = x
kit.servo[4].angle = y
toets=sys.stdin.read(1)
ascii = ord(toets)
if (ascii == 27): #esc, stop ermee
termios.tcsetattr(sys.stdin, termios.TCSADRAIN,filedescriptors)
break
if (toets == "a") or (toets == "A") or (toets == "4"): # left
x -= 2 # stapjes van 1 zijn wel heel erg klein
if (x < 0):
x = 0
if (toets == "d") or (toets == "D") or (toets == "6"): # right
x += 2
if (x > 180):
x = 180
if (toets == "w") or (toets == "W") or (toets == "8"): # up
y += 2
if (y > 180):
y = 180
if (toets == "s") or (toets == "S") or (toets == "2"): # down
y -= 2
if (y < 0):
y = 0
print ()
# Herstel terminal output
termios.tcsetattr(sys.stdin, termios.TCSADRAIN,filedescriptors)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Categorieën: