Randomized Arduino Drum Machine

by blinkyblinky in Circuits > Arduino

28469 Views, 77 Favorites, 0 Comments

Randomized Arduino Drum Machine

SAM_5080.JPG
SAM_5091.JPG
SAM_5092.JPG

I like drum machines. However they are not always the easiest to build. I wanted one that is:

A. Simple, Yet Powerful - If it uses lots of components then it is too complicated
B. Sound - It's not much of a drum machine if it "beeps"
C. Easily Modifiable - If I can't change stuff for improvement, then it is kind of annoying.

A meticulous internet search wasn't so successful.

Finally, I found this but, even that was a bit un-editable although it was cool. I thought that the samples were a bit small and I for one was not going to rewrite a bunch of samples.

Therefore, I decided to play around with the code and rewrote my own version of it and tweaked it around until I got a sound I liked.

Remember: Make sure you have the Potentiometer on Analog Pin 1 and not Analog Pin Zero. The True Random library uses this wobbly voltage to pick random numbers.

I drew up a schematic from the code and then made it real.

I know this uses the TX (Digital Pin 1) and RX (Digital Pin Zero) but I had already built a Digital to Analog Converter shield for those pins and decided not to build it again.

Parts and Stuff.

SAM_5093.JPG
Resistor.jpg
SAM_5090.JPG
perf-board.jpg
SAM_5094.JPG
pr1055044a.jpg
SAM_5095.JPG
You Will Need:
8 1K Resistors
8 2K Resistors
1 Potentiometer
1 3-Pin Terminal Block
Male Headers
Arduino Uno
Perf Board/Breadboard

Program.

PC101888.JPG
Here is the source code so far:

#include <TrueRandom.h>

/*
You will need the TrueRandom library: http://code.google.com/p/tinkerit/wiki/TrueRandom
Drum Machine mkII
Original Code by: Sebastian Tomczak
Remade to have random beats by: Blinkyblinky
Have Fun!
*/

int wavesound;
int delayval;
int barLength = 16;
byte kick[] =

{

127, 80, 42, 5, 165, 242, 241, 233, 128, 73, 48, 22, 127, 69, 55, 113, 151, 183, 209, 217, 223, 228, 233, 215, 161, 117, 91, 76, 65, 49, 37, 31, 31, 48, 83, 120, 146, 166, 183, 198, 206, 210, 209, 199, 178, 145, 111, 88, 78, 73, 69, 67, 72, 80, 88, 97, 109, 124, 137, 150, 163, 171, 174, 172, 168, 160, 144, 125, 114, 110, 108, 104, 104, 106, 109, 110, 112, 117, 124, 129, 135, 142, 145, 145, 143, 140, 137, 132, 128, 125, 122, 119, 118, 119, 119, 119, 118, 118, 120, 124, 126, 129, 132, 135, 137, 137, 135, 132, 131, 130, 129, 128, 126, 126, 124, 123, 121, 120, 120, 122, 123, 124, 126, 128, 129, 130, 130, 131, 131, 131, 130, 130, 130, 129, 129, 128, 126, 125, 125, 124, 124, 124, 124, 125, 126, 126, 128, 128, 128, 129, 129, 129, 129, 129, 128, 128, 128, 128, 126, 126, 126, 126, 126, 126, 126, 126, 126, 128, 127, 126, 128, 128, 128, 128, 128, 128, 128, 128, 126, 126, 126, 126, 126, 126, 126, 126, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126

};

byte snare[] =

{

127, 215, 65, 212, 56, 102, 135, 122, 51, 201, 220, 46, 175, 80, 152, 95, 123, 116, 184, 155, 59, 122, 100, 161, 143, 173, 101, 155, 97, 73, 112, 98, 176, 96, 140, 77, 134, 109, 132, 149, 112, 149, 97, 161, 98, 151, 98, 155, 149, 112, 157, 103, 133, 106, 167, 97, 166, 108, 129, 124, 136, 146, 124, 136, 129, 150, 94, 130, 105, 141, 146, 128, 129, 99, 150, 121, 141, 99, 142, 116, 131, 114, 118, 143, 127, 143, 115, 144, 120, 137, 109, 129, 131, 139, 129, 113, 144, 119, 145, 117, 135, 129, 134, 136, 124, 130, 130, 139, 121, 136, 121, 132, 128, 127, 126, 122, 130, 126, 138, 120, 136, 122, 131, 123, 130, 128, 127, 128, 118, 132, 125, 131, 122, 131, 125, 131, 122, 126, 128, 126, 129, 121, 129, 123, 132, 129, 127, 131, 123, 128, 125, 130, 123, 131, 123, 128, 131, 129, 128, 126, 125, 124, 131, 121, 124, 129, 130, 126, 124, 126, 127, 130, 125, 126, 128, 126, 128, 126, 126, 126, 126, 125, 128, 126, 126, 126, 126, 126, 126, 125, 128, 126, 126, 126, 126, 126, 126, 126, 126, 128, 128, 126, 128, 126, 127, 126, 128, 125, 127, 128, 128, 126, 126, 128, 126, 126, 128, 128, 128, 128, 128, 126, 128, 126, 126, 128, 128, 126, 126, 128, 128, 126, 126, 127, 126, 128, 126, 126, 128, 128, 128, 126, 126, 126, 128, 128, 126, 126, 126, 128, 128, 126, 128, 128, 126, 126

};


byte hat[] =


{

127, 128, 225, 217, 99, 38, 61, 153, 152, 144, 133, 73, 122, 144, 65, 188, 87, 170, 164, 111, 122, 151, 114, 88, 174, 77, 140, 92, 122, 141, 156, 124, 121, 123, 126, 133, 132, 139, 119, 120, 127, 141, 130, 122, 129, 127, 132, 121, 139, 118, 130, 131, 129, 132, 130, 134, 126, 128, 130, 126, 122, 132, 129, 127, 131, 126, 128, 127, 126, 125, 127, 125, 128, 125, 128, 128, 127, 127, 126, 127, 128, 128, 128, 127, 127, 127, 127, 127, 128, 127, 127, 126, 127, 127, 128, 127, 128, 126, 127, 128, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 128, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 128, 128, 126, 126, 128, 127, 126, 127, 126, 127, 127, 126, 127, 126, 127, 127, 127, 127, 127, 126, 127, 127, 127, 126, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 126, 126, 126, 127, 127, 127, 126, 127, 127, 127, 126, 127, 127, 126, 127, 127, 127, 127, 127, 127, 126, 126, 126, 126, 126, 126, 126, 127, 127, 126, 127, 126, 126, 127, 126, 127, 126, 126, 126, 126, 126, 126, 126, 127, 127, 126, 127, 127, 127, 127, 126, 126, 127, 127, 127, 126, 127, 126, 127, 127, 127, 127, 127, 126, 126, 127, 127, 126, 127, 127, 127, 127, 126, 127, 127, 127, 127, 127, 127, 127, 127

};


byte crash[] =


{

127, 128, 225, 217, 99, 38, 61, 153, 152, 144, 133, 73, 122, 144, 65, 188, 87, 170, 164, 111, 122, 151, 114, 88, 174, 77, 140, 92, 122, 141, 156, 124, 121, 123, 126, 133, 132, 139, 119, 120, 127, 141, 130, 122, 129, 127, 132, 121, 139, 118, 130, 131, 129, 132, 130, 134, 126, 128, 130, 126, 122, 132, 129, 127, 131, 126, 128, 127, 126, 125, 127, 125, 128, 125, 128, 128, 127, 127, 126, 127, 128, 128, 128, 127, 127, 127, 127, 127, 128, 127, 127, 126, 127, 127, 128, 127, 128, 126, 127, 128, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 128, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 128, 128, 126, 126, 128, 127, 126, 127, 126, 127, 127, 126, 127, 126, 127, 127, 127, 127, 127, 126, 127, 127, 127, 126, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 126, 126, 126, 127, 127, 127, 126, 127, 127, 127, 126, 127, 127, 126, 127, 127, 127, 127, 127, 127, 126, 126, 126, 126, 126, 126, 126, 127, 127, 126, 127, 126, 126, 127, 126, 127, 126, 126, 126, 126, 126, 126, 126, 127, 127, 126, 127, 127, 127, 127, 126, 126, 127, 127, 127, 126, 127, 126, 127, 127, 127, 127, 127, 126, 126, 127, 127, 126, 127, 127, 127, 127, 126, 127, 127, 127, 127, 127, 127, 127, 127

};



void setup() {
  // declare which of the DAC's pins are outputs
  DDRD = DDRD | B11111001;


}

void loop() {
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);
wavesound = TrueRandom.random(1,6);
playBeat(wavesound);





} 



void playBeat(byte beat) {

if(beat == 1) {

for(int i = 0; i < 256; i ++) {

delayMicroseconds(analogRead(1) + 1);

}

}

else if(beat == 2) {

playKick();

}

else if(beat == 3) {

playSnare();

}

else if(beat == 4) {

playHat();

}

else if(beat == 5) {

playCrash();

}


delay(80);

}

void playKick() {

for(int i = 0; i < 256; i ++) {

PORTD = kick[i];

delayMicroseconds(analogRead(1) + 1);

}

PORTD = 127;


}



void playSnare() {

for(int i = 0; i < 256; i ++) {

PORTD = snare[i];

delayMicroseconds(analogRead(1) + 1);

}

PORTD = 127;


}



void playHat() {

for(int i = 0; i < 256; i ++) {

PORTD = hat[i];

delayMicroseconds(analogRead(1) + 1);

}

PORTD = 127;


}


void playCrash() {

for(int i = 0; i < 256; i ++) {

PORTD = crash[i];

delayMicroseconds(analogRead(1) + 1);

}

PORTD = 127;

}
 



Here is some more code you can try:


#include <TrueRandom.h>

/*
You will need the TrueRandom library: http://code.google.com/p/tinkerit/wiki/TrueRandom
Drum Machine mkII
Original Code by: Sebastian Tomczak
Remade to have random beats by: Blinkyblinky
Have Fun!
*/

int wavesound;
int wavesound1;
int wavesound2;
int wavesound3;
int wavesound4;
int wavesound5;
int wavesound6;
int wavesound7;
int wavesound8;
int wavesound9;
int wavesound10;
int wavesound11;
int wavesound12;
int wavesound13;
int wavesound14;
int wavesound15;
int wavesound16;
int wavesound17;
int wavesound18;
int wavesound19;
int wavesound20;
int delayval;
int barLength = 16;
byte kick[] =

{

127, 80, 42, 5, 165, 242, 241, 233, 128, 73, 48, 22, 127, 69, 55, 113, 151, 183, 209, 217, 223, 228, 233, 215, 161, 117, 91, 76, 65, 49, 37, 31, 31, 48, 83, 120, 146, 166, 183, 198, 206, 210, 209, 199, 178, 145, 111, 88, 78, 73, 69, 67, 72, 80, 88, 97, 109, 124, 137, 150, 163, 171, 174, 172, 168, 160, 144, 125, 114, 110, 108, 104, 104, 106, 109, 110, 112, 117, 124, 129, 135, 142, 145, 145, 143, 140, 137, 132, 128, 125, 122, 119, 118, 119, 119, 119, 118, 118, 120, 124, 126, 129, 132, 135, 137, 137, 135, 132, 131, 130, 129, 128, 126, 126, 124, 123, 121, 120, 120, 122, 123, 124, 126, 128, 129, 130, 130, 131, 131, 131, 130, 130, 130, 129, 129, 128, 126, 125, 125, 124, 124, 124, 124, 125, 126, 126, 128, 128, 128, 129, 129, 129, 129, 129, 128, 128, 128, 128, 126, 126, 126, 126, 126, 126, 126, 126, 126, 128, 127, 126, 128, 128, 128, 128, 128, 128, 128, 128, 126, 126, 126, 126, 126, 126, 126, 126, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126

};

byte snare[] =

{

127, 215, 65, 212, 56, 102, 135, 122, 51, 201, 220, 46, 175, 80, 152, 95, 123, 116, 184, 155, 59, 122, 100, 161, 143, 173, 101, 155, 97, 73, 112, 98, 176, 96, 140, 77, 134, 109, 132, 149, 112, 149, 97, 161, 98, 151, 98, 155, 149, 112, 157, 103, 133, 106, 167, 97, 166, 108, 129, 124, 136, 146, 124, 136, 129, 150, 94, 130, 105, 141, 146, 128, 129, 99, 150, 121, 141, 99, 142, 116, 131, 114, 118, 143, 127, 143, 115, 144, 120, 137, 109, 129, 131, 139, 129, 113, 144, 119, 145, 117, 135, 129, 134, 136, 124, 130, 130, 139, 121, 136, 121, 132, 128, 127, 126, 122, 130, 126, 138, 120, 136, 122, 131, 123, 130, 128, 127, 128, 118, 132, 125, 131, 122, 131, 125, 131, 122, 126, 128, 126, 129, 121, 129, 123, 132, 129, 127, 131, 123, 128, 125, 130, 123, 131, 123, 128, 131, 129, 128, 126, 125, 124, 131, 121, 124, 129, 130, 126, 124, 126, 127, 130, 125, 126, 128, 126, 128, 126, 126, 126, 126, 125, 128, 126, 126, 126, 126, 126, 126, 125, 128, 126, 126, 126, 126, 126, 126, 126, 126, 128, 128, 126, 128, 126, 127, 126, 128, 125, 127, 128, 128, 126, 126, 128, 126, 126, 128, 128, 128, 128, 128, 126, 128, 126, 126, 128, 128, 126, 126, 128, 128, 126, 126, 127, 126, 128, 126, 126, 128, 128, 128, 126, 126, 126, 128, 128, 126, 126, 126, 128, 128, 126, 128, 128, 126, 126

};


byte hat[] =


{

127, 128, 225, 217, 99, 38, 61, 153, 152, 144, 133, 73, 122, 144, 65, 188, 87, 170, 164, 111, 122, 151, 114, 88, 174, 77, 140, 92, 122, 141, 156, 124, 121, 123, 126, 133, 132, 139, 119, 120, 127, 141, 130, 122, 129, 127, 132, 121, 139, 118, 130, 131, 129, 132, 130, 134, 126, 128, 130, 126, 122, 132, 129, 127, 131, 126, 128, 127, 126, 125, 127, 125, 128, 125, 128, 128, 127, 127, 126, 127, 128, 128, 128, 127, 127, 127, 127, 127, 128, 127, 127, 126, 127, 127, 128, 127, 128, 126, 127, 128, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 128, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 128, 128, 126, 126, 128, 127, 126, 127, 126, 127, 127, 126, 127, 126, 127, 127, 127, 127, 127, 126, 127, 127, 127, 126, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 126, 126, 126, 127, 127, 127, 126, 127, 127, 127, 126, 127, 127, 126, 127, 127, 127, 127, 127, 127, 126, 126, 126, 126, 126, 126, 126, 127, 127, 126, 127, 126, 126, 127, 126, 127, 126, 126, 126, 126, 126, 126, 126, 127, 127, 126, 127, 127, 127, 127, 126, 126, 127, 127, 127, 126, 127, 126, 127, 127, 127, 127, 127, 126, 126, 127, 127, 126, 127, 127, 127, 127, 126, 127, 127, 127, 127, 127, 127, 127, 127

};


byte crash[] =


{

127, 128, 225, 217, 99, 38, 61, 153, 152, 144, 133, 73, 122, 144, 65, 188, 87, 170, 164, 111, 122, 151, 114, 88, 174, 77, 140, 92, 122, 141, 156, 124, 121, 123, 126, 133, 132, 139, 119, 120, 127, 141, 130, 122, 129, 127, 132, 121, 139, 118, 130, 131, 129, 132, 130, 134, 126, 128, 130, 126, 122, 132, 129, 127, 131, 126, 128, 127, 126, 125, 127, 125, 128, 125, 128, 128, 127, 127, 126, 127, 128, 128, 128, 127, 127, 127, 127, 127, 128, 127, 127, 126, 127, 127, 128, 127, 128, 126, 127, 128, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 128, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 128, 128, 126, 126, 128, 127, 126, 127, 126, 127, 127, 126, 127, 126, 127, 127, 127, 127, 127, 126, 127, 127, 127, 126, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 126, 126, 126, 127, 127, 127, 126, 127, 127, 127, 126, 127, 127, 126, 127, 127, 127, 127, 127, 127, 126, 126, 126, 126, 126, 126, 126, 127, 127, 126, 127, 126, 126, 127, 126, 127, 126, 126, 126, 126, 126, 126, 126, 127, 127, 126, 127, 127, 127, 127, 126, 126, 127, 127, 127, 126, 127, 126, 127, 127, 127, 127, 127, 126, 126, 127, 127, 126, 127, 127, 127, 127, 126, 127, 127, 127, 127, 127, 127, 127, 127

};



void setup() {
  // declare the SpeakerPin as an OUTPUT:

  DDRD = DDRD | B11111001;


}

void loop() {
  
wavesound = TrueRandom.random(1,5);
wavesound1 = TrueRandom.random(1,5);
wavesound2 = TrueRandom.random(1,5);
wavesound3 = TrueRandom.random(1,5);
wavesound4 = TrueRandom.random(1,5);
wavesound5 = TrueRandom.random(1,5);
wavesound6 = TrueRandom.random(1,5);
wavesound7 = TrueRandom.random(1,5); 
wavesound8 = TrueRandom.random(1,5);
wavesound9 = TrueRandom.random(1,5);
wavesound10 = TrueRandom.random(1,5);
wavesound11 = TrueRandom.random(1,5);
wavesound12 = TrueRandom.random(1,5);
wavesound13 = TrueRandom.random(1,5);
wavesound14 = TrueRandom.random(1,5);
wavesound15 = TrueRandom.random(1,5);
wavesound16 = TrueRandom.random(1,5);
wavesound17 = TrueRandom.random(1,5);
wavesound18 = TrueRandom.random(1,5);
wavesound19 = TrueRandom.random(1,5);
wavesound20 = TrueRandom.random(1,5);
playBeat(wavesound);
playBeat(wavesound1);
playBeat(wavesound2);
playBeat(wavesound3);
playBeat(wavesound4);
playBeat(wavesound5);
playBeat(wavesound6); 
playBeat(wavesound7);
playBeat(wavesound8);
playBeat(wavesound9);
playBeat(wavesound10);
playBeat(wavesound11);
playBeat(wavesound12);
playBeat(wavesound13);
playBeat(wavesound14);
playBeat(wavesound15);
playBeat(wavesound16);
playBeat(wavesound17);
playBeat(wavesound18);
playBeat(wavesound19);
playBeat(wavesound20);


} 



void playBeat(byte beat) {

if(beat == 1) {

for(int i = 0; i < 256; i ++) {

delayMicroseconds(analogRead(1) + 1);

}

}

else if(beat == 2) {

playKick();

}

else if(beat == 3) {

playSnare();

}

else if(beat == 4) {

playHat();

}

else if(beat == 5) {

playCrash();

}


delay(80);

}

void playKick() {

for(int i = 0; i < 256; i ++) {

PORTD = kick[i];

delayMicroseconds(analogRead(1) + 1);

}

PORTD = 127;

}



void playSnare() {

for(int i = 0; i < 256; i ++) {

PORTD = snare[i];

delayMicroseconds(analogRead(1) + 1);

}

PORTD = 127;

}



void playHat() {

for(int i = 0; i < 256; i ++) {

PORTD = hat[i];

delayMicroseconds(analogRead(1) + 1);

}

PORTD = 127;

}


void playCrash() {

for(int i = 0; i < 256; i ++) {

PORTD = crash[i];

delayMicroseconds(analogRead(1) + 1);

}

PORTD = 127;

}
 


Okay...So What Exactly Is a DAC?

SAM_5093.JPG
A DAC or, Digital to Analog Converter is essentially, a device that takes a series of on-off pulses from a computer, which speaks in binary (or microcontroller) and then converts it into specific voltage levels.

So How does it do it exactly?

Collin Cunningham will explain in more depth:




Let's Get Started!

DAC.png
DrumMachineImage.jpg
SAM_5087.JPG
SAM_5092.JPG
Build according to the schematic. I can supply pictures of my build in the end but my camera was broken at the time I made this and so, I don't have the pictures for during the build. Sorry.

Let's Finish!

SAM_5095.JPG
SAM_5094.JPG
Solder the headers terminal and the output wires and commence testing. (make sure you screw in the potentiometer.)

Done!

SAM_5081.JPG
SAM_5080.JPG
SAM_5082.JPG
That's it!

If you need any help or you have any suggestions PM me or leave a comment below.