arduino music – Kevin Gulling http://www.kevingulling.com Game Development, VR, and more Sat, 17 Dec 2016 20:26:01 +0000 en-US hourly 1 https://wordpress.org/?v=5.9.13 81085834 12 Days of Arduino – Day 4 – Tremolo FX With Shift Register https://kevingulling.com/2016/12/12-days-of-arduino-day-4-tremolo-fx-with-shift-register/ https://kevingulling.com/2016/12/12-days-of-arduino-day-4-tremolo-fx-with-shift-register/#comments Fri, 16 Dec 2016 19:31:58 +0000 https://kevingulling.com/?p=1284 Welcome back to day 4 of 12 days of Arduino! I’m glad you’ve been following this far, things are about to get exciting! Today I take the keyboard and using a SN74HC595 Texas Instruments Shift Register I create a tremolo effect Project requires –Arduino Uno –Active buzzer –3x button touch switch -220 ohm resistor -3x […]

The post 12 Days of Arduino – Day 4 – Tremolo FX With Shift Register appeared first on Kevin Gulling - Game Development, VR, and more.

]]>
shift register tremolo

Welcome back to day 4 of 12 days of Arduino! I’m glad you’ve been following this far, things are about to get exciting! Today I take the keyboard and using a SN74HC595 Texas Instruments Shift Register I create a tremolo effect



Project requires
–Arduino Uno
–Active buzzer
–3x button touch switch
-220 ohm resistor
-3x 10k ohm resistor
-220 ohm resistor
-Jumper wires
-Tip120
-SN74HC595

SN74HC595 Shift Register datasheet.
Tip 120 datasheet from adafruit.

arduino keyboard with tremelo

Keyboard with Tremolo Sketch


//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 11;

int number = 1;
int speakerPin = 6;

//Buttons
int button1Pin = 2;
int button2Pin = 3;
int button3Pin = 4;

void setup() {
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(speakerPin, OUTPUT);
pinMode(button1Pin, INPUT);
pinMode(button2Pin, INPUT);
pinMode(button3Pin, INPUT);

}

void loop() {
if(digitalRead(button1Pin) == HIGH){
tone(speakerPin, 1000);
digitalWrite(latchPin, LOW);
// shift out the bits:
shiftOut(dataPin, clockPin, MSBFIRST, number);
digitalWrite(latchPin, HIGH);
delay(10);
number++;
}
else if(digitalRead(button2Pin) == HIGH){
tone(speakerPin, 2000);
digitalWrite(latchPin, LOW);
// shift out the bits:
shiftOut(dataPin, clockPin, MSBFIRST, number);
digitalWrite(latchPin, HIGH);
delay(10);
number++;
}
else if(digitalRead(button3Pin) == HIGH){
tone(speakerPin, 3000);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, number);
digitalWrite(latchPin, HIGH);
delay(10);
number++;
}
else{
number = 0;
digitalWrite(latchPin, LOW);
// shift out the bits:
shiftOut(dataPin, clockPin, MSBFIRST, number);
digitalWrite(latchPin, HIGH);
delay(10);
}

}

One thing to note here is that MSBFIRST means “most significant bit first” and LSBFIRST means “least significant bit first”. We want to use MSBFIRST to accomplish this effect. Basically what’s happening here is we increment 0 by 1 each time the loop is ran and as a result we have an alternating effect on pin 1 of the shift register. A cleaner way to run this would be to increment by 1 and then subtract by 1, but really this is all pointless in the first place, it’s definitely a “Rube Goldberg” way of going about this since you could simply program it with code, but there are opportunities here to utilize 7 more pins, so maybe tomorrow I can make this into something “practical” (I use this term loosely!) and utilize more of the 8 bits of memory we can store here! The possibilities are endless, exciting!

Here’s a tutorial for ShiftOut I highly recommend if you are getting started with shift registers!

Please check out the sponsor of this series:


The post 12 Days of Arduino – Day 4 – Tremolo FX With Shift Register appeared first on Kevin Gulling - Game Development, VR, and more.

]]>
https://kevingulling.com/2016/12/12-days-of-arduino-day-4-tremolo-fx-with-shift-register/feed/ 1 1284
12 Days of Arduino – Day 2 – Arduino Piano / Keyboard https://kevingulling.com/2016/12/12-days-arduino-day-2-arduino-piano-keyboard/ https://kevingulling.com/2016/12/12-days-arduino-day-2-arduino-piano-keyboard/#comments Wed, 14 Dec 2016 15:04:52 +0000 https://kevingulling.com/?p=1242 Hello everybody and welcome back to Day 2 of “12 Days of Arduino”! On the second day of Arduino Kevin gave to thee: Arduino Piano/Keyboard Remember this is not a tutorial, just a tech demo, if you are looking for tutorials check out @educ8s.tv on YouTube! If you read the previous article (Arduino Morse Code […]

The post 12 Days of Arduino – Day 2 – Arduino Piano / Keyboard appeared first on Kevin Gulling - Game Development, VR, and more.

]]>
arduino keyboard

Hello everybody and welcome back to Day 2 of “12 Days of Arduino”! On the second day of Arduino Kevin gave to thee:

Arduino Piano/Keyboard

arduino keyboard photo

Remember this is not a tutorial, just a tech demo, if you are looking for tutorials check out @educ8s.tv on YouTube!

If you read the previous article (Arduino Morse Code Keyer) you can see that making a sound with the press of a button is simple as pi. It stands to reason that making a musical instrument out of the same components is not that difficult of a stretch. Thankfully Arduino’s Tone class used with an active buzzer makes this easy!


Project requires

–Arduino Uno
–Active buzzer
–4x button touch switch
-LED
-220 ohm resistor
-4x 10k ohm resistor
-jumper wires



The sketch:

sketch

Piano / Keyboard Sketch

I’m going to leave the code in text format here rather than an image so it’s easier to copy and because the sketches are becoming too large to fit in a screenshot!

int switchPin1 = 2;
int switchPin2 = 4;
int switchPin3 = 7;
int switchPin4 = 8;
int ledPin = 13;
int speakerPin = 11;

void setup() {
// put your setup code here, to run once:
pinMode(switchPin1, INPUT);
pinMode(switchPin2, INPUT);
pinMode(switchPin3, INPUT);
pinMode(switchPin4, INPUT);
pinMode(ledPin, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(switchPin1) == HIGH){
digitalWrite(ledPin, HIGH);
tone(speakerPin, 880); //A5 880 //B 988 //C6 1046 //D 1175 // E6 1319 //F 1396 // G6 1567 //A6 1760 //B 1976
}
else if(digitalRead(switchPin2) == HIGH){
digitalWrite(ledPin, HIGH);
tone(speakerPin, 932); //bflat
}
else if(digitalRead(switchPin3) == HIGH){
digitalWrite(ledPin, HIGH);
tone(speakerPin, 1046);
}
else if(digitalRead(switchPin4) == HIGH){
digitalWrite(ledPin, HIGH);
tone(speakerPin, 1319);
}
else{
digitalWrite(ledPin, LOW);
noTone(speakerPin);
}
}

Because of the if/else setup here, you can “pull-off” to a lower note by pressing two buttons at once. You could reverse the order of the speaker frequency values if you wanted to accomplish a “hammer-on” instead.

The Tone class is a blast to play with. The Arduino itself can trigger frequencies from 31Hz to 65535Hz, way beyond the human audible frequency range. Maybe I’ll make a dog whistle next? 😉 You could essentially use a larger breadboard and a shift register to create a full size piano/keyboard.

Here is a great resource to find the frequencies for each note: http://www.phy.mtu.edu/~suits/notefreqs.html

If you have any ideas for improving the Arduino keyboard or want to share your own construction feel free to show us in the comments!

Please check out the sponsor of this series:


Day 3 →

The post 12 Days of Arduino – Day 2 – Arduino Piano / Keyboard appeared first on Kevin Gulling - Game Development, VR, and more.

]]>
https://kevingulling.com/2016/12/12-days-arduino-day-2-arduino-piano-keyboard/feed/ 1 1242