LoginSignup
0
0

More than 1 year has passed since last update.

DMX制御MP3再生Raspberry-Py

Last updated at Posted at 2022-08-05

タッチパネルGUI付きDMX512入力照明同期用MP3再生器製作(2017年)

image.png

DMX512信号はSTM32-Mbedを使いUSB接続( ttyACM0 )でコマンドをRaspberry-Pyに送りました。

image.png

python プログラムソース 例

#/usr/bin/env python

import serial
import time
import pygame.mixer
import pygame, Buttons
import subprocess
from pygame.locals import *

#Initialize pygame
pygame.init()
sx=2
sy=2
sl=158
sh=36
sz=sh+4

#str1="Dmx mp3 Play"
str1="Play "

class Button_Example:
    def __init__(self):
        self.main()
    
    def restart(self):
      command = "/usr/bin/sudo /sbin/shutdown -r now"
      process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
      output = process.communicate()[0]
      print output

    def shutdown(self):
      command = "/usr/bin/sudo /sbin/shutdown -h now"
      process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
      output = process.communicate()[0]
      print output


    #Create a display
    def display(self):
        self.screen = pygame.display.set_mode((sl*2+4,250),0,32)  #480,320
        pygame.display.set_caption(str1)

    #Update the display and show the button
    def update_display(self):
        self.screen.fill(( 0,  0, 64))
        #Parameters:               surface,      color,       x,      y, length, height, width,    text,      text_color
        self.Button1.create_button(self.screen, (107,142,35),  sx, sy+sz*0  , sl,  sh,    0, "< 1 >", (255,255,255))
        self.Button2.create_button(self.screen, (107,142,35),  sx, sy+sz*1  , sl,  sh,    0, "< 2 >", (255,255,255))
        self.Button3.create_button(self.screen, (107,142,35),  sx, sy+sz*2  , sl,  sh,    0, "< 3 >", (255,255,255))
        self.Button4.create_button(self.screen, (107,142,35),sx+sl, sy+sz*0  , sl,  sh,    0,"< 4 >", (255,255,255))
        self.Button5.create_button(self.screen, (107,142,35),sx+sl, sy+sz*1  , sl,  sh,    0,"< 5 >", (255,255,255))
        self.Button6.create_button(self.screen, (107,142,35),sx+sl, sy+sz*2  , sl,  sh,    0,"< 6 >", (255,255,255))
        self.Button0.create_button(self.screen, (107,142,35),  sx, sy+sz*3+6 , sl,  sh,    0,"<Stop>", (255,255,255))
        #self.Button9.create_button(self.screen, (107, 35,35),sx+sl, sy+sz*3+6 , sl, sh,    0,"<End!>" , (255,255,255))
        self.Button9.create_button(self.screen,(107, 35,35),sx+sl, sy+sz*3+6 , sl, sh,    0,"shutdown" , (255,255,255))
        pygame.display.flip()


    #Run the loop
    def main(self):
        self.Button1 = Buttons.Button()
        self.Button2 = Buttons.Button()
        self.Button3 = Buttons.Button()
        self.Button4 = Buttons.Button()
        self.Button5 = Buttons.Button()
        self.Button6 = Buttons.Button()
        self.Button0 = Buttons.Button()
        self.Button9 = Buttons.Button()
        self.display()
        pygame.mixer.init()
        while True:
            self.update_display()
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                elif event.type == MOUSEBUTTONDOWN:
                    if self.Button1.pressed(pygame.mouse.get_pos()):
                        #print "Give me a command!"
                        pygame.mixer.music.load('001.mp3')
                        pygame.mixer.music.play()
                        pygame.display.set_caption(str1+"< 1 >")
                    if self.Button2.pressed(pygame.mouse.get_pos()):
                        pygame.mixer.music.load('002.mp3')
                        pygame.mixer.music.play()
                        pygame.display.set_caption(str1+"< 2 >")
                    if self.Button3.pressed(pygame.mouse.get_pos()):
                        pygame.mixer.music.load('003.mp3')
                        pygame.mixer.music.play()
                        pygame.display.set_caption(str1+"< 3 >")
                    if self.Button4.pressed(pygame.mouse.get_pos()):
                        pygame.mixer.music.load('004.mp3')
                        pygame.mixer.music.play()
                        pygame.display.set_caption(str1+"< 4 >")
                    if self.Button5.pressed(pygame.mouse.get_pos()):
                        pygame.mixer.music.load('005.mp3')
                        pygame.mixer.music.play()
                        pygame.display.set_caption(str1+"< 5 >")
                    if self.Button6.pressed(pygame.mouse.get_pos()):
                        pygame.mixer.music.load('006.mp3')
                        pygame.mixer.music.play()
                        pygame.display.set_caption(str1+"< 6 >")
                    if self.Button0.pressed(pygame.mouse.get_pos()):
                        pygame.mixer.music.stop()
                        pygame.display.set_caption(str1+"<Stop>")
                    if self.Button9.pressed(pygame.mouse.get_pos()):
                        pygame.mixer.music.stop()
                        #pygame.display.set_caption(str1+"End")
                        pygame.display.set_caption(str1+"<<shutdown>>")
                        time.sleep(2)
                        self.shutdown()
                        pygame.quit()
if __name__ == '__main__':
#    con=serial.Serial('/dev/ttyACM0',9600)
    pm = pygame.mixer.Sound("start.wav")
    pm.play()
    obj = Button_Example()

image.png

Mbed Nucleo_F042  調査中 後日 全ソースUP予定

// Nucleo_F042  // T.kurume  2022  3/31
#include "mbed.h"
#include "Adafruit_GFX.h"
#include "Adafruit_SSD1306.h"

組込写真

image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0