Implement octave shift buttons code?

Hi,

I am very new to the Arduino movement and would like some help implementing an octave switch to a project I have just completed.

The project was based on the touch capacitive keyboard project found on instructables. Everything is working fine but I have no idea how I’d go about the code I’d need to be able to change octaves up or down.

Here is my code so far:

#include <CapacitiveSensor.h>

CapacitiveSensor cs_2_3 = CapacitiveSensor(2,3); 
CapacitiveSensor cs_2_4 = CapacitiveSensor(2,4);
CapacitiveSensor cs_2_5 = CapacitiveSensor(2,5); 
CapacitiveSensor cs_2_6 = CapacitiveSensor(2,6);
CapacitiveSensor cs_2_7 = CapacitiveSensor(2,7); 
CapacitiveSensor cs_2_8 = CapacitiveSensor(2,8);
CapacitiveSensor cs_2_9 = CapacitiveSensor(2,9); 
CapacitiveSensor cs_2_10 = CapacitiveSensor(2,10);

int velocity = 100;//velocity of MIDI notes, must be between 0 and 127
//(higher velocity usually makes MIDI instruments louder)

int noteON = 144;//144 = 10010000 in binary, note on command

void setup() {
// Set MIDI baud rate:
Serial.begin(31250);

}

void loop() {

long total1 = cs_2_3.capacitiveSensor(30);
long total2 = cs_2_4.capacitiveSensor(30);
long total3 = cs_2_5.capacitiveSensor(30);
long total4 = cs_2_6.capacitiveSensor(30);
long total5 = cs_2_7.capacitiveSensor(30);
long total6 = cs_2_8.capacitiveSensor(30);
long total7 = cs_2_9.capacitiveSensor(30);
long total8 = cs_2_10.capacitiveSensor(30);

if (total1 > 700) {

for (int note=60;note<62;note++) {//from note 50 (D3) to note 69 (A4)
MIDImessage(noteON, note, velocity);//turn note on
delay(0);
MIDImessage(noteON, note, 0);}}//turn note off

if (total2 > 700) {
for (int note=62;note<64;note++) {//from note 50 (D3) to note 69 (A4)
MIDImessage(noteON, note, velocity);//turn note on
delay(0);//hold note for 300ms
MIDImessage(noteON, note, 0);}}//turn note off 

if (total3 > 500) {

for (int note=64;note<65;note++) {//from note 50 (D3) to note 69 (A4)
MIDImessage(noteON, note, velocity);//turn note on
delay(0);
MIDImessage(noteON, note, 0);}}//turn note off

if (total4 > 700) {
for (int note=65;note<67;note++) {//from note 50 (D3) to note 69 (A4)
MIDImessage(noteON, note, velocity);//turn note on
delay(0);//hold note for 300ms
MIDImessage(noteON, note, 0);}}//turn note off 

if (total5 > 700) {

for (int note=67;note<69;note++) {//from note 50 (D3) to note 69 (A4)
MIDImessage(noteON, note, velocity);//turn note on
delay(0);
MIDImessage(noteON, note, 0);}}//turn note off

if (total6 > 700) {
for (int note=69;note<71;note++) {//from note 50 (D3) to note 69 (A4)
MIDImessage(noteON, note, velocity);//turn note on
delay(0);//hold note for 300ms
MIDImessage(noteON, note, 0);}}//turn note off 

if (total7 > 700) {

for (int note=71;note<72;note++) {//from note 50 (D3) to note 69 (A4)
MIDImessage(noteON, note, velocity);//turn note on
delay(0);
MIDImessage(noteON, note, 0);}}//turn note off

if (total8 > 700) {
for (int note=72;note<73;note++) {//from note 50 (D3) to note 69 (A4)
MIDImessage(noteON, note, velocity);//turn note on
delay(0);//hold note for 300ms
MIDImessage(noteON, note, 0);}}//turn note off 

}
//send MIDI message
void MIDImessage(int command, int MIDInote, int MIDIvelocity) {
Serial.write(command);//send note on or note off command 
Serial.write(MIDInote);//send pitch data
Serial.write(MIDIvelocity);//send velocity data
}

Any help on this would be greatly appreciated! :slight_smile:

Looks like you are using all your capsense inputs to play pairs of notes. Did you want to add more capsense inputs for the "buttons" or use physical buttons?

Hi John,

I was under the impression that I could still use digital pins 11, 12 and 13 on my UNO r3 for this. Using pin 11 for moving the octave up, and 12 to move the octave down using capsense. Is there a limit to how many inputs can be used via capsense?

I shall take a look into this.

Thanks for the reply John!

If anybody can help me with just an example of how you can implement the concept of octave up and down into the code I already have, this would be greatly appreciated. I just can't fathom it!

PLEASE!! =(

PolyKrome: If anybody can help me with just an example of how you can implement the concept of octave up and down into the code I already have, this would be greatly appreciated. I just can't fathom it!

PLEASE!! =(

There are lots of tutorials about reading buttons and debouncing the signal (mechanical buttons tend to bounce a few times on closing). Use a variable to keep track of which octave. Use buttons to go up and down. Add some checks so that you don't go outside your desired range of octaves.