Advertisement
qianzhe

Untitled

Aug 15th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 22.38 KB | None | 0 0
  1. # External module imports
  2. from __future__ import division
  3. import RPi.GPIO as GPIO
  4. import time
  5. import pygame
  6.  
  7. # Import the PCA9685 module.
  8. import Adafruit_PCA9685
  9.  
  10. # Import pygame module.
  11. # import pygame
  12.  
  13. # Initialise the PCA9685 using the default address (0x40).
  14. pwm = Adafruit_PCA9685.PCA9685()
  15.  
  16. # GPIO Pin Definitons:
  17. beastStart = 5  # IR Module pin for start position for the Beast (character)
  18. beastShow = 6  # IR Module pin where the Beast (Character) would be at when he appears.
  19. beastShop = 13
  20. belleShow = 19  # IR Module pin where the Belle (Character) would be at when she appears.
  21. belleStart = 26  # IR Module pin for start position for Belle (character)
  22. screenStop = 21  # IR Module pin for the background.
  23.  
  24. # PCA9685 Pin Definitions
  25. belleM_Left = 0  # PWM Pin to send to the Motor Driver.
  26. belleM_Right = 1  # PWM Pin to send to the Motor Driver.
  27. beastM_Right = 2  # PWM Pin to send to the Motor Driver.
  28. beastM_Left = 3  # PWM Pin to send to the Motor Driver.
  29. screen_Left = 4  # PWM Pin to send to the Motor Driver.
  30. screen_Right = 5  # PWM Pin to send to the Motor Driver.
  31. belleBody = 6
  32. belleArm = 7
  33. beastLeg = 9
  34. beastArm = 8
  35. gboxMotor = 10  # Servo for the gearbox - This is for the one with the motor
  36. gboxNMotor = 11  # Servo for the gearbox - This is for the one WITHOUT the motor.
  37. led_red = 12  # To send to High power LED Driver.
  38. led_green = 13  # To send to High power LED Driver.
  39. led_blue = 14  # To send to High power LED Driver.
  40. led_white = 15  # To send to High power LED Driver.
  41.  
  42. # Configure min and max servo pulse lengths
  43. servo_min = 120  # Min pulse length out of 4096
  44. servo_max = 300  # Max pulse length out of 4096
  45. led_low = 0
  46. led_high = 3560
  47. gearBox_servoMin = 345 #TODO: Very important, pls change. 345 is engage
  48. gearBox_servoMax = 405 #TODO: 405 is disengage
  49. motorSpd = 1596
  50.  
  51. # Pin Setup:
  52. GPIO.setmode(GPIO.BCM)  # Broadcom pin-numbering scheme
  53. GPIO.setup(beastStart, GPIO.IN)  # Button pin set as input w/ pull-up
  54. GPIO.setup(beastShop, GPIO.IN)  # Button pin set as input w/ pull-up
  55. GPIO.setup(beastShow, GPIO.IN)  # Button pin set as input w/ pull-up
  56. GPIO.setup(belleShow, GPIO.IN)  # Button pin set as input w/ pull-up
  57. GPIO.setup(belleStart, GPIO.IN)  # Button pin set as input w/ pull-up
  58. GPIO.setup(screenStop, GPIO.IN)  # Button pin set as input w/ pull-up
  59.  
  60.  
  61. # This is to check if the song has completed playing.
  62. def checkifComplete(channel):
  63.     while channel.get_busy():  # Check if Channel is busy
  64.         pygame.time.wait(800)  # wait in ms
  65.     channel.stop()             # Stop channel
  66.  
  67. # NOTE: Servos work with these values:
  68. # Pulses are at a 50/60Hz interval
  69. # Pulse high vary between 1 to 2 miliseconds, i.e. centre should be 1.5ms
  70.  
  71. # Helper function to make setting a servo pulse width simpler.
  72. def set_servo_pulse(channel, pulse):
  73.     pulse_length = 1000000    # 1,000,000 us per second
  74.     pulse_length //= 60       # 60 Hz
  75.     print('{0}us per period'.format(pulse_length))
  76.     pulse_length //= 4096     # 12 bits of resolution
  77.     print('{0}us per bit'.format(pulse_length))
  78.     pulse *= 1000
  79.     pulse //= pulse_length
  80.     pwm.set_pwm(channel, 0, pulse)
  81.  
  82. # Set frequency to 60hz, good for servos.
  83. pwm.set_pwm_freq(60)
  84.  
  85.  
  86. # Alternatively specify a different address and/or bus:
  87. # pwm = Adafruit_PCA9685.PCA9685(address=0x41, busnum=2)
  88.  
  89.  
  90. print("Here we go! Press CTRL+C to exit")
  91. try:
  92.     if __name__ == "__main__":
  93.         music_file1 = "sounds/Na1.wav"
  94.         music_file2 = "sounds/Shop1.wav"
  95.         music_file3 = "sounds/Beast1.wav"
  96.         music_file4 = "sounds/Shop2.wav"
  97.         music_file5 = "sounds/Beast2.wav"
  98.         music_file6 = "sounds/Shop3.wav"
  99.         music_file7 = "sounds/Beast3.wav"
  100.         music_file8 = "sounds/QZSing.wav"
  101.         music_file9 = "sounds/Na2.wav"
  102.         music_file10 = "sounds/DoorSound.wav"
  103.         music_file11 = "sounds/Beast4.wav"
  104.         music_file12 = "sounds/Belle1.wav"
  105.         music_file13 = "sounds/Beast5.wav"
  106.         music_file14 = "sounds/Belle2.wav"
  107.         music_file15 = "sounds/Beast6.wav"
  108.         music_file16 = "sounds/Belle3.wav"
  109.         music_file17 = "sounds/Beast7.wav"
  110.         music_file18 = "sounds/Belle4.wav"
  111.         music_file19 = "sounds/Na3.wav"
  112.         music_file20 = "sounds/Beast8.wav"
  113.         music_file21 = "sounds/Belle5.wav"
  114.         music_file22 = "sounds/Belle6.wav"
  115.         music_file23 = "sounds/Belle7.wav"
  116.         music_file24 = "sounds/Ambulance.wav"
  117.         music_file25 = "sounds/DrChia.wav"
  118.         music_file26 = "sounds/Beast9.wav"
  119.         music_file27 = "sounds/Beast10.wav"
  120.         music_file28 = "sounds/Na4.wav"
  121.         music_file29 = "sounds/Shop4.wav"
  122.         music_file30 = "sounds/Beast11.wav"
  123.         music_file31 = "sounds/Shop5.wav"
  124.         music_file32 = "sounds/neckCrack.wav"
  125.         music_file33 = "sounds/Na5.wav"
  126.  
  127.         # set up the mixer
  128.         freq = 44100  # audio CD quality
  129.         bitsize = -16  # unsigned 16 bit
  130.         channels = 2  # 1 is mono, 2 is stereo
  131.         buffer = 2048  # number of samples (experiment to get right sound)
  132.         pygame.mixer.init(freq, bitsize, channels, buffer)
  133.         pygame.mixer.set_num_channels(128)
  134.  
  135.         pygame.mixer.init()  # Initialize Mixer
  136.  
  137.         # Create sound object for each Audio
  138.         myAudio1 = pygame.mixer.Sound(music_file1)
  139.         myAudio2 = pygame.mixer.Sound(music_file2)
  140.         myAudio3 = pygame.mixer.Sound(music_file3)
  141.         myAudio4 = pygame.mixer.Sound(music_file4)
  142.         myAudio5 = pygame.mixer.Sound(music_file5)
  143.         myAudio6 = pygame.mixer.Sound(music_file6)
  144.         myAudio7 = pygame.mixer.Sound(music_file7)
  145.         myAudio8 = pygame.mixer.Sound(music_file8)
  146.         myAudio9 = pygame.mixer.Sound(music_file9)
  147.         myAudio10 = pygame.mixer.Sound(music_file10)
  148.         myAudio11 = pygame.mixer.Sound(music_file11)
  149.         myAudio12 = pygame.mixer.Sound(music_file12)
  150.         myAudio13 = pygame.mixer.Sound(music_file13)
  151.         myAudio14 = pygame.mixer.Sound(music_file14)
  152.         myAudio15 = pygame.mixer.Sound(music_file15)
  153.         myAudio16 = pygame.mixer.Sound(music_file16)
  154.         myAudio17 = pygame.mixer.Sound(music_file17)
  155.         myAudio18 = pygame.mixer.Sound(music_file18)
  156.         myAudio19 = pygame.mixer.Sound(music_file19)
  157.         myAudio20 = pygame.mixer.Sound(music_file20)
  158.         myAudio21 = pygame.mixer.Sound(music_file21)
  159.         myAudio22 = pygame.mixer.Sound(music_file22)
  160.         myAudio23 = pygame.mixer.Sound(music_file23)
  161.         myAudio24 = pygame.mixer.Sound(music_file24)
  162.         myAudio25 = pygame.mixer.Sound(music_file25)
  163.         myAudio26 = pygame.mixer.Sound(music_file26)
  164.         myAudio27 = pygame.mixer.Sound(music_file27)
  165.         myAudio28 = pygame.mixer.Sound(music_file28)
  166.         myAudio29 = pygame.mixer.Sound(music_file29)
  167.         myAudio30 = pygame.mixer.Sound(music_file30)
  168.         myAudio31 = pygame.mixer.Sound(music_file31)
  169.         myAudio32 = pygame.mixer.Sound(music_file32)
  170.         myAudio33 = pygame.mixer.Sound(music_file33)
  171.  
  172.         # Create a Channel for each Audio
  173.         myChannel1 = pygame.mixer.Channel(1)
  174.  
  175.  
  176.         pwm.set_pwm(led_red, 0, led_high)
  177.  
  178.         # Audio Narration: The beginning.
  179.  
  180.         myAudio1.set_volume(1)  # Reduce volume of first audio to 80%
  181.         print("Playing audio : ", music_file1)
  182.         myChannel1.play(myAudio1)
  183.         checkifComplete(myChannel1)  # Check if Audio1 complete
  184.  
  185.         pwm.set_pwm(led_red, 0, led_low)
  186.         pwm.set_pwm(led_white, 0, led_high)
  187.  
  188.         time.sleep(1)
  189.         # Move beast to the shop scene
  190.  
  191.         # while time < 10:
  192.         #     pwm.set_pwm(beastLeg, 0, 200)
  193.         #     time.sleep(0.75)
  194.         #     pwm.set_pwm(beastLeg, 0, 400)
  195.         #     time.sleep(0.75)
  196.         #     pwm.set_pwm(beastM_Left, 0, motorSpd)
  197.  
  198.         pwm.set_pwm(beastM_Left, 0, 1024)
  199.         pwm.set_pwm(beastArm, 0, servo_max)
  200.         pwm.set_pwm(beastLeg, 0, servo_max)
  201.         time.sleep(0.75)
  202.         pwm.set_pwm(beastArm, 0, servo_min)
  203.         pwm.set_pwm(beastLeg, 0, servo_min)
  204.         time.sleep(0.75)
  205.         pwm.set_pwm(beastArm, 0, servo_max)
  206.         pwm.set_pwm(beastLeg, 0, servo_max)
  207.         time.sleep(0.75)
  208.         pwm.set_pwm(beastArm, 0, servo_min)
  209.         pwm.set_pwm(beastLeg, 0, servo_min)
  210.         time.sleep(0.75)
  211.         pwm.set_pwm(beastArm, 0, servo_max)
  212.         pwm.set_pwm(beastLeg, 0, servo_max)
  213.         time.sleep(0.75)
  214.         pwm.set_pwm(beastArm, 0, servo_min)
  215.         pwm.set_pwm(beastLeg, 0, servo_min)
  216.         time.sleep(0.75)
  217.         pwm.set_pwm(beastArm, 0, servo_max)
  218.         pwm.set_pwm(beastLeg, 0, servo_max)
  219.         time.sleep(0.75)
  220.  
  221.  
  222.         pwm.set_pwm(beastM_Left, 0, 0)
  223.  
  224.         # Insert Lelong Sound
  225.         myAudio2.set_volume(1)  # Reduce volume of first audio to 80%
  226.         print("Playing audio : ", music_file2)
  227.         myChannel1.play(myAudio2)
  228.         checkifComplete(myChannel1)  # Check if Audio1 complete
  229.  
  230.         # Beast thinking that this is a good deal
  231.         myAudio3.set_volume(1)  # Reduce volume of first audio to 80%
  232.         print("Playing audio : ", music_file3)
  233.         myChannel1.play(myAudio3)
  234.         checkifComplete(myChannel1)  # Check if Audio1 complete
  235.         # Shopkeeper says 50 cents
  236.         myAudio4.set_volume(1)  # Reduce volume of first audio to 80%
  237.         print("Playing audio : ", music_file4)
  238.         myChannel1.play(myAudio4)
  239.  
  240.         pwm.set_pwm(beastArm, 0, servo_min)
  241.         time.sleep(0.75)
  242.  
  243.         checkifComplete(myChannel1)  # Check if Audio1 complete
  244.         # Beast says here you go
  245.         myAudio5.set_volume(1)  # Reduce volume of first audio to 80%
  246.         print("Playing audio : ", music_file5)
  247.         myChannel1.play(myAudio5)
  248.  
  249.         pwm.set_pwm(beastArm, 0, servo_max)
  250.         time.sleep(0.75)
  251.  
  252.  
  253.         checkifComplete(myChannel1)  # Check if Audio1 complete
  254.         # Shopkeeper says  thank you and have a nice day
  255.         myAudio6.set_volume(1)  # Reduce volume of first audio to 80%
  256.         print("Playing audio : ", music_file6)
  257.         myChannel1.play(myAudio6)
  258.         checkifComplete(myChannel1)  # Check if Audio1 complete
  259.         # The beast says bye
  260.         myAudio7.set_volume(1)  # Reduce volume of first audio to 80%
  261.         print("Playing audio : ", music_file7)
  262.         myChannel1.play(myAudio7)
  263.         checkifComplete(myChannel1)  # Check if Audio1 complete
  264.  
  265.         # QZSong
  266.         myAudio8.set_volume(1)  # Reduce volume of first audio to 80%
  267.         print("Playing audio : ", music_file8)
  268.         myChannel1.play(myAudio8)
  269.  
  270.         pwm.set_pwm(gboxMotor, 0, 345) #TODO: 345 is engage, 405 disengage
  271.         time.sleep(0.25)
  272.         pwm.set_pwm(screen_Left, 0, 1200)
  273.         time.sleep(10)
  274.  
  275.  
  276.         pwm.set_pwm(beastLeg, 0, servo_min)
  277.         time.sleep(0.75)
  278.         pwm.set_pwm(beastLeg, 0, servo_max)
  279.         time.sleep(0.75)
  280.         pwm.set_pwm(beastLeg, 0, servo_min)
  281.         time.sleep(0.75)
  282.         pwm.set_pwm(beastLeg, 0, servo_max)
  283.         time.sleep(0.75)
  284.         pwm.set_pwm(beastLeg, 0, servo_min)
  285.         time.sleep(0.75)
  286.         pwm.set_pwm(beastLeg, 0, servo_max)
  287.         time.sleep(0.75)
  288.  
  289.         pwm.set_pwm(screen_Left, 0, 0)
  290.         checkifComplete(myChannel1)  # Check if Audio1 complete
  291.  
  292.         pwm.set_pwm(led_white, 0, led_low)
  293.  
  294.  
  295.  
  296.         # Narrator says interesting stuff
  297.         myAudio9.set_volume(1)  # Reduce volume of first audio to 80%
  298.         print("Playing audio : ", music_file9)
  299.         myChannel1.play(myAudio9)
  300.  
  301.  
  302.  
  303.         # pwm.set_pwm(beastM_Right, 0, 1024)
  304.         # pwm.set_pwm(beastArm, 0, servo_max)
  305.         # time.sleep(0.75)
  306.         # pwm.set_pwm(beastArm, 0, servo_min)
  307.         # time.sleep(0.75)
  308.         # pwm.set_pwm(beastArm, 0, servo_max)
  309.         # time.sleep(0.75)
  310.         # pwm.set_pwm(beastArm, 0, servo_min)
  311.         # time.sleep(0.75)
  312.         # pwm.set_pwm(beastArm, 0, servo_max)
  313.         # time.sleep(0.75)
  314.         # pwm.set_pwm(beastArm, 0, servo_min)
  315.         # time.sleep(0.75)
  316.         # pwm.set_pwm(beastArm, 0, servo_max)
  317.         # time.sleep(0.75)
  318.         # pwm.set_pwm(beastArm, 0, servo_min)
  319.         # time.sleep(0.75)
  320.         # pwm.set_pwm(beastM_Right, 0, 0)
  321.  
  322.  
  323.         #shift from 2st and 3nd
  324.  
  325.         # Move scene to scene 2 and beast to beast show
  326.         pwm.set_pwm(gboxMotor, 0, 345)  # TODO: 345 is engage, 405 disengage
  327.         time.sleep(0.25)
  328.         pwm.set_pwm(screen_Left, 0, 1200)
  329.         time.sleep(12)
  330.         pwm.set_pwm(screen_Left, 0, 0)
  331.         checkifComplete(myChannel1)  # Check if Audio1 complete
  332.  
  333.  
  334.         myAudio10.set_volume(1)  # Reduce volume of first audio to 80%
  335.         print("Playing audio : ", music_file10)
  336.         myChannel1.play(myAudio10)
  337.         checkifComplete(myChannel1)  # Check if Audio1 complete
  338.  
  339.  
  340.         # while GPIO.input(screenStop):
  341.         #     pwm.set_pwm(gboxMotor, 0, gearBox_servoMin)
  342.         #     time.sleep(0.25)
  343.         #     pwm.set_pwm(screen_Left, 0, 500)
  344.         #
  345.         # while GPIO.input(beastShow):
  346.         #     pwm.set_pwm(beastArm, 0, servo_min)
  347.         #     pwm.set_pwm(beastLeg, 0, servo_min)
  348.         #     time.sleep(0.75)
  349.         #     pwm.set_pwm(beastArm, 0, servo_max)
  350.         #     pwm.set_pwm(beastLeg, 0, servo_max)
  351.         #     time.sleep(0.75)
  352.         #     pwm.set_pwm(beastM_Left, 0, 500)
  353.         #
  354.         # # Insert Door sound
  355.         #
  356.         # # Move from scene 2 to scene home
  357.         # pwm.set_pwm(gboxMotor, 0, gearBox_servoMax)
  358.         # time.sleep(0.25)
  359.         # pwm.set_pwm(screen_Left, 0, 0)
  360.         # pwm.set_pwm(led_white, 0, 1024)
  361.         # time.sleep(3)
  362.         # pwm.set_pwm(gboxMotor, 0, gearBox_servoMin)
  363.         # time.sleep(0.25)
  364.         # pwm.set_pwm(screen_Left, 0, 500)
  365.         # time.sleep(1)
  366.         #
  367.         # while GPIO.input(screenStop):
  368.         #     pwm.set_pwm(gboxMotor, 0, gearBox_servoMin)
  369.         #     time.sleep(0.25)
  370.         #     pwm.set_pwm(screen_Left, 0, 500)
  371.         #
  372.         # time.sleep(2)
  373.         #
  374.         # while GPIO.input(belleShow):
  375.         #     pwm.set_pwm(belleM_Right, 0, 1024)
  376.         #
  377.         # # Insert baby I am home
  378.         myAudio11.set_volume(1)  # Reduce volume of first audio to 80%
  379.         print("Playing audio : ", music_file11)
  380.         myChannel1.play(myAudio11)
  381.         checkifComplete(myChannel1)  # Check if Audio1 complete
  382.         #
  383.         # # Insert beauty asking him what does he have and is it for her.
  384.         myAudio12.set_volume(1)  # Reduce volume of first audio to 80%
  385.         print("Playing audio : ", music_file12)
  386.         myChannel1.play(myAudio12)
  387.         checkifComplete(myChannel1)  # Check if Audio1 complete
  388.         #
  389.         pwm.set_pwm(led_white, 0, led_high)
  390.         pwm.set_pwm(belleM_Right, 0, 1024)
  391.         time.sleep(7)
  392.         pwm.set_pwm(belleM_Right, 0, 0)
  393.  
  394.         # # Beast says that it is her fav milkshake
  395.         myAudio13.set_volume(1)  # Reduce volume of first audio to 80%
  396.         print("Playing audio : ", music_file13)
  397.         myChannel1.play(myAudio13)
  398.         checkifComplete(myChannel1)  # Check if Audio1 complete
  399.         #
  400.         # # Let us complete our game in the play room
  401.         myAudio14.set_volume(1)  # Reduce volume of first audio to 80%
  402.         print("Playing audio : ", music_file14)
  403.         myChannel1.play(myAudio14)
  404.         checkifComplete(myChannel1)  # Check if
  405.         #
  406.         # # Beast says yes of course
  407.         myAudio15.set_volume(1)  # Reduce volume of first audio to 80%
  408.         print("Playing audio : ", music_file15)
  409.         myChannel1.play(myAudio15)
  410.         checkifComplete(myChannel1)  # Check if
  411.  
  412.         #
  413.         pwm.set_pwm(led_white, 0, 0)
  414.         time.sleep(0.5)
  415.         pwm.set_pwm(gboxMotor, 0, 345)  # TODO: 345 is engage, 405 disengage
  416.         time.sleep(0.25)
  417.         pwm.set_pwm(screen_Left, 0, 1200)
  418.         time.sleep(9)
  419.         pwm.set_pwm(screen_Left, 0, 0)
  420.  
  421.         # pwm.set_pwm(gboxMotor, 0, gearBox_servoMax)
  422.         # time.sleep(0.25)
  423.         # pwm.set_pwm(screen_Left, 0, 0)
  424.         # pwm.set_pwm(led_white, 0, 1024)
  425.         # time.sleep(3)
  426.         # pwm.set_pwm(gboxMotor, 0, gearBox_servoMin)
  427.         # time.sleep(0.25)
  428.         # pwm.set_pwm(screen_Left, 0, 500)
  429.         # time.sleep(1)
  430.         #
  431.         # while GPIO.input(screenStop):
  432.         #     pwm.set_pwm(gboxMotor, 0, gearBox_servoMin)
  433.         #     time.sleep(0.25)
  434.         #     pwm.set_pwm(screen_Left, 0, 500)
  435.         #
  436.         # # Beauty says give it to me
  437.         myAudio16.set_volume(1)  # Reduce volume of first audio to 80%
  438.         print("Playing audio : ", music_file16)
  439.         myChannel1.play(myAudio16)
  440.         checkifComplete(myChannel1)
  441.         #
  442.         # # Beast says that I am going to put into something lol
  443.         #
  444.         myAudio17.set_volume(1)  # Reduce volume of first audio to 80%
  445.         print("Playing audio : ", music_file17)
  446.         myChannel1.play(myAudio17)
  447.         checkifComplete(myChannel1)
  448.         # # Beauty says great move.
  449.         #
  450.         myAudio18.set_volume(1)  # Reduce volume of first audio to 80%
  451.         print("Playing audio : ", music_file18)
  452.         myChannel1.play(myAudio18)
  453.         checkifComplete(myChannel1)
  454.         # # Narrator speaks 3rd scene lol
  455.         #
  456.         myAudio19.set_volume(1)  # Reduce volume of first audio to 80%
  457.         print("Playing audio : ", music_file19)
  458.         myChannel1.play(myAudio19)
  459.         checkifComplete(myChannel1)
  460.  
  461.         pwm.set_pwm(led_white, 0, led_high)
  462.         # # Beast says checkmate.
  463.         myAudio20.set_volume(1)  # Reduce volume of first audio to 80%
  464.         print("Playing audio : ", music_file20)
  465.         myChannel1.play(myAudio20)
  466.         checkifComplete(myChannel1)
  467.  
  468.         #
  469.         # # Beauty says that she is tired and is going to try the milkshake.
  470.         #
  471.         myAudio21.set_volume(1)  # Reduce volume of first audio to 80%
  472.         print("Playing audio : ", music_file21)
  473.         myChannel1.play(myAudio21)
  474.         checkifComplete(myChannel1)
  475.         # # Beauty drinks the milkshake
  476.         myAudio22.set_volume(1)  # Reduce volume of first audio to 80%
  477.         print("Playing audio : ", music_file22)
  478.         myChannel1.play(myAudio22)
  479.         checkifComplete(myChannel1)
  480.         #
  481.         # # She does not feel so good
  482.         myAudio23.set_volume(1)  # Reduce volume of first audio to 80%
  483.         print("Playing audio : ", music_file23)
  484.         myChannel1.play(myAudio23)
  485.         checkifComplete(myChannel1)
  486.  
  487.         pwm.set_pwm(belleBody, 0, 600)
  488.         time.sleep(0.5)
  489.  
  490.         #
  491.         # # Ambulance sound.
  492.         #
  493.         myAudio24.set_volume(1)  # Reduce volume of first audio to 80%
  494.         print("Playing audio : ", music_file24)
  495.         myChannel1.play(myAudio24)
  496.  
  497.         #
  498.  
  499.         pwm.set_pwm(led_white, 0, led_low)
  500.  
  501.         pwm.set_pwm(gboxMotor, 0, 345)  # TODO: 345 is engage, 405 disengage
  502.         time.sleep(0.25)
  503.         pwm.set_pwm(screen_Left, 0, 1200)
  504.         pwm.set_pwm(led_blue, 0, 0)
  505.         pwm.set_pwm(led_red, 0, 3072)
  506.         time.sleep(0.5)
  507.         pwm.set_pwm(led_red, 0, 0)
  508.         pwm.set_pwm(led_blue, 0, 3072)
  509.         time.sleep(0.5)
  510.         pwm.set_pwm(led_blue, 0, 0)
  511.         pwm.set_pwm(led_red, 0, 3072)
  512.         time.sleep(0.5)
  513.         pwm.set_pwm(led_red, 0, 0)
  514.         pwm.set_pwm(led_blue, 0, 3072)
  515.         time.sleep(0.5)
  516.         pwm.set_pwm(led_blue, 0, 0)
  517.         pwm.set_pwm(led_red, 0, 3072)
  518.         time.sleep(0.5)
  519.         pwm.set_pwm(led_red, 0, 0)
  520.         pwm.set_pwm(led_blue, 0, 3072)
  521.         time.sleep(0.5)
  522.         pwm.set_pwm(led_blue, 0, 0)
  523.         pwm.set_pwm(led_red, 0, 3072)
  524.         time.sleep(0.5)
  525.         pwm.set_pwm(led_red, 0, 0)
  526.         pwm.set_pwm(led_blue, 0, 3072)
  527.         time.sleep(0.5)
  528.         pwm.set_pwm(led_blue, 0, 0)
  529.         pwm.set_pwm(led_red, 0, 3072)
  530.         time.sleep(0.5)
  531.         pwm.set_pwm(led_red, 0, 0)
  532.         pwm.set_pwm(led_blue, 0, 3072)
  533.         time.sleep(0.5)
  534.         pwm.set_pwm(led_blue, 0, 0)
  535.         pwm.set_pwm(led_red, 0, 3072)
  536.         time.sleep(0.5)
  537.         pwm.set_pwm(led_red, 0, 0)
  538.         pwm.set_pwm(led_blue, 0, 3072)
  539.         time.sleep(0.5)
  540.         pwm.set_pwm(led_blue, 0, 0)
  541.         pwm.set_pwm(led_red, 0, 3072)
  542.         time.sleep(0.5)
  543.         pwm.set_pwm(led_red, 0, 0)
  544.         pwm.set_pwm(led_blue, 0, 3072)
  545.         time.sleep(0.5)
  546.         pwm.set_pwm(led_blue, 0, 0)
  547.         pwm.set_pwm(led_red, 0, 3072)
  548.         time.sleep(0.5)
  549.         pwm.set_pwm(led_red, 0, 0)
  550.         pwm.set_pwm(led_blue, 0, 3072)
  551.         time.sleep(0.5)
  552.         pwm.set_pwm(led_blue, 0, 0)
  553.         pwm.set_pwm(led_red, 0, 3072)
  554.         time.sleep(0.5)
  555.         pwm.set_pwm(led_red, 0, 0)
  556.         pwm.set_pwm(led_blue, 0, 3072)
  557.         time.sleep(0.5)
  558.         pwm.set_pwm(screen_Left, 0, 0)
  559.  
  560.         checkifComplete(myChannel1)
  561.  
  562.         # # Heavy breathing
  563.         #
  564.         myAudio25.set_volume(1)  # Reduce volume of first audio to 80%
  565.         print("Playing audio : ", music_file25)
  566.         myChannel1.play(myAudio25)
  567.         checkifComplete(myChannel1)
  568.         #
  569.         # # Doc says that belle kena food poisoning.
  570.         myAudio26.set_volume(1)  # Reduce volume of first audio to 80%
  571.         print("Playing audio : ", music_file26)
  572.         myChannel1.play(myAudio26)
  573.         checkifComplete(myChannel1)
  574.         #
  575.         myAudio33.set_volume(1)  # Reduce volume of first audio to 80%
  576.         print("Playing audio : ", music_file33)
  577.         myChannel1.play(myAudio33)
  578.         checkifComplete(myChannel1)
  579.  
  580.         pwm.set_pwm(led_white, 0, 0)
  581.         pwm.set_pwm(led_red, 0, 0)
  582.         pwm.set_pwm(led_blue, 0, 0)
  583.         pwm.set_pwm(gboxMotor, 0, 405)  # TODO: 345 is engage, 405 disengage
  584.         time.sleep(0.25)
  585.  
  586.         pwm.set_pwm(beastM_Right, 0, 1024)
  587.         time.sheet(6)
  588.         pwm.set_pwm(belleM_Left, 0, 1024)
  589.         time.sheet(7)
  590.         ppwm.set_pwm(gboxNMotor, 0, 345)  # TODO: 345 is engage, 405 disengage
  591.         time.sleep(0.25)
  592.         pwm.set_pwm(screen_Right, 0, 1200)
  593.         time.sleep(40)
  594.         pwm.set_pwm(screen_right, 0, 0)
  595.         ppwm.set_pwm(gboxNMotor, 0, 405)  # TODO: 345 is engage, 405 disengage
  596.         time.sleep(0.25)
  597.  
  598.  
  599.  
  600.  
  601.  
  602. except KeyboardInterrupt: # If CTRL+C is pressed, exit cleanly:
  603.     pwm.set_pwm(beastArm, 0, servo_max)
  604.     pwm.set_pwm(beastM_Left, 0, 0)
  605.     pwm.set_pwm(beastArm, 0, servo_min)
  606.     pwm.set_pwm(led_white, 0, 0)
  607.     pwm.set_pwm(led_red, 0, 0)
  608.     pwm.set_pwm(beastM_Right, 0, 0)
  609.     pwm.set_pwm(beastM_Left, 0, 0)
  610.     pwm.set_pwm(gboxMotor, 0, 405)
  611.     pwm.set_pwm(screen_Left, 0, 0)
  612.     pwm.set_pwm(gboxMotor, 0, 405)
  613.     GPIO.cleanup()  # cleanup all GPIO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement