DMX制御MP3再生Raspberry-Py

## タッチパネルGUI付きDMX512入力照明同期用MP3再生器製作（2017年）
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/378482/e96e3b24-dd0d-add1-8d89-7ad6b77194bd.png)


### DMX512信号はSTM32-Mbedを使いUSB接続( ttyACM0 )でコマンドをRaspberry-Pyに送りました。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/378482/ef138fce-0e0b-f9c8-c47e-47bc7d2d6f5f.png)

### python プログラムソース　例
```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](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/378482/fcd32de4-0489-0756-f7dc-b373450c15a8.png)
### Mbed Nucleo_F042　　調査中　後日　全ソースUP予定
```cpp
// Nucleo_F042  //　T.kurume 　2022  3/31
#include "mbed.h"
#include "Adafruit_GFX.h"
#include "Adafruit_SSD1306.h"
```
### 組込写真
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/378482/91c11463-f02e-62b6-158f-93d3150438c7.png)