WT040
Published © GPL3+

Annoying Soundbox

Sometimes you need to break the silence.

IntermediateFull instructions provided8 hours1,360
Annoying Soundbox

Things used in this project

Hardware components

Adafruit Feather M0 Basic Proto
×1
Adafruit Audio FX - 16MB
×1
Adafruit USB Micro-B Breakout Board
×1
Adafruit Trellis
×1
Adafruit Mono 2.5W Class D Audio Amplifier - PAM8302
×1
Adafruit SSD1306 128x64 OLED Display
×1
Adafruit Stereo Enclosed Speaker Set - 3W 4 Ohm
×1
wire, several colors
×1
custom enclosure
×1
Custom PCB
Custom PCB
×1
several m3 screws and nuts
×2
LED (choose your color)
×16
Female headers
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)
Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

Enclosure bottom

Enclosure bottom

Enclosure mid

Enclosure mid

Enclosure top

Enclosure top

Feather PCB holder

Feather PCB holder

Feet

Feet

Speaker cover (print 2x)

Speaker cover (print 2x)

Trellis holder

Trellis holder

Schematics

PCB

Custom PCB Gerber files

Code

Arduino Code

Arduino
Arduino code itself
/*********************************************************************
/*
Soundbox V2 code by WT040
Some snpippets of code are copied from the Adafruit library examples

History:
v2.0.0	25/08/2017 release version
*/
/*********************************************************************/
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_Trellis.h>
#include "Adafruit_Soundboard.h"
#include "Arduino.h"
#include "wiring_private.h"

#define OLED_RESET 19
Adafruit_SSD1306 display(OLED_RESET);

#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2

#define LOGO16_GLCD_HEIGHT 16 
#define LOGO16_GLCD_WIDTH  16 

Adafruit_Trellis matrix0 = Adafruit_Trellis();
Adafruit_TrellisSet trellis = Adafruit_TrellisSet(&matrix0);
#define NUMTRELLIS 1

#define numKeys (NUMTRELLIS * 16)
#define INTPIN A2

#define SFX_RST 9
Uart Serial2(&sercom1, 11, 10, SERCOM_RX_PAD_0, UART_TX_PAD_2);
Adafruit_Soundboard sfx = Adafruit_Soundboard(&Serial2, NULL, SFX_RST);

boolean trackPlaying = false;
int trackToPlay = -1;

word volume = 10;

char* trackName = "";
char subTrackName[15] = "";

//edit this code to give the soundboards a name
char* soundBoards[] = {
	"Soundboard 1",
	"Soundboard 2",
	"Soundboard 3",
	"Soundboard 4",
	"Soundboard 5",
	"Soundboard 6",
	"Soundboard 7",
	"Soundboard 8",
	"Soundboard 9",
	"Soundboard 10",
	"Soundboard 11",
	"Soundboard 12",
	"Soundboard 13",
	"Soundboard 14",
	"Soundboard 15",
	"Soundboard 16"
};

//edit this code to give the sounda a (file) name
char* trellisPad1[16][16][2] = {
	{	//Soundboard 1
		{ "T01RAND4WAV","test track" },
		{ "T01RAND4WAV","test track 2" },
		{ "00000003WAV","3" },
		{ "00000004WAV","4" },
		{ "00000005WAV","5" },
		{ "00000006WAV","6" },
		{ "00000007WAV","7" },
		{ "00000008WAV","8" },
		{ "00000009WAV","9" },
		{ "00000010WAV","10" },
		{ "00000011WAV","11" },
		{ "00000012WAV","12" },
		{ "00000013WAV","13" },
		{ "00000014WAV","14" },
		{ "00000015WAV","15" },
		{ "00000016WAV","16" }
	},

	{	//Soundboard 2
		{ "T01RAND4WAV","test track" },
		{ "T01RAND4WAV","test track 2" },
		{ "00000003WAV","3" },
		{ "00000004WAV","4" },
		{ "00000005WAV","5" },
		{ "00000006WAV","6" },
		{ "00000007WAV","7" },
		{ "00000008WAV","8" },
		{ "00000009WAV","9" },
		{ "00000010WAV","10" },
		{ "00000011WAV","11" },
		{ "00000012WAV","12" },
		{ "00000013WAV","13" },
		{ "00000014WAV","14" },
		{ "00000015WAV","15" },
		{ "00000016WAV","16" }
	},

	{	//Soundboard 3
		{ "T01RAND4WAV","test track" },
		{ "T01RAND4WAV","test track 2" },
		{ "00000003WAV","3" },
		{ "00000004WAV","4" },
		{ "00000005WAV","5" },
		{ "00000006WAV","6" },
		{ "00000007WAV","7" },
		{ "00000008WAV","8" },
		{ "00000009WAV","9" },
		{ "00000010WAV","10" },
		{ "00000011WAV","11" },
		{ "00000012WAV","12" },
		{ "00000013WAV","13" },
		{ "00000014WAV","14" },
		{ "00000015WAV","15" },
		{ "00000016WAV","16" }
	},

	{	//Soundboard 4
		{ "T01RAND4WAV","test track" },
		{ "T01RAND4WAV","test track 2" },
		{ "00000003WAV","3" },
		{ "00000004WAV","4" },
		{ "00000005WAV","5" },
		{ "00000006WAV","6" },
		{ "00000007WAV","7" },
		{ "00000008WAV","8" },
		{ "00000009WAV","9" },
		{ "00000010WAV","10" },
		{ "00000011WAV","11" },
		{ "00000012WAV","12" },
		{ "00000013WAV","13" },
		{ "00000014WAV","14" },
		{ "00000015WAV","15" },
		{ "00000016WAV","16" }
	},

	{	//Soundboard 5
		{ "T01RAND4WAV","test track" },
		{ "T01RAND4WAV","test track 2" },
		{ "00000003WAV","3" },
		{ "00000004WAV","4" },
		{ "00000005WAV","5" },
		{ "00000006WAV","6" },
		{ "00000007WAV","7" },
		{ "00000008WAV","8" },
		{ "00000009WAV","9" },
		{ "00000010WAV","10" },
		{ "00000011WAV","11" },
		{ "00000012WAV","12" },
		{ "00000013WAV","13" },
		{ "00000014WAV","14" },
		{ "00000015WAV","15" },
		{ "00000016WAV","16" }
	},

	{	//Soundboard 6
		{ "T01RAND4WAV","test track" },
		{ "T01RAND4WAV","test track 2" },
		{ "00000003WAV","3" },
		{ "00000004WAV","4" },
		{ "00000005WAV","5" },
		{ "00000006WAV","6" },
		{ "00000007WAV","7" },
		{ "00000008WAV","8" },
		{ "00000009WAV","9" },
		{ "00000010WAV","10" },
		{ "00000011WAV","11" },
		{ "00000012WAV","12" },
		{ "00000013WAV","13" },
		{ "00000014WAV","14" },
		{ "00000015WAV","15" },
		{ "00000016WAV","16" }
	},

	{	//Soundboard 7
		{ "T01RAND4WAV","test track" },
		{ "T01RAND4WAV","test track 2" },
		{ "00000003WAV","3" },
		{ "00000004WAV","4" },
		{ "00000005WAV","5" },
		{ "00000006WAV","6" },
		{ "00000007WAV","7" },
		{ "00000008WAV","8" },
		{ "00000009WAV","9" },
		{ "00000010WAV","10" },
		{ "00000011WAV","11" },
		{ "00000012WAV","12" },
		{ "00000013WAV","13" },
		{ "00000014WAV","14" },
		{ "00000015WAV","15" },
		{ "00000016WAV","16" }
	},

	{	//Soundboard 8
		{ "T01RAND4WAV","test track" },
		{ "T01RAND4WAV","test track 2" },
		{ "00000003WAV","3" },
		{ "00000004WAV","4" },
		{ "00000005WAV","5" },
		{ "00000006WAV","6" },
		{ "00000007WAV","7" },
		{ "00000008WAV","8" },
		{ "00000009WAV","9" },
		{ "00000010WAV","10" },
		{ "00000011WAV","11" },
		{ "00000012WAV","12" },
		{ "00000013WAV","13" },
		{ "00000014WAV","14" },
		{ "00000015WAV","15" },
		{ "00000016WAV","16" }
	},

	{	//Soundboard 9
		{ "T01RAND4WAV","test track" },
		{ "T01RAND4WAV","test track 2" },
		{ "00000003WAV","3" },
		{ "00000004WAV","4" },
		{ "00000005WAV","5" },
		{ "00000006WAV","6" },
		{ "00000007WAV","7" },
		{ "00000008WAV","8" },
		{ "00000009WAV","9" },
		{ "00000010WAV","10" },
		{ "00000011WAV","11" },
		{ "00000012WAV","12" },
		{ "00000013WAV","13" },
		{ "00000014WAV","14" },
		{ "00000015WAV","15" },
		{ "00000016WAV","16" }
	},

	{	//Soundboard 10
		{ "T01RAND4WAV","test track" },
		{ "T01RAND4WAV","test track 2" },
		{ "00000003WAV","3" },
		{ "00000004WAV","4" },
		{ "00000005WAV","5" },
		{ "00000006WAV","6" },
		{ "00000007WAV","7" },
		{ "00000008WAV","8" },
		{ "00000009WAV","9" },
		{ "00000010WAV","10" },
		{ "00000011WAV","11" },
		{ "00000012WAV","12" },
		{ "00000013WAV","13" },
		{ "00000014WAV","14" },
		{ "00000015WAV","15" },
		{ "00000016WAV","16" }
	},

	{	//Soundboard 11
		{ "T01RAND4WAV","test track" },
		{ "T01RAND4WAV","test track 2" },
		{ "00000003WAV","3" },
		{ "00000004WAV","4" },
		{ "00000005WAV","5" },
		{ "00000006WAV","6" },
		{ "00000007WAV","7" },
		{ "00000008WAV","8" },
		{ "00000009WAV","9" },
		{ "00000010WAV","10" },
		{ "00000011WAV","11" },
		{ "00000012WAV","12" },
		{ "00000013WAV","13" },
		{ "00000014WAV","14" },
		{ "00000015WAV","15" },
		{ "00000016WAV","16" }
	},

	{	//Soundboard 12
		{ "T01RAND4WAV","test track" },
		{ "T01RAND4WAV","test track 2" },
		{ "00000003WAV","3" },
		{ "00000004WAV","4" },
		{ "00000005WAV","5" },
		{ "00000006WAV","6" },
		{ "00000007WAV","7" },
		{ "00000008WAV","8" },
		{ "00000009WAV","9" },
		{ "00000010WAV","10" },
		{ "00000011WAV","11" },
		{ "00000012WAV","12" },
		{ "00000013WAV","13" },
		{ "00000014WAV","14" },
		{ "00000015WAV","15" },
		{ "00000016WAV","16" }
	},

	{	//Soundboard 13
		{ "T01RAND4WAV","test track" },
		{ "T01RAND4WAV","test track 2" },
		{ "00000003WAV","3" },
		{ "00000004WAV","4" },
		{ "00000005WAV","5" },
		{ "00000006WAV","6" },
		{ "00000007WAV","7" },
		{ "00000008WAV","8" },
		{ "00000009WAV","9" },
		{ "00000010WAV","10" },
		{ "00000011WAV","11" },
		{ "00000012WAV","12" },
		{ "00000013WAV","13" },
		{ "00000014WAV","14" },
		{ "00000015WAV","15" },
		{ "00000016WAV","16" }
	},

	{	//Soundboard 14
		{ "T01RAND4WAV","test track" },
		{ "T01RAND4WAV","test track 2" },
		{ "00000003WAV","3" },
		{ "00000004WAV","4" },
		{ "00000005WAV","5" },
		{ "00000006WAV","6" },
		{ "00000007WAV","7" },
		{ "00000008WAV","8" },
		{ "00000009WAV","9" },
		{ "00000010WAV","10" },
		{ "00000011WAV","11" },
		{ "00000012WAV","12" },
		{ "00000013WAV","13" },
		{ "00000014WAV","14" },
		{ "00000015WAV","15" },
		{ "00000016WAV","16" }
	},

	{	//Soundboard 15
		{ "T01RAND4WAV","test track" },
		{ "T01RAND4WAV","test track 2" },
		{ "00000003WAV","3" },
		{ "00000004WAV","4" },
		{ "00000005WAV","5" },
		{ "00000006WAV","6" },
		{ "00000007WAV","7" },
		{ "00000008WAV","8" },
		{ "00000009WAV","9" },
		{ "00000010WAV","10" },
		{ "00000011WAV","11" },
		{ "00000012WAV","12" },
		{ "00000013WAV","13" },
		{ "00000014WAV","14" },
		{ "00000015WAV","15" },
		{ "00000016WAV","16" }
	},

	{	//Soundboard 16
		{ "T01RAND4WAV","test track" },
		{ "T01RAND4WAV","test track 2" },
		{ "00000003WAV","3" },
		{ "00000004WAV","4" },
		{ "00000005WAV","5" },
		{ "00000006WAV","6" },
		{ "00000007WAV","7" },
		{ "00000008WAV","8" },
		{ "00000009WAV","9" },
		{ "00000010WAV","10" },
		{ "00000011WAV","11" },
		{ "00000012WAV","12" },
		{ "00000013WAV","13" },
		{ "00000014WAV","14" },
		{ "00000015WAV","15" },
		{ "00000016WAV","16" }
	},


};

int amountOfKeysPressed = 0;
int trellisKeysPressed[16] = { false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false };
int volumeModeBtns[16] = { 1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
word currentSoundboard = 0;
#define modePlay 1
#define modeSetVolume 2
#define modeSetSoundboard 3
int mode = modePlay;

void SERCOM1_Handler(){
	Serial2.IrqHandler();
}

void setup() {
	Serial.begin(9600);
	display.begin(SSD1306_SWITCHCAPVCC, 0x3D);  

	pinMode(INTPIN, INPUT);
	digitalWrite(INTPIN, HIGH);
	trellis.begin(0x70);

	display.clearDisplay();
	display.display();
	display.setTextSize(1);
	display.setTextColor(WHITE);
	display.setCursor(0, 0);
	display.setTextWrap(false);
	display.println("Soundbox v2");
	display.display();

	Serial2.begin(9600);
	pinPeripheral(10, PIO_SERCOM);
	pinPeripheral(11, PIO_SERCOM);
	
	if (!sfx.reset()) {
		Serial.println("Not found");
		display.println(F("Couldn't find soundboard"));
		display.display();
		while (1);
	}
	else {
		display.println(F("soundboard found"));
		display.display();
	}

	delay(2000);
	volume = sfx.volDown();
	while (volume != 0) {
		if (volume > 0) {
			volume = sfx.volDown();
		}
	}
	
	while (volume < 120) {
		volume = sfx.volUp();
	}
	volume = 10;

	showTrellisStartSequence();
	showIdleDisplay();
}


void loop() {
	if (!trackPlaying) {
		readTrellis();
		delay(250);
		readTrellis();
	}
	delay(30);

	checkInput();
	if (trackPlaying && (trackToPlay > -1)) {
		playTrack(trackToPlay);
	}
}

void readTrellis() {
	if (trellis.readSwitches()) {
		// go through every button
		for (uint8_t i = 0; i < numKeys; i++) {
			if (trellis.justPressed(i)) {
				trellisKeysPressed[i] = true;
			}
			if (trellis.justReleased(i)) {
				trellisKeysPressed[i] = false;
			}
		}
	}
}

void checkInput() {
	amountOfKeysPressed = 0;
	for (uint8_t i = 0; i < numKeys; i++) {
		// if it was pressed...
		if (trellisKeysPressed[i] == true) {
			amountOfKeysPressed++;
		}
	}

	if (amountOfKeysPressed == 1) {
		for (uint8_t i = 0; i < numKeys; i++) {
			if ((trellisKeysPressed[i] == true) && (mode == modePlay)) {
				trackToPlay = i;
				playTrack(trackToPlay);
			}

			if ((trellisKeysPressed[i] == true) && (mode == modeSetVolume)) {
				if (i == volume) {
					mode = modePlay;
					for (uint8_t i = 0; i < numKeys; i++) {
						trellis.clrLED(i);
					}
					trellis.blinkRate(0);
					trellis.writeDisplay();
				}

				else if (i < 16) {
					clearVolume();
					
					while (i > volume) {
						for (int t = 1; t < 12; t++) {
							sfx.volUp();
						}
						volume++;
					}

					while (i < volume) {
						for (int t = 1; t < 12; t++) {
							sfx.volDown();
						}
						volume--;
					}
					printVolume();

					for (uint8_t i = 0; i < numKeys; i++) {
						if (i <= volume) {
							trellis.setLED(i);
						}
						else {
							trellis.clrLED(i);
						}
					}

					trellis.writeDisplay();
				}
			}

			if ((trellisKeysPressed[i] == true) && (mode == modeSetSoundboard)) {
				if (i == currentSoundboard) {
					mode = modePlay;
					for (uint8_t i = 0; i < numKeys; i++) {
						trellis.clrLED(i);
					}
					trellis.blinkRate(0);
					trellis.writeDisplay();
				}
				else {
					trellis.clrLED(currentSoundboard);
					clearSoundboardName();
					currentSoundboard = i;
					printSoundboardName();
					trellis.setLED(currentSoundboard);
					trellis.writeDisplay();
				}
			}
		}
	}
	if (amountOfKeysPressed == 2) {
		Serial.println("2 buttons!");
		if (trellisKeysPressed[0] && trellisKeysPressed[15]) {
			mode = modeSetVolume;
			trellis.blinkRate(1);
			for (uint8_t i = 0; i < numKeys; i++) {
				if (i <= volume) {
					trellis.setLED(i);
				}
				else {
					trellis.clrLED(i);
				}
			}
			trellis.writeDisplay();
		}

		if (trellisKeysPressed[0] && trellisKeysPressed[1]) {
			mode = modeSetSoundboard;
			trellis.blinkRate(1);
			trellis.setLED(currentSoundboard);
			trellis.writeDisplay();
		}
	}

	for (uint8_t i = 0; i < numKeys; i++) {
		trellisKeysPressed[i] = false;
	}
}

void playTrack(int key) {
	uint32_t current, total;
	trackPlaying = true;
	trackName = trellisPad1[currentSoundboard][key][1];
	display.setCursor(14, 31);

	if (strlen(trackName) > 18) {
		strncpy(subTrackName, trackName, 15);
		display.print(subTrackName);
		display.print("...");
	}
	else {
		display.print(trackName);
	}


	display.display();
	trellis.setLED(key);
	trellis.writeDisplay();
	Serial.println(trellisPad1[currentSoundboard][key][0]);
	sfx.playTrack(trellisPad1[currentSoundboard][key][0]);

	delay(1000);
	if (!sfx.trackTime(&current, &total)) 
		Serial.println("Failed to query");
	Serial.print(current); Serial.println(" seconds");

	delay ((total*1000)+2000);

	trellis.clrLED(key);
	trellis.writeDisplay();
	trackPlaying = false;
	trackToPlay = -1;
	display.setCursor(14, 31);
	display.setTextColor(BLACK);
	if (strlen(trackName) > 18) {
		strncpy(subTrackName, trackName, 15);
		display.print(subTrackName);
		display.print("...");
	}
	else {
		display.print(trackName);
	}
	display.display();
	display.setTextColor(WHITE);
}

uint32_t trackLength(char trackName) {
	uint32_t trash, length;

	sfx.trackTime(&trash, &length);
	Serial.println(length);
	return length;
}

void showTrellisStartSequence() {
	for (uint8_t i = 0; i<numKeys; i++) {
		trellis.setLED(i);
		trellis.writeDisplay();
		delay(50);
	}
	for (uint8_t i = 0; i<numKeys; i++) {
		trellis.clrLED(i);
		trellis.writeDisplay();
		delay(50);
	}
}

void showIdleDisplay() {
	display.setTextSize(1);
	display.clearDisplay();
	display.setCursor(30, 0);
	display.print("Soundbox 2");
	display.setTextSize(1);
	display.setCursor(20, 10);
	display.print("Push to annoy!");
	display.drawLine(0, 19, 128, 19, WHITE);
	display.setCursor(0, 31);
	display.write(14);
	display.print(": ");
	display.setCursor(83, 56);
	display.print("Vol: ");
	display.display();
	printSoundboardName();
	printVolume();
}

void printSoundboardName() {
	display.setTextSize(1);
	display.setTextColor(WHITE);
	display.setCursor(0, 23);
	display.write(64);
	display.print(": ");
	display.setCursor(14, 23);
	display.print(soundBoards[currentSoundboard]);
	display.display();
}

void clearSoundboardName() {
	display.setTextSize(1);
	display.setCursor(14, 23);
	display.setTextColor(BLACK);
	display.print(soundBoards[currentSoundboard]);
	display.display();
}


void printVolume() {
	display.setCursor(110, 56);
	display.setTextColor(WHITE);
	display.print(volume, DEC);
	display.display();
}

void clearVolume() {
	display.setCursor(110, 56);
	display.setTextColor(BLACK);
	display.print(volume, DEC);
	display.display();
}

Credits

WT040
2 projects • 12 followers
Contact

Comments

Please log in or sign up to comment.