Instrument

This website is all about the instrument Jaeho and I have created.


How It Works

Our instrument is controlled by seven different buttons which each play a different note. Each note does not play until you press it and will play for as long as you hold down the button which plays it. The notes you can play are: A, B, C, D, E, F, G, H. Here is a diagram of what our instrument looked like:

Arduino Code For Instrument

Following is the Arduino code Jaeho and I have created for our instrument:

  /* Instrument
Cory Byrne and Jaeho Jang
2017-05-31
 */

  int buttonA = 2; //button A connected to port 2
  int buttonB = 3; //button B connected to port 3
  int buttonC = 4; //button C connected to port 4
  int buttonD = 5; //button D connected to port 5
  int buttonE = 6; //button E connected to port 6
  int buttonF = 7; //button F connected to port 7
  int buttonG = 8; //button G connected to port 8

void setup() { //code for seting up each button
pinMode (buttonA, INPUT);
pinMode (buttonB, INPUT);
pinMode (buttonC, INPUT);
pinMode (buttonD, INPUT);
pinMode (buttonE, INPUT);
pinMode (buttonF, INPUT);
pinMode (buttonG, INPUT);
}

void loop() { //code for reading if any button is pressed
  if (digitalRead(buttonA)==HIGH) { //if button A is pressed play note A
    a ();
  }
  if (digitalRead(buttonB)==HIGH) { //if button B is pressed play note B
    b ();
  }
  if (digitalRead(buttonC)==HIGH) { //if button C is pressed play note C
    c ();
  }
  if (digitalRead(buttonD)==HIGH) { //if button D is pressed play note D
    d ();
  }
  if (digitalRead(buttonE)==HIGH) { //if button E is pressed play note E
    e ();
  }
  if (digitalRead(buttonF)==HIGH) { //if button F is pressed play note F
    f ();
  
  if (digitalRead(buttonG)==HIGH) { //if button G is pressed play note G
    g ();
  }
}
void a () { //code for playing 'A' note
  // play the tone using pin 13 with frequency 440 Hz for 500 ms = 0.3 seconds
  tone(13, 440, 30);
}
void b () { //code for playing 'B' note
  // play the tone using pin 13 with frequency 494 Hz for 500 ms = 0.3 seconds
  tone(13, 494, 30);
}
void c () { //code for playing 'C' note
  // play the tone using pin 13 with frequency 523 Hz for 500 ms = 0.3 seconds
  tone(13, 523, 30);
}
void d () { //code for playing 'D' note
  // play the tone using pin 13 with frequency 587 Hz for 500 ms = 0.3 seconds
  tone(13, 587, 30);
}
void e () { //code for playing 'E' note
  // play the tone using pin 13 with frequency 659 Hz for 500 ms = 0.3 seconds
  tone(13, 659, 30);
}
void f () { //code for playing 'F' note
  // play the tone using pin 13 with frequency 698 Hz for 500 ms = 0.3 seconds
  tone(13, 698, 30);
}
void g () { //code for playing 'G' note
  // play the tone using pin 13 with frequency 784 Hz for 500 ms = 0.3 seconds
  tone(13, 784, 30);
}
	

Diagram