Digipixel Piezo

Post here to discuss all things DigiPixel related.

Moderators: Chuckt, Garth, bitfogav

Post Reply [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
User avatar
ZephaniahNoah
semi-newbie
semi-newbie
Posts: 24
Joined: Wed Dec 31, 2014 7:17 am
Location: Milky Way, Earth
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Digipixel Piezo

Post by ZephaniahNoah » Wed Dec 31, 2014 8:28 am

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.
Last edited by ZephaniahNoah on Fri Jan 02, 2015 6:02 pm, edited 3 times in total.
DigiPixel is AWESOME! Image

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Digipixel Piezo

Post by brad » Wed Dec 31, 2014 9:34 am

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 :)

User avatar
ZephaniahNoah
semi-newbie
semi-newbie
Posts: 24
Joined: Wed Dec 31, 2014 7:17 am
Location: Milky Way, Earth
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Digipixel Piezo

Post by ZephaniahNoah » Thu Jan 01, 2015 10:36 am

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.
DigiPixel is AWESOME! Image

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Re: Digipixel Piezo

Post by bitfogav » Sun Jan 04, 2015 9:39 pm

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 :)
If you don't know what Voltage your country is using, you shouldn't be doing electronics ;-)

User avatar
ZephaniahNoah
semi-newbie
semi-newbie
Posts: 24
Joined: Wed Dec 31, 2014 7:17 am
Location: Milky Way, Earth
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Digipixel Piezo

Post by ZephaniahNoah » Wed Jan 07, 2015 9:32 am

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.
DigiPixel is AWESOME! Image

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Digipixel Piezo

Post by brad » Wed Jan 07, 2015 9:55 am

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.

User avatar
ZephaniahNoah
semi-newbie
semi-newbie
Posts: 24
Joined: Wed Dec 31, 2014 7:17 am
Location: Milky Way, Earth
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Digipixel Piezo

Post by ZephaniahNoah » Sat Jan 10, 2015 6:36 am

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.
DigiPixel is AWESOME! Image

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Digipixel Piezo

Post by brad » Sat Jan 10, 2015 1:53 pm

Infant the tone function uses interrupts itself in the form of timer2

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Who is online

Users browsing this forum: No registered users and 6 guests