10 Mayıs 2015 Pazar

Buzzer Control by using a Soft Potentiometer

        Using a Soft Potentiometer, we are able to control the song of the buzzer that is being played. As the value of the Soft potentiometer changes, so as the note of the buzzer.

        The circuit diagrams (one made on digital environment, the other one is the implemented) and the datasheet of shift register can be seen below:


Digital Drawed Circuit



Implemented Circuit



      Here is a video available to see the outputs and how the system works:







Arduino Code :


/*
  Can KAVALOĞLU
*/

const int softPin = 0;
const int buzzerPin = 9;
const int songLength = 18;
char notes[] = "cdfda ag cdfdg gf ";
int beats[] = {1,1,1,1,1,1,4,4,2,1,1,1,1,1,1,4,4,2};
int tempo = 150;
char notes_2[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b' };

void setup(){
  pinMode(buzzerPin, OUTPUT);
  Serial.begin(9600);
}

void loop(){
  int i, duration,index;
  index = analogRead(softPin)/4; 
  index = map(index, 0, 256, 0, 6);
  
  duration = beats[i] * tempo;
  if (notes[i] == ' '){
    delay(duration);
  }
  else{
    tone(buzzerPin, frequency(notes_2[index]), duration);
    delay(duration);
  }
  delay(tempo/10);
  Serial.println(index);
}


int frequency(char note){
  int i;
  const int numNotes = 8;
  char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
  int frequencies[] = {262, 294, 330, 349, 392, 440, 494, 523};

  for (i = 0; i < numNotes; i++){
    if (names[i] == note){
      return(frequencies[i]);
    }
  }
  return(0);
}



Hiç yorum yok:

Yorum Gönder