Group project with Rick

Greetings friends!

For this weekly assignment, we have created a music buzzer with a bpm bird.

We have made the song “All star” using piano notes and tone.h to make
make it sound like the actual song. It took a long time to make it because I had to make a list of notes manually from the music score. Rick made a BPM bird using a servo to hit the beat once per 400ms, and in combination it sounded on sync. The problems that we’ve encountered was that servo.h and tone.h are not compatible with one another due to the inner-timer that these libraries use. We tried to look into the tone.h library to find the respective frequencies of the notes, but due to the delay issue, we had to separate the servo and the buzzer on separate Arduino boards to make it work properly.

Source Codes:

#include <Servo.h>

unsigned long previousMillis = 0;
const long interval = 7;
int angle = 0;

Servo myservo;

void setup() {
  myservo.attach(5);
}

void loop() {
  myservo.write(angle);
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
    angle = (angle + 1) % 64;
  }
}
#include<Tone.h>
//                  0       1         2         3         4       5       6       7         8       9
int notes[11] = {NOTE_C4, NOTE_D4, NOTE_E4, NOTE_F4, NOTE_G4, NOTE_A4, NOTE_B4, NOTE_C5, NOTE_D5, NOTE_E5, 0};
int i = 0;
int duration[90] = {4, 2, 2, 4, 2, 2, 2, 4, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 2, 6, 4,
                    2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 4, 2, 2, 4, 2, 2, 4, 4, 4,
                    2, 4, 1, 1, 2, 4, 1, 1, 2, 4, 4, 2, 4, 2, 4, 1, 1, 2, 4, 1, 1, 2, 4, 4, 2, 4,
                    4, 4, 2, 2, 2, 8, 2, 2, 2, 2, 8, 4, 2, 4, 4, 16
                   };
int note[90] = {4, 8, 6, 6, 5, 4, 4, 7, 6, 6, 5, 5, 4, 4, 8, 6, 6, 5, 5, 4, 4, 2, 10,
                4, 4, 8, 6, 6, 5, 5, 4, 4, 7, 6, 6, 5, 5, 4, 4, 8, 6, 6, 5, 4, 4, 5, 2, 10,
                6, 4, 4, 2, 4, 4, 4, 2, 4, 4, 4, 6, 10, 6, 4, 4, 2, 4, 4, 4, 2, 4, 4, 4, 6, 10,
                6, 8, 7, 6, 5, 5, 4, 4, 5, 4, 6, 5, 4, 5, 2, 10
               };
Tone player;

void setup() {
  player.begin(3);
}

void loop() {
  player.play(notes[note[i % 90]], duration[i % 90] * 100);
  delay(duration[i % 90] * 100 + 20);
  i++;
}

 

One thought on “Group project with Rick”

Leave a Reply