-
Notifications
You must be signed in to change notification settings - Fork 1
/
canine.py
89 lines (73 loc) · 1.75 KB
/
canine.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
79
80
81
82
83
84
85
86
87
88
89
import cwiid
import os
import pygame
import pygame.mixer
import random
from pygame.mixer import Sound
from gpiozero import Robot
from gpiozero import LED
from gpiozero import Button
from signal import pause
from time import sleep
robot = Robot(left=(10, 9), right=(8, 7))
red = LED(27)
blue = LED(22)
button = Button(17)
button_delay = 0.1
def barking():
randomfile = random.sample(os.listdir("/home/pi/K9audio/"), 1)[0]
wooffile = '/home/pi/K9audio/'+ randomfile
woof = Sound(wooffile)
woof.play()
red.on()
blue.on()
pygame.mixer.init()
randomfile = ''
wooffile = ''
file = '/home/pi/K9audio/i-am-k9-mk-3.wav'
bark = Sound(file)
bark.play()
sleep(5)
button.when_pressed = barking
blue.blink()
try:
wii=cwiid.Wiimote()
except RuntimeError:
# Uncomment this line to shutdown the Pi if pairing fails
#os.system("sudo halt")
quit()
wii.led = 1
blue.on()
yesfile = '/home/pi/K9audio/affirmative.wav'
yes = Sound(yesfile)
yes.play()
wii.rpt_mode = cwiid.RPT_BTN
while True:
buttons = wii.state['buttons']
# If Plus and Minus buttons pressed
# together then rumble and quit.
if (buttons - cwiid.BTN_PLUS - cwiid.BTN_MINUS == 0):
wii.rumble = 1
sleep(1)
wii.rumble = 0
red.off()
blue.off()
os.system("sudo halt")
exit(wii)
if (buttons & cwiid.BTN_LEFT):
robot.left()
sleep(button_delay)
elif(buttons & cwiid.BTN_RIGHT):
robot.right()
sleep(button_delay)
elif (buttons & cwiid.BTN_UP):
robot.forward()
sleep(button_delay)
elif (buttons & cwiid.BTN_DOWN):
robot.backward()
sleep(button_delay)
elif (buttons & cwiid.BTN_A):
barking()
sleep(button_delay)
else:
robot.stop()