Slider Piano: group 24

Andrew Ferg
Bereket Abraham
Lauren Berdick
Ryan Soussan

Group 24

Before we tell you about our amazing resistor piano, we just wanted to show you this awesome picture of the acceleration picked up by the accelerometer in Part 5.

Data picked up from the accelerometer

Three ideas:
– Make a drum out of the piezo. The piezo readings can be run through processing to play a tune/melody each time the piezo is hit.

IMG_0433

– a therimen made from an accelerometer. As you rotate the accelerometer through an angle theta, the pitch changes. As you rotate through a different angle, the tempo changes.

IMG_0221

– A piano made out of a slimpot. As you press different areas of the slimpot, the buzzer plays different notes.

Piano Slider

Final result:

In the end, we chose the piano. However, for the final design we ditched the buzzer and played the notes through the computer. Using the serial port, we sent the notes to a processing script. Using the SoundCipher library, we were able to play computer generated notes and simulate the piano keys visually. We thought it was a success. The graphics synced well with the hardware and it sounded realistic. We did have some issues with the “debouncing” of the keys — if you held a key down it played the note twice. But it was not that noticeable.

IMG_2054

Parts used in final system

Arduino
Wires
Slimpot
Resistors

Instructions to recreate

A slimpot has variable resistance when the user presses different areas of the slimpot. Seeing this, we decided to segment the resistances, so each resistance was assigned an interval. Each interval corresponded to a different piano key. We sent this piano key number to Processing over the serial port. We then downloaded Soundcipher library off the internet which plays notes given a frequency. This allowed us to play the keys. We used rectangles to visualize the keys of the keyboard on the screen (using Processing for the graphics). The keys dimmed in colour when they were pressed. The 32bit Processing had to be downloaded in order to use the serial port.

Source code

Arduino Code:

// these constants won't change:
const int pin1 = A0; // the piezo is connected to analog pin 0

// Voltage thresholds of the piano keys
// 15,20,33,50, 130, 200,
// these variables will change:
int sensorReading = 0;      // variable to store the value read from the sensor pin

void setup() {
 Serial.begin(9600);       // use the serial port
 
}

void loop() {
  sensorReading = analogRead(pin1);    
  
  if (sensorReading > 200) Serial.write((uint8_t)0);
  else if (sensorReading > 130) Serial.write((uint8_t)1);
  else if (sensorReading > 50) Serial.write((uint8_t)2);
  else if (sensorReading > 33) Serial.write((uint8_t)3);
  else if (sensorReading > 20) Serial.write((uint8_t)4);
  else if (sensorReading > 15) Serial.write((uint8_t)5);
  else if (sensorReading > 2) Serial.write((uint8_t)6);
  else;
  
  delay(100);  // delay to avoid overloading the serial port buffer
}

Processing Code:

import arb.soundcipher.*;

SoundCipher sc;
int keysNoteMap[] = {59, 60, 63, 64, 65, 67, 69};
import processing.serial.*;
Serial myPort;  // The serial port

void setup(){
  sc = new SoundCipher(this);
  //keysNoteMap = new int[7];
  
  //keysNoteMap[7] = {59, 60, 63, 64, 65, 67, 69};
  size (250,150);
  println(Serial.list());
  myPort = new Serial(this, Serial.list()[0], 9600);
  println("starting....");
}

// keep processing 'alive'
void draw() {
  boolean pressed = false;
  int note = 9;
  while (myPort.available() > 0) {
    note = myPort.read();
    pressed = true;
    println(note);
    sc.playNote(keysNoteMap[note], 100, 1);
  }
  
//white tut 
  fill(255);
  if( pressed && note==6){
    fill(204);
  }
  rect (10, 10, 30, 100);
    
  fill(255);
    if( pressed && note==5){
    fill(204);
  }
  rect (40, 10, 30, 100);
    fill(255);
    if( pressed && note==4){
    fill(204);
  }
  rect (70, 10, 30, 100);
    fill(255);
    if( pressed && note==3){
    fill(204);
  }
  rect (100, 10, 30, 100);
    fill(255);
    if( pressed && note==2){
    fill(204);
  }
  
  rect (130, 10, 30, 100);
    fill(255);
    if( pressed && note==1){
    fill(204);
  }
  
  rect (160, 10, 30, 100);
    fill(255);
    if( pressed && note==0){
    fill(204);
  }
  
  rect (190, 10, 30, 100);
  
  //black tut
  fill(0);
  rect (32,10,15,60);
  fill(0);
  rect (62,10,15,60);
  fill(0);
  rect (122,10,15,60);
  fill(0);
  rect (152,10,15,60);
  fill(0);
  rect (182,10,15,60);
  
  if(pressed){
    sc.playNote(keysNoteMap[note], 100, 4.0);
    delay(100); 
  }
  pressed = false;
}