Playing with a Piezo buzzer!



The purpose of the project is to use a piezo buzzer and have it make different sounds.  I feel like I failed with the potentiometer and the button for the dice.  I figured that I would try something more simple with building and focus on the code.  I was able to create three codes to have the buzzer make three different sounds.  The most difficult part of the project was altering the code.  I had to determine what to add and where to change the original code to make the buzzer play a different sounds.  This reminds me of the different sounds in a sports or board game that requires different buzzer sounds. 


 

Original buzzer sound


Code:

Siren Sound



Change of the code:

void loop() {
  // Rising tone
  for (int f = 400; f <= 1200; f += 10) {
    tone(buzzerPin, f, 20);
    delay(20);
  }

  // Falling tone
  for (int f = 1200; f >= 400; f -= 10) {
    tone(buzzerPin, f, 20);
    delay(20);
  }
}

SciFi Beat





Change of the code:

void loop() {
  int f = random(200, 2000);      // random pitch
  int d = random(50, 300);        // random duration
  tone(buzzerPin, f, d);
  delay(d + 30);
}










Comments

Popular posts from this blog

Maker Spacer

Week 2 Maker spacer challenge