Music to My Ears

Introducing the world’s most annoying instrument! I made an audio-visual musical instrument whose pitch changes depending on how hard to press the force sensor.

https://vimeo.com/87478117

int buzzer = 9;
int forceReading = A1;
int green = 11;
int yellow = 10;
int red = 8;
int green_ = 7;
int c= 261
int d= 294
int e= 329
int f= 349
int g= 392
int a=440
int b=493
int c_=523

void setup(){
  Serial.begin(9600);
  pinMode(7, INPUT);
  pinMode(green, OUTPUT);
  pinMode(yellow, OUTPUT);
  pinMode(red, OUTPUT);
  pinMode(green_, OUTPUT);
}

void loop(){
  int reading = analogRead(forceReading);
  Serial.println(reading);

  if (reading < 70){
    tone(buzzer, c);
    digitalWrite(green, HIGH);
  }
  else{
    digitalWrite(green, LOW);
  }
  if (reading > 69 && reading < 140){
    tone (buzzer, d);
  }
  if (reading > 139 && reading < 210){
    tone(buzzer, e);
    digitalWrite(yellow, HIGH);
  }
  else{
    digitalWrite(yellow, LOW);
  }
  if (reading > 209 && reading < 280){
    tone (buzzer, f);
  }
  if (reading >279 && reading < 350){
    tone (buzzer, g);
    digitalWrite(red, HIGH);
  }
  else{
    digitalWrite(red, LOW);
  }
  if (reading > 349 && reading < 420){
    tone (buzzer, a);
  }
  if (reading > 419 && reading < 490){
    tone (buzzer, b);
  }
  if (reading > 489 && reading < 560){
    tone (buzzer, c_);
    digitalWrite(green_, HIGH);
  }
  else{
    digitalWrite(green_, LOW);
  }
}

 

Leave a Reply