import RPi.GPIO as GPIO
import time as time
import os
GPIO.setmode(GPIO.BCM)
GPIO.setup(3,GPIO.OUT)
pwm = GPIO.PWM(3,60)
pwm.start(0)
GPIO.setup(2,GPIO.OUT)
pwm2 = GPIO.PWM(2,60)
pwm2.start(0)
GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(20, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def setAngleGreen(angle):
duty = angle / 18 + 2
GPIO.output(3,True)
pwm.ChangeDutyCycle(duty)
time.sleep(1)
GPIO.output(3,False)
pwm.ChangeDutyCycle(0)
def setAngleRed(angle):
duty = angle / 18 + 2
GPIO.output(2,True)
pwm2.ChangeDutyCycle(duty)
time.sleep(1)
GPIO.output(2,False)
pwm2.ChangeDutyCycle(0)
def fuckYou():
os.system('sudo mplayer -volume 60 /home/pi/Desktop/goodbey-i-nator/FuckYou.wav &')
for i in range(1, 8):
setAngleRed((i*20))
setAngleRed(10)
def playSweetGoodbey():
os.system('sudo mplayer -volume 60 /home/pi/Desktop/goodbey-i-nator/GoodBye.wav &')
for i in range(1, 10):
setAngleGreen(200-(i* 10))
time.sleep(0.15)
setAngleGreen(200)
while True:
input_state_green = GPIO.input(21)
input_state_red = GPIO.input(20)
if input_state_green == False:
playSweetGoodbey()
elif input_state_red == False:
fuckYou()
time.sleep(0.2)
pwm.stop()
Comments