Advertisement
MnMWizard

Mason Paste 1 PLAB 2

Oct 10th, 2021 (edited)
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. #AudioTest.py ---------------------------------------------------------------------------------------------
  2.  
  3. import mplayer
  4. import time
  5.  
  6. p = mplayer.Player()
  7. p.loadfile('/home/pi/Desktop/Fmp3.mp3')
  8.  
  9. print("hello")
  10.  
  11. time.sleep(3)
  12.  
  13. #p.loadfile('/home/pi/Desktop/Fmp3.mp3')
  14.  
  15.  
  16.  
  17. #pip install mplayer.py is what ended up working I think. Not sure if it matters that
  18. # this .py file is inside a copy of the library folder or not.
  19.  
  20. # command to play from terminal:
  21. # player /home/pi/Desktop/Fmp3.mp3
  22.  
  23.  
  24. #MT.py (Maestro Test) -------------------------------------------------------------------------------
  25.  
  26. import maestro
  27. import time
  28. import mplayer
  29.  
  30. print("No errors?\n")
  31.  
  32.  
  33. servo = maestro.Controller('/dev/ttyAMA0')
  34.  
  35.  
  36.  
  37. p = mplayer.Player()
  38.  
  39. #p.loadfile('/home/pi/Desktop/Fmp3.mp3')
  40. p.loadfile('/home/pi/Desktop/mash.mp3')
  41.  
  42. time.sleep(0.2)
  43.  
  44. servo.runScriptSub(0)
  45.  
  46. #calling another subscript while one is running does overwrite.
  47. # calling another audio does NOT overwrite
  48.  
  49. #solution could be to use os.system to call an mplayer command that stops audio if there is one.
  50. time.sleep(2)
  51.  
  52. #servo.runScriptSub(1)
  53.  
  54.  
  55.  
  56. time.sleep(240)
  57.  
  58. servo.close
  59.  
  60. print("No errors.")
  61.  
  62. #To run from console, navigate to Documents/Maestro using the cd command.
  63. #Then run it with: python3 MT.py
  64.  
  65. #This was done following the piddler in the root's tutorial and taking advice from
  66. # the top comment.
  67.  
  68. # Didn't require the sudo chmod command unless me doing it last boot stuck this time.
  69.  
  70.  
  71. # Structural code stuff ---------------------------------------------------------------------------------
  72. #Preliminary code for an outer pi, definitely not finished just an idea
  73.  
  74. import time
  75. import board
  76. import digitalio
  77. import os
  78. #import pwmio
  79. #from adafruit_motor import servo
  80. from gpiozero import Servo
  81.  
  82. import paho.mqtt.client as mqtt
  83.  
  84. client = mqtt.Client("left")
  85. brokerAddress = "192.168.1.50"
  86. client.connect(brokerAddress)
  87.  
  88.  
  89. #os.system("your terminal command here")
  90.  
  91. IR = digitalio.DigitalInOut(board.D26)
  92. IR.direction = digitalio.Direction.INPUT
  93.  
  94. servo = Servo(16)
  95.  
  96.  
  97. ThermalCamOff = 1
  98.  
  99. servoPos = 0
  100.  
  101. while(True):
  102. if(ThermalCamOff):
  103. if(IR.value==1):
  104. #publish left IR trigger, need to change localhost when we get the broker set up.
  105. #os.system("mosquitto_pub -h localhost -t 'mqtt/leftsensortrig' -m '1'")
  106.  
  107. client.publish("leftsensortrig", "1")
  108.  
  109. #Set horizontal position to far left (colbi says bigger val = more counter clockwise)
  110. servo.value=1
  111.  
  112. time.sleep(0.8) #however long the length of time of the IR trigger is
  113.  
  114. else: #if thermal cam is on
  115. servo.value = servoPos
  116.  
  117.  
  118.  
  119. #I think to trigger the group routine, there will be a case in the middle pi that
  120. #says if both IR sensors are triggered at the same time, publish startGroupRoutine
  121.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement