Irak MayerStephanie VicarteElizabeth Vicarte
Published © GPL3+

GloMusic

Voice select music instrument interface. Easy to access a wide variety of music instruments.

IntermediateFull instructions providedOver 1 day1,071

Things used in this project

Hardware components

MATRIX Voice
MATRIX Labs MATRIX Voice
×1
Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
×1
Through Hole Resistor, 3.3 kohm
Through Hole Resistor, 3.3 kohm
×3
DFRobot Thin Film Pressure Sensor
×1

Software apps and online services

Snips AIR
Snips AIR

Story

Read more

Schematics

GloMusic diagram

The resistor is a 3.3 Kohm.

Code

EspGlovePressLed.ino

Arduino
This program controls the LED ring of a Matrix Voice board based on the pressure values of attached sensors. Then establish a communication link via UART
/*
 * Project GloMusic
 * File: EspGlovePressLed.ino
 * Description: This program controls the LED ring of a Matrix Voice board based on the pressure values of attached sensors. Then establish a communication link via UART
 * Author: VisteliLabs
 * Date: 11/16/2019
 
 Copyright <2019> <VisteliLabs>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
#include "MATRIXVoiceOTA.h"
#include "everloop.h"
#include "everloop_image.h"
#include "wishbone_bus.h"

//Initialize Matrix Voice hardware
namespace hal = matrix_hal;
hal::WishboneBus wb;
hal::Everloop everloop;
hal::EverloopImage image1d;

//Use extension port for pressure sensors
const int FSR_PIN = 12;  // Pin connected to FSR/resistor divider
const int FSR_PIN1 = 26; // Pin connected to FSR/resistor divider
const int FSR_PIN2 = 27; // Pin connected to FSR/resistor divider
const int FSR_PIN3 = 25; // Pin connected to FSR/resistor divider

//Define the instrument constants
const char VIOLIN = 'A';
const char CHORUS = 'B'
const char CELLO  = 'C';
const char FLUTE = 'D';

//Array of data to transmit
#define DATASIZE 48
uint8_t pressData[DATASIZE];

unsigned counter = 0;

//Current selected instrument
char ActiveInstrument = VIOLIN;

//Create a visual gauge of the pressure level on each section of the led ring
void everloopPressStatus(char instrument,int data1,int data2,int data3) 
{
  //At 18 leds, we create 3 gauges sampling the 2048 analog levels on 6 leds per measurement (330)
  //The index shows the number of leds to light
  int index1 = int(data1 /330);
  int index2 = int(data2 /330);
  int index3 = int(data3 /330);
  int redIdx = 0;
  int greenIdx = 0;
  int blueIdx = 0;
  int i;

  //Set the instrument color
  if (instrument == VIOLIN)
  {
    greenIdx = 255;
  }
  else if (instrument == CELLO)
  {
    redIdx = 255;
  }
  else if (instrument == CHORUS)
  {
    blueIdx = 255;
  }
  else if (instrument == FLUTE)
  {
    redIdx = 255;
    greenIdx = 255;
  }

  //Reset to OFF all the ring LEDs
  for (hal::LedValue &led : image1d.leds) {
    led.red = 0;
    led.green = 0;
    led.blue = 0;
    led.white = 0;
  }

  //Turn the corresponding LEDs 
  for(i=0;i<=index1;i++)
  {
    image1d.leds[i].red = redIdx;
    image1d.leds[i].green = greenIdx;
    image1d.leds[i].blue = blueIdx;
  }
    
  for(i=0;i<=index2;i++)
  {
    image1d.leds[i+6].red = redIdx;
    image1d.leds[i+6].green = greenIdx;
    image1d.leds[i+6].blue = blueIdx;
  }

   for(i=0;i<=index3;i++)
  {
    image1d.leds[i+12].red = redIdx;
    image1d.leds[i+12].green = greenIdx;
    image1d.leds[i+12].blue = blueIdx;
  }
 
  everloop.Write(&image1d);
  usleep(25000);
  
}

void setup() {
  Serial.begin(115200);

  pinMode(FSR_PIN, INPUT);
  pinMode(FSR_PIN1, INPUT);
  pinMode(FSR_PIN2, INPUT);
  pinMode(FSR_PIN3, INPUT);

  //initialize ring
  wb.Init();
  everloop.Setup(&wb);
  
}

void loop() 
{
  byte inCmd;
  int fsrADC = analogRead(FSR_PIN);
  int fsrADC1 = analogRead(FSR_PIN1);
  if (fsrADC == fsrADC1)
    fsrADC1 = analogRead(FSR_PIN1);
  int fsrADC2 = analogRead(FSR_PIN2);
    if (fsrADC1 == fsrADC2)
      fsrADC2 = analogRead(FSR_PIN2);
  int fsrADC3 = analogRead(FSR_PIN3);

  //Format transmission stream
  sprintf((char *)pressData,"%d | %d | %d |",fsrADC,fsrADC1,fsrADC3);

  everloopPressStatus(ActiveInstrument,fsrADC,fsrADC1,fsrADC3) ;

  //if command available
  if (Serial.available())
  {
    //Read command
    inCmd = Serial.read();
    //Send data command
    if (inCmd == '1') 
    {
      //Send data
      usleep(100);
      Serial.println((char *)pressData);
    }
    //change instrument command
    else if (inCmd == 'A')
    {
      ActiveInstrument = VIOLIN;
    }
    else if (inCmd == 'B')
    {
      ActiveInstrument = CHORUS;
    }
    else if (inCmd == 'C')
    {
      ActiveInstrument = CELLO;
    }
    else if (inCmd == 'D')
    {
      ActiveInstrument = FLUTE;
    }
  }

}

GloMusic.py

Python
This program establish the connection to Snips and process the selection intrument commands. Plays the corresponding instrumments according to the pressure values from the sensors control in the ESP32 chip
######################################
#GloMusic.py
#
# This program establish the connection to Snips and process the selection intrument commands. Plays the corresponding instrumments according to the pressure values from the sensors control in the ESP32 chip
#
# Copyright <2019> <VisteliLabs>
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
#associated documentation files (the "Software"), to deal in the Software without restriction,
#including without limitation the rights to use, copy, modify, merge, publish, distribute,
#sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
#subject to the following conditions:
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
#INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
#IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
#WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
#OR OTHER DEALINGS IN THE SOFTWARE.
#
#######################################

import paho.mqtt.client as mqtt
from time import sleep
from math import pi, sin
import pygame
import time
import serial
import re
import json

#Initialize the pygame sound engine
pygame.mixer.init()
#Set the number of channels to allow multiple simultaneous sounds
pygame.mixer.set_num_channels(15)

#Initialize the file array for the instruments. The array format is intrument (ch chorus, c cello, v violin, ...), scale (A B C D ...), music file (mf), Path
#Chorus files
chADFmfPath = ['/home/pi/MusicOrch/Chorus/chorus-female-a#5-PB-loop.wav',
            '/home/pi/MusicOrch/Chorus/chorus-female-d#5-PB-loop.wav',
            '/home/pi/MusicOrch/Chorus/chorus-female-f#5-PB-loop.wav']
            
chCEGMmfPath = ['/home/pi/MusicOrch/Chorus/chorus-male-c3-PB-loop.wav',
            '/home/pi/MusicOrch/Chorus/chorus-male-e3-PB-loop.wav',
            '/home/pi/MusicOrch/Chorus/chorus-male-g3-PB-loop.wav']

chCEGmfPath = ['/home/pi/MusicOrch/Chorus/chorus-female-c5-PB-loop.wav',
                '/home/pi/MusicOrch/Chorus/chorus-female-e5-PB-loop.wav',
                '/home/pi/MusicOrch/Chorus/chorus-female-g5-PB-loop.wav']

#Create an array of Sound objects for each instrumment. This is the array for chorus.
#Chorus
chsndObj = [pygame.mixer.Sound(chADFmfPath[0]),pygame.mixer.Sound(chADFmfPath[1]),
          pygame.mixer.Sound(chADFmfPath[2]),
          pygame.mixer.Sound(chCEGMmfPath[0]),pygame.mixer.Sound(chCEGMmfPath[1]),
          pygame.mixer.Sound(chCEGMmfPath[2]),
          pygame.mixer.Sound(chCEGmfPath[0]),pygame.mixer.Sound(chCEGmfPath[1]),
          pygame.mixer.Sound(chCEGmfPath[2])]

#Cello files
cCmfPath = ['/home/pi/MusicOrch/Cello/c2-stac-rr2-PB.wav',
            '/home/pi/MusicOrch/Cello/c4-stac-rr2-PB.wav',
            '/home/pi/MusicOrch/Cello/c5-stac-rr2-PB.wav']
            
cEmfPath = ['/home/pi/MusicOrch/Cello/e2-stac-rr2-PB.wav',
            '/home/pi/MusicOrch/Cello/e4-stac-rr2-PB.wav',
            '/home/pi/MusicOrch/Cello/e5-stac-rr2-PB.wav']
            
cGmfPath = ['/home/pi/MusicOrch/Cello/g2-stac-rr2-PB.wav',
            '/home/pi/MusicOrch/Cello/g3-stac-rr2-PB.wav',
            '/home/pi/MusicOrch/Cello/g4-stac-rr2-PB.wav']

#Cello            
csndObj = [pygame.mixer.Sound(cCmfPath[0]),pygame.mixer.Sound(cCmfPath[1]),
          pygame.mixer.Sound(cCmfPath[2]),
          pygame.mixer.Sound(cEmfPath[0]),pygame.mixer.Sound(cEmfPath[1]),
          pygame.mixer.Sound(cEmfPath[2]),
          pygame.mixer.Sound(cGmfPath[0]),pygame.mixer.Sound(cGmfPath[1]),
          pygame.mixer.Sound(cGmfPath[2])]

#Violin files
vCmfPath = ['/home/pi/MusicOrch/Solo Violin/spic/LLVln_spic_C3_v1_rr1-PB.wav',
            '/home/pi/MusicOrch/Solo Violin/spic/LLVln_spic_C4_v1_rr1-PB.wav',
            '/home/pi/MusicOrch/Solo Violin/spic/LLVln_spic_C5_v1_rr1-PB.wav',
            '/home/pi/MusicOrch/Solo Violin/spic/LLVln_spic_C6_v1_rr1-PB.wav']

vEmfPath = ['/home/pi/MusicOrch/Solo Violin/spic/LLVln_spic_E3_v1_rr1-PB.wav',
           '/home/pi/MusicOrch/Solo Violin/spic/LLVln_spic_E4_v1_rr1-PB.wav',
           '/home/pi/MusicOrch/Solo Violin/spic/LLVln_spic_E5_v1_rr1-PB.wav',
           '/home/pi/MusicOrch/Solo Violin/spic/LLVln_spic_E5_v1_rr1-PB.wav']

vGmfPath = ['/home/pi/MusicOrch/Solo Violin/spic/LLVln_spic_G2_v1_rr1-PB.wav',
           '/home/pi/MusicOrch/Solo Violin/spic/LLVln_spic_G3_v1_rr1-PB.wav',
           '/home/pi/MusicOrch/Solo Violin/spic/LLVln_spic_G4_v1_rr1-PB.wav',
           '/home/pi/MusicOrch/Solo Violin/spic/LLVln_spic_G5_v1_rr1-PB.wav']
                  
#Violin
vsndObj = [pygame.mixer.Sound(vCmfPath[0]),pygame.mixer.Sound(vCmfPath[1]),
          pygame.mixer.Sound(vCmfPath[2]),
          pygame.mixer.Sound(vEmfPath[0]),pygame.mixer.Sound(vEmfPath[1]),
          pygame.mixer.Sound(vEmfPath[2]),
          pygame.mixer.Sound(vGmfPath[0]),pygame.mixer.Sound(vGmfPath[1]),
          pygame.mixer.Sound(vGmfPath[2])]

#Flute files          
fAmfPath = ['/home/pi/MusicOrch/Flute/stac-PB/LDFlute_stac_A3_v2_rr1-PB.wav',
            '/home/pi/MusicOrch/Flute/stac-PB/LDFlute_stac_A4_v3_rr2-PB.wav',
            '/home/pi/MusicOrch/Flute/stac-PB/LDFlute_stac_A5_v1_rr1-PB.wav']
            
fCmfPath = ['/home/pi/MusicOrch/Flute/stac-PB/LDFlute_stac_C4_v4_rr1-PB.wav',
            '/home/pi/MusicOrch/Flute/stac-PB/LDFlute_stac_C5_v1_rr1-PB.wav',
            '/home/pi/MusicOrch/Flute/stac-PB/LDFlute_stac_C6_v2_rr2-PB.wav']
            
fEmfPath = ['/home/pi/MusicOrch/Flute/stac-PB/LDFlute_stac_E3-PB.wav',
            '/home/pi/MusicOrch/Flute/stac-PB/LDFlute_stac_E4_v2_rr1-PB.wav',
            '/home/pi/MusicOrch/Flute/stac-PB/LDFlute_stac_E5_v1_rr2-PB.wav']
            
#Flute
fsndObj = [pygame.mixer.Sound(fAmfPath[0]),pygame.mixer.Sound(fAmfPath[1]),
          pygame.mixer.Sound(fAmfPath[2]),
          pygame.mixer.Sound(fCmfPath[0]),pygame.mixer.Sound(fCmfPath[1]),
          pygame.mixer.Sound(fCmfPath[2]),
          pygame.mixer.Sound(fEmfPath[0]),pygame.mixer.Sound(fEmfPath[1]),
          pygame.mixer.Sound(fEmfPath[2])]

#Timpani files
tCmfPath = ['/home/pi/MusicOrch/Timpani/timpani-roll-C2-PB-loop.wav',
            '/home/pi/MusicOrch/Timpani/timpani-roll-C3-PB-loop.wav',
            '/home/pi/MusicOrch/Timpani/timpani-roll-C4-PB-loop.wav']

tEmfPath = ['/home/pi/MusicOrch/Timpani/timpani-roll-A2-PB-loop.wav',
            '/home/pi/MusicOrch/Timpani/timpani-roll-E2-PB-loop.wav',
            '/home/pi/MusicOrch/Timpani/timpani-roll-E3-PB-loop.wav']
            
tGmfPath = ['/home/pi/MusicOrch/Timpani/timpani-roll-A3-PB-loop.wav',
            '/home/pi/MusicOrch/Timpani/timpani-roll-G2-PB-loop.wav',
            '/home/pi/MusicOrch/Timpani/timpani-roll-G3-PB-loop.wav']

#Timpani
tsndObj = [pygame.mixer.Sound(tCmfPath[0]),pygame.mixer.Sound(tCmfPath[1]),
          pygame.mixer.Sound(tCmfPath[2]),
          pygame.mixer.Sound(tEmfPath[0]),pygame.mixer.Sound(tEmfPath[1]),
          pygame.mixer.Sound(tEmfPath[2]),
          pygame.mixer.Sound(tGmfPath[0]),pygame.mixer.Sound(tGmfPath[1]),
          pygame.mixer.Sound(tGmfPath[2])]
            
#Initialize the serial port for communication with the Matrix Voice ESP32
ser = serial.Serial(
        port='/dev/ttyS0',
        baudrate = 115200,
        parity=serial.PARITY_NONE,
        stopbits=serial.STOPBITS_ONE,
        bytesize=serial.EIGHTBITS,
        timeout=5
)

#Snips settings
HOST = 'localhost'
PORT = 1883

PauseExec = False

#Instruments commnand codes
ViolinIns = 'A'
ChorusIns = 'B'
CelloIns = 'C'
FluteIns = 'D'
PianoIns = 'E'
MixOneIns = 'F'
TimpaniIns = 'G'
ExitIns = 'X'

#Snips credentials, make sure you set your Username
snipsUserName = "YourUserName"
Reactor = 'hermes/intent/'+snipsUserName+':ArcReactor' 
ViolinMus = 'hermes/intent/'+snipsUserName+':Violin'
CelloMus = 'hermes/intent/'+snipsUserName+':Cello'
PianoMus = 'hermes/intent/'+snipsUserName+':Piano'
FluteMus = 'hermes/intent/'+snipsUserName+':Flute'
TimpaniMus = 'hermes/intent/'+snipsUserName+':Timpani'
ExitMus = 'hermes/intent/'+snipsUserName+':Exit'
MixOneMus = 'hermes/intent/'+snipsUserName+':MixOne'
ChorusMus = 'hermes/intent/'+snipsUserName+':Chorus'

#Initial default instrument
activeInstrument = ViolinIns

baseNote = 660
anchorVal = 3

#Function that selects the sound file according to the pressure value and scale index  
#returns the Sound object
def selectSoundObj(objArray,indexId,noteValue):
	global baseNote
	global anchorVal 
    offsetVal = int(noteValue / baseNote)
    return (objArray[indexId*anchorVal+offsetVal])

#Function that plays the sound in the corresponding channel
#Parameters are the select instruments, and the pressure values from each sensor
def playNote(selIns,note1,note2,note3):
    global vsndObj
    global fsndObj
    if (selIns == ViolinIns):
        #print('Violin')
        if (note1 > 0):
            pygame.mixer.Channel(0).play(selectSoundObj(vsndObj,0,note1))
        if (note2 > 0):
            pygame.mixer.Channel(1).play(selectSoundObj(vsndObj,1,note2))
        if (note3 > 0):
            pygame.mixer.Channel(2).play(selectSoundObj(vsndObj,2,note3))
    if (selIns == FluteIns):
        #print('Flute')
        if (note1 > 0):
            pygame.mixer.Channel(3).play(selectSoundObj(fsndObj,0,note1))
        if (note2 > 0):
            pygame.mixer.Channel(4).play(selectSoundObj(fsndObj,1,note2))
        if (note3 > 0):
            pygame.mixer.Channel(5).play(selectSoundObj(fsndObj,2,note3))
            
    if (selIns == CelloIns):
        #print('Cello')
        if (note1 > 0):
            pygame.mixer.Channel(6).play(selectSoundObj(csndObj,0,note1))
        if (note2 > 0):
            pygame.mixer.Channel(7).play(selectSoundObj(csndObj,1,note2))
        if (note3 > 0):
            pygame.mixer.Channel(8).play(selectSoundObj(csndObj,2,note3))

    if (selIns == ChorusIns):
        #print('Chorus')
        if (note1 > 0):
            pygame.mixer.Channel(9).play(selectSoundObj(chsndObj,0,note1),maxtime=4000)
        if (note2 > 0):
            pygame.mixer.Channel(10).play(selectSoundObj(chsndObj,1,note2),maxtime=4000)
        if (note3 > 0):
            pygame.mixer.Channel(11).play(selectSoundObj(chsndObj,2,note3),maxtime=4000)
            
    if (selIns == TimpaniIns):
        #print('Timpani')
        if (note1 > 0):
            pygame.mixer.Channel(12).play(selectSoundObj(tsndObj,0,note1))
        if (note2 > 0):
            pygame.mixer.Channel(13).play(selectSoundObj(tsndObj,1,note2))
        if (note3 > 0):
            pygame.mixer.Channel(14).play(selectSoundObj(tsndObj,2,note3))

    if (selIns == MixOneIns):
        #print('MixOne')
        if (note1 > 0):
            pygame.mixer.Channel(0).play(selectSoundObj(vsndObj,0,note1),fade_ms=50)
            pygame.mixer.Channel(3).play(selectSoundObj(fsndObj,0,note1),fade_ms=60)            
            pygame.mixer.Channel(6).play(selectSoundObj(csndObj,0,note1))
        if (note2 > 0):
            pygame.mixer.Channel(1).play(selectSoundObj(vsndObj,1,note2),fade_ms=50)
            pygame.mixer.Channel(4).play(selectSoundObj(fsndObj,1,note2))
            pygame.mixer.Channel(7).play(selectSoundObj(csndObj,1,note2),fade_ms=60)
        if (note3 > 0):
            pygame.mixer.Channel(2).play(selectSoundObj(vsndObj,2,note3))
            pygame.mixer.Channel(5).play(selectSoundObj(fsndObj,2,note3),fade_ms=50)            
            pygame.mixer.Channel(8).play(selectSoundObj(csndObj,2,note3),fade_ms=60)

#Subscribe to the programmed intents
def on_connect(client, userdata, flags, rc):
    print("Connected to {0} with result code {1}".format(HOST, rc))
    # Subscribe to the hotword detected topic
    client.subscribe("hermes/hotword/default/detected")
    # Subscribe to intent topic
    client.subscribe(ViolinMus) 
    client.subscribe(CelloMus) 
    client.subscribe(PianoMus) 
    client.subscribe(FluteMus) 
    client.subscribe(ExitMus) 
    client.subscribe(TimpaniMus) 
    client.subscribe(MixOneMus) 
    client.subscribe(ChorusMus) 

#Snips callback function with the detected intent
def on_message(client, userdata, msg):
    global activeInstrument
    if msg.topic == 'hermes/hotword/default/detected':
        print("Hotword detected!")
    elif msg.topic == ViolinMus: 
        activeInstrument = ViolinIns
        print("Violin detected!")
    elif msg.topic == CelloMus: 
        activeInstrument = CelloIns
        print("Cello detected!")
    elif msg.topic == PianoMus: 
        activeInstrument = PianoIns
        print("Piano detected!")
    elif msg.topic == FluteMus:
        activeInstrument = FluteIns 
        print("Flute detected!")
    elif msg.topic == TimpaniMus:
        activeInstrument = TimpaniIns
        print("Timpani detected!")
    elif msg.topic == ExitMus:
        activeInstrument = ExitIns
        print("Exit detected!")
    elif msg.topic == MixOneMus:
        activeInstrument = MixOneIns
        print("Mix One detected!")
    elif msg.topic == ChorusMus:
        activeInstrument = ChorusIns
        print("Chorus detected!")

#Initialize the mqqt engine
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message

#Connect to mqtt service
client.connect(HOST, PORT, 60)
#client.loop_forever()
client.loop_start()

currIns = activeInstrument

#main loop
while True:
    try:
        #print("LOOP")
        if (PauseExec == False):
			#Set read command to ESP32
            ser.write(b'1')
            time.sleep(0.1)
			#Read a line of data
            x=ser.readline()
            #print(x)
			#Convert the binary data into string
            strdecode = x.decode('utf-8')
			#split the data according to the divider
            values = strdecode.split("|")
            #print(values)
			#Play the data
            playNote(activeInstrument,int(values[0]),int(values[1]),int(values[2]))
            time.sleep(0.05)

		#If instrument change let know the ESP32 task
        if (currIns != activeInstrument):
            print(activeInstrument)
            currIns = activeInstrument
            if (activeInstrument == ViolinIns):
                ser.write(b'A')
            elif (activeInstrument == ChorusIns):
                ser.write(b'B')                
            elif (activeInstrument == CelloIns):
                ser.write(b'C')
            elif (activeInstrument == FluteIns):
                ser.write(b'D')
            elif (activeInstrument == PianoIns):
                ser.write(b'E')
            elif (activeInstrument == MixOneIns):
                ser.write(b'F')
            elif (activeInstrument == TimpaniIns):
                ser.write(b'G')
            elif (activeInstrument == ExitIns):
                break
    except:
		#if serial crash, reset.
        ser.close()
        ser = serial.Serial(
            port='/dev/ttyS0',
            baudrate = 115200,
            parity=serial.PARITY_NONE,
            stopbits=serial.STOPBITS_ONE,
            bytesize=serial.EIGHTBITS,
            timeout=1
        )
        #print("CRASH")
        continue
        
#On exit close the sound engine.
pygame.mixer.quit()

Credits

Irak Mayer

Irak Mayer

18 projects • 10 followers
Stephanie Vicarte

Stephanie Vicarte

14 projects • 12 followers
Elizabeth Vicarte

Elizabeth Vicarte

13 projects • 7 followers

Comments