import time
import random
from gpiozero import LED
from adafruit_servokit import ServoKit
kit = ServoKit(channels=16)
laser = LED(17)
global lastx
global lasty
def moveto(xpos,ypos):
global lastx
global lasty
global maxnum
print(str(lastx) + "," + str(lasty) + " ---> " + str(xpos) + "," + str(ypos))
xnum = abs(xpos - lastx)
ynum = abs(ypos - lasty)
if (xpos > lastx):
xstep = 1
else:
xstep = -1
if (ypos > lasty):
ystep = 1
else:
ystep = -1
if (ynum > xnum):
maxnum = ynum
else:
maxnum = xnum
print ("Stappen: " + str(maxnum))
for n in range (0,maxnum):
if (lastx != xpos):
lastx += xstep
kit.servo[0].angle = lastx
if (ypos != lasty):
lasty += ystep
kit.servo[4].angle = lasty
time.sleep(0.03)
t = 0
lastx = 0
lasty = 0
xmax = 160
xmin = 100
ymax = 140
ymin = 100
kit.servo[0].angle = xmin
kit.servo[4].angle = ymin
print ("BIRDZAPPER v0.1")
print ("---------------")
print ()
print ("Ctrl-C om te stoppen")
print ()
while True:
xwaarde = random.randint(xmin,xmax)
ywaarde = random.randint(ymin, ymax)
laser.on()
moveto(xwaarde,ywaarde)
laser.off()
time.sleep(random.randint(3,7))