Musical Instruments

From XinCheJian
Jump to navigation Jump to search
   
Musical Instruments

Release status: stable [box doku]

Description sound generator with visual reference
Author(s)  User:edward.giles
Last Version  v1

Edward Giles is a young but ambitious maker of 11 years old and member of XinCheJian, his projects range from generating sound to making things move or both - he is an interactive artist, he has a passion to make stuff and can usually be found working on his projects at XinCheJian on a Wednesday, he is always working on something and takes a special interest in "Conway's Game of Life" as presented for the first time in early 2012 at Barcamp Shanghai.

EdwardPhoto.jpg

3-button musical instrument

My project is a musical instrument, designed to have as few controls as possible (3 buttons and a headphone/speaker mode switch) and use a shift register chip. It can play notes from three octaves (22 notes) and has indicator lights to display the note and the octave. The side lights signal that there is an extra octave on that side, while the red lights indicate the note. It generates sounds using the tone function.

Edwardgiles-1.png

1st beta: As you can see, it is not user-friendly, so the next step is to put a housing around it. There are so many wires that can be pulled out. The buttons are read by this circuit:

Edwardgiles-2.png

I learned how to use a shift register chip (SN74HC595) The full circuit schematic:

Edwardgiles-3.png


Source code (upload to Arduino and insert 3-button instrument):

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

// Frequency lookup table
int tones[] = {131,147,165,175,196,220,247,262,294,330,349,392,440,494,523,587,659,698,784,880,988,1047};

byte obj = 128;
int freq = 7;

void setup() {
  //set pins to output so you can control the shift register
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(4, OUTPUT);
  analogReference(DEFAULT);
  pinMode(5, OUTPUT);
}

void loop() {
    if (buttonPressed(0)) {
      obj = obj << 1;
      freq -= 1;
      if (obj == 0) {
        obj = 1;
      }
      if (freq == -1) {
          freq = 0;
          obj = 64;
      }
      delay(140);
    }
    if (buttonPressed(1)) {
      obj = obj >> 1;
      freq += 1;
      if (obj == 0) {
        obj = 128;
      }
      if (freq >= 22) {
          freq = 21;
          obj = 2;
      }
      delay(140);
    }
    digitalWrite(latchPin, LOW);
    digitalWrite(clockPin, LOW);
    digitalWrite(2, HIGH);
    digitalWrite(4, HIGH);
    // shift out the bits:
    if (freq < 7) {
      digitalWrite(2, LOW);
    }
    if (freq > 14) {
      digitalWrite(4, LOW);
    }
    shiftOut(dataPin, clockPin, LSBFIRST, obj);  

    //take the latch pin high so the LEDs will light up:
    digitalWrite(latchPin, HIGH);
    // pause before next value:
    tone(5, tones[freq]);
    delay(25);
  }
boolean buttonPressed(int button) {
  int val = 1023;
  val = analogRead(button);
  if (val < 100) {
    return HIGH;
  } else {
    return LOW;
  }
}

Workshop in Beijing

Current status: I have finished making kits and I have received my custom PCBs.


BoardSides.png


Instructions: This assumes you know how to solder Learn at [1]
Make sure the board is the right way up. It should say "Keyboard for Arduino".
1. Bend the wires of the 220 ohm resistors (red, red, brown, gold/none) so they fit into the positions marked R1 to R9, as well as R14.
2. While holding the resistors, turn over the board and bend the wires out so they don't fall out.
3. Solder them in place.
4. Repeat steps 1-3 for the two 10 kilo-ohm resistors (brown, black, black, red, brown). Place it in the positions marked R10 and R11.
5. Repeat steps 1-3 for the 330 ohm resistor (orange, orange, black, black, brown). Place it in the position marked R12.
6. Repeat steps 1-3 for the 4.7 kilo-ohm resistor (yellow, violet, red, gold/none). Place it in the position marked R13.
7. Place the 3 black pushbuttons into the places marked S1, S2 and S3.
8. Turn the board over and solder the buttons in place.
9. Place in the black chip. Make sure the notch faces in the same direction as the break in the white line on the circuit board in the place marked U1. If it does not fit in the holes, bend the metal pins inwards on a flat surface.
10. Solder each of the pins into the holes. Do not let two pins of the chip be soldered together.
11. Place in the switch.
12. Place the 8 red LEDs into the places marked LED1 to LED9. Make sure the longer wire is nearer to the top of the board than the bottom lead.
13. While holding them in place, turn the board over and bend the metal wires outwards.
14. Repeat steps 12 and 13 for the 2 green LEDs. Place them in LED9 and LED10.
15. Place the green screw terminal into the 2-hole area near the top-right corner.
16. Rest the board upside-down on the table and solder the screw terminal in place.
17. Turn the board over, so the text is facing forward.
18. Insert the headphone plug into the area labeled "TRS1".
19. Turn the board over and solder the headphone jack in place.
Note: Before soldering in a component, turn the board so that the printed side (the top) is facing up.

Musical Keyboard

Another project that I am starting is a musical keyboard:

Edwardgiles-4.png

To finish this project it requires an extra Arduino.