[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/session.php on line 580: sizeof(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/session.php on line 636: sizeof(): Parameter must be an array or an object that implements Countable
Brads Electronic Projects Forum • Digipixel Piezo
Page 1 of 1

Digipixel Piezo

Posted: Wed Dec 31, 2014 8:28 am
by ZephaniahNoah
I was just wondering how to use the Piezo buzzer on the DigiPixel. It goes here right? I soldered the negative lead to the square hole and positive to the circle.
Image
How would I figure out which pins to send the sound to? I'm a complete newbie to the DigiPixel as well as Arduino but I've made games in other computer languages and I was able to create something simple for the DigiPixel. I've barely worked with micro-controllers and don't know how to add sound to my game.

EDIT: Just in case anyone was wondering I soldered the Piezo on wrong. Don't do it the way I did.

Re: Digipixel Piezo

Posted: Wed Dec 31, 2014 9:34 am
by brad
The piezo speaker connection was a bit of a late requested addition and as such I didn't write any code for it myself however the main thing you need to know is that it is connected to the Arduino pin 9.

So if you have a look on google for 'arduino sound' or something to that effect, you should get some pretty good tutorials.

Here is one such example:

http://arduino.cc/en/pmwiki.php?n=Reference/tone

Just remember that your piezo speaker is connected to pin 9 :)

Re: Digipixel Piezo

Posted: Thu Jan 01, 2015 10:36 am
by ZephaniahNoah
brad wrote:The piezo speaker connection was a bit of a late requested addition and as such I didn't write any code for it myself however the main thing you need to know is that it is connected to the Arduino pin 9.

So if you have a look on google for 'arduino sound' or something to that effect, you should get some pretty good tutorials.

Here is one such example:

http://arduino.cc/en/pmwiki.php?n=Reference/tone

Just remember that your piezo speaker is connected to pin 9 :)
Awesome! Thanks, I'll have a look.

Re: Digipixel Piezo

Posted: Sun Jan 04, 2015 9:39 pm
by bitfogav
I was going to say isn't that the wrong way around for the piezo connections? but I see you have now updated your post :)

How did you get on with this ZephaniahNoah? I was hoping to try out this too :)

Re: Digipixel Piezo

Posted: Wed Jan 07, 2015 9:32 am
by ZephaniahNoah
bitfogav wrote:I was going to say isn't that the wrong way around for the piezo connections? but I see you have now updated your post :)

How did you get on with this ZephaniahNoah? I was hoping to try out this too :)
It went well. Any time I wanted my game to play a sound I just added:

tone(9, frequency, duration);

However, if I wanted to play a little jingle when the player died I would have to put a delay(X); and set X to the previous tone's duration. For instance, if I were to just do... :

Code: Select all

tone(9, 100, 100);
tone(9, 200, 100);
tone(9, 300, 100);
...it would play all sounds at once. But this... :

Code: Select all

tone(9, 100, 100);
delay(100);
tone(9, 200, 100);
delay(100);
tone(9, 300, 100);
...plays each sound separately. But of course this wouldn't work so well if I wanted a dyeing animation because delay stops the whole program for that amount of time causing the screen to turn black. I don't mind this so much but for music obviously this would be terrible. There is some kind of timer that subtracts from a variable until it equals zero then continues the code without stopping the whole program, but I haven't tried that.
The link brad provided was very useful and I was able to look up pretty much everything else on the web but other than that it was quite simple.

Re: Digipixel Piezo

Posted: Wed Jan 07, 2015 9:55 am
by brad
What you could do is look into using interrupts. You can set the interrupt for a certain amount of time (like your delays) but your code still runs and then when that certain amount of time has ticked over, the interrupt will trigger your audio code.

Re: Digipixel Piezo

Posted: Sat Jan 10, 2015 6:36 am
by ZephaniahNoah
brad wrote:What you could do is look into using interrupts. You can set the interrupt for a certain amount of time (like your delays) but your code still runs and then when that certain amount of time has ticked over, the interrupt will trigger your audio code.
Ok, I'll look into that.

Re: Digipixel Piezo

Posted: Sat Jan 10, 2015 1:53 pm
by brad
Infant the tone function uses interrupts itself in the form of timer2