Austin Detzel
Published © CC BY-NC-SA

Draw Sound With Arduino

Drawing is fun, so is making music. So let's combine them so we can draw sounds! It's simple once you understand how it works.

IntermediateFull instructions provided1.5 hours1,263
Draw Sound With Arduino

Story

Read more

Code

Code snippet #1

Plain text
#define speaker 3
#define led 5
#define pot A0
#define input_pin A1
#define pitch_min 50
#define pitch_max 4978


void setup() {
  Serial.begin(9600);
 
}

void loop() {
  int input_pitch = analogRead(pot);
  int input = analogRead(input_pin);
  int pitch_adj = map(input_pitch, 0, 1023, -500, 500); 
  int pitch = map(input, 0, 1023, pitch_min, pitch_max);
  int b = map(input, 0, 1023, 0, 255);
  analogWrite(led, b);
  Serial.println(pitch);
  int final_pitch = pitch + pitch_adj;
  if(final_pitch > pitch_max){
    final_pitch = pitch_max;
  }
  if(final_pitch < pitch_min){
    final_pitch = pitch_min;
  }
if(final_pitch != pitch_min){
    if(pitch != pitch_min){
      tone(speaker, final_pitch, 30);
    }
  }
  delay(25);
}

Credits

Austin Detzel

Austin Detzel

26 projects • 38 followers

Comments