As usual we recalled information from last weeks lab as well as sharing information from our individual research on mozzi.
The first task was to build the circuit for the buzzer. I firstly built the circuit using the solder-less breadboard and then copied the code that would be needed to make the buzzer work. This was the code:
//Specify digital pin on the Arduino that the positive lead of piezo buzzer is attached.
const int piezoPin = 8;
void setup() {
}//close setup
void loop() {
/*Tone needs 2 arguments, but can take three
1) Pin#
2) Frequency – this is in hertz (cycles per second) which
determines the pitch of the noise made
3) Duration – how long teh tone plays
*/
tone(piezoPin, 1000, 500);//tone(piezoPin, 1000, 500);
//delay(1000);
} –
The final outcome was that the buzzer worked. We were able to play around with the delay time and the tone which would affect the pitch of the sound as well as how long the sound is played for.
The next task was to change the tone that it would continue to get a higher pitch as time went by. The delay time has to be changed for that to be made possible and this is shown below in the code:
//Specify digital pin on the Arduino that the positive lead of piezo buzzer is attached.
const int piezoPin = 8;
void setup() {
}//close setup
void loop() {
/*Tone needs 2 arguments, but can take three
1) Pin#
2) Frequency – this is in hertz (cycles per second) which
determines the pitch of the noise made
3) Duration – how long the tone plays
*/for (int i=31; i<10000; i++) {
tone(piezoPin, i, 1000);
delay(10);
The next task was to upload a Mario tone. Using the code it would use different delay and tones to create the melody of the Mario tone we all know well. My outcome was positive in the end even though I did run into an issue with the upload of the tone. This was because I was working with 2 active functions in different tabs. I fixed this by beginning a new file and putting in the code and it worked. (The code is toooooo long to copy into here)
The next task was to create a digital oscillator. This had a different breadboard configuration so I firstly put the components on the breadboard first. Then I uploaded the code on to Arduino. This is the code that was used:
//CODE DigitalOSC ******
const int ledPin = 13; //variable to represent LED Pin
const int periodKnob = A0; //variable for knob pin (A0 = analog in pin 0)
int delayTime; //variable for the delay time
void setup() {
pinMode(ledPin, OUTPUT); //configure pin 13 as a digital output
}
void loop() { //set delay time equal to the current value read on analog pin 0 delayTime = analogRead(periodKnob);
//map the analog read range from 0-1023 to 10000-1 //delayTime = map(delayTime, 0, 1023, 10000, 1);
digitalWrite(ledPin, HIGH);
delayMicroseconds(delayTime);
digitalWrite(ledPin, LOW);
delayMicroseconds(delayTime);
With this code I was able to use the knob to change the tone of the sound. turning it up to make the tone high and turning it down to make the tone deeper.