sounds activated with button using Arduino

djsfantasi

Joined Apr 11, 2010
9,156
Here is sample code of how the library should be used.

Code:
#include "Volume.h"
Volume vol;
uint16_t frequency = 440;
void setup() {
  vol.begin();
  vol.alternatePin(true);
}
void loop() {
  for(byte volume = 0; volume < 255; volume++){
    vol.tone(frequency,volume);
    vol.delay(5);
  }
. . .
 

MrSoftware

Joined Oct 29, 2013
2,188
And add yourself a print statement after the if(button == high) so that you can have a second visual confirmation that the button press is being detected.

In regards to the comment above about digital read and debouncing; the way you're dong it now is not the best way to read a button press and as mentioned can give you some funny behavior from debouncing and missed button presses, but it should work good enough to get some sound out of it if you press the button a few times. Eventually you'll want to setup an interrupt to occur when that button goes high. Then inside your interrupt handler, take care of debouncing and set a flag. In your main loop check for the flag, if it's set then play the sound, then clear the flag.
 

Thread Starter

Killerbee65

Joined May 15, 2017
256
And add yourself a print statement after the if(button == high) so that you can have a second visual confirmation that the button press is being detected.

In regards to the comment above about digital read and debouncing; the way you're dong it now is not the best way to read a button press and as mentioned can give you some funny behavior from debouncing and missed button presses, but it should work good enough to get some sound out of it if you press the button a few times. Eventually you'll want to setup an interrupt to occur when that button goes high. Then inside your interrupt handler, take care of debouncing and set a flag. In your main loop check for the flag, if it's set then play the sound, then clear the flag.
Thanks! Although I'm more of a visual learner I'll try my best to understand, if not I'll come back to ask questions but so far great!
 

djsfantasi

Joined Apr 11, 2010
9,156
His button wiring and button read code can be working just fine.

The first issue is there is no sound. One could expect to hear something from the setup() routine, which tries to play a sound without a button push.

This sketch will NEVER make a sound. Not even a peep.

That’s because it is using commands attached to an object defined by the Volume3 library. But the object is NOT defined in the code, nor is it initialized properly.

As I’ve explained in prior posts.

The TS needs to concentrate on getting sound out of the setup() routine. Once this is working, a pleasant surprise may be that the push button code starts working.

The problem is NOT the push button.
 

Deleted member 115935

Joined Dec 31, 1969
0
As the OP has said ,
they have many forum posts. They have been on this problem for a long time,
The OP says they are a programmer, but to be fair, I see very little evidence of that,

I was wondering about pointing the OP back to the basics, learn how to use the ardino, by using some of the simple example codes , such as the button ,

Either that or some one is going to have to give them the code in total.
 

Thread Starter

Killerbee65

Joined May 15, 2017
256
As the OP has said ,
they have many forum posts. They have been on this problem for a long time,
The OP says they are a programmer, but to be fair, I see very little evidence of that,

I was wondering about pointing the OP back to the basics, learn how to use the ardino, by using some of the simple example codes , such as the button ,

Either that or some one is going to have to give them the code in total.
The OP?
 

Thread Starter

Killerbee65

Joined May 15, 2017
256
As the OP has said ,
they have many forum posts. They have been on this problem for a long time,
The OP says they are a programmer, but to be fair, I see very little evidence of that,

I was wondering about pointing the OP back to the basics, learn how to use the ardino, by using some of the simple example codes , such as the button ,

Either that or some one is going to have to give them the code in total.
I assume you're referring to me? I did mention. In a few of my threads that I am only a beginner, for a comparison, I am only just learning my ABC'S while people that take their time and help me have most likely already written books (figuratively speaking). It is also hard for me to understand concepts I can't physically dissect and learn, hence why I have so many forums up. I am not looking for a cut and dry answer, I appreciate all the time these people put into helping me. To those who have stuck this far, thank you I have learned so much from you all and I am very much a better "programmer" than what I was when I started.
 

MrSoftware

Joined Oct 29, 2013
2,188
His button wiring and button read code can be working just fine.

The first issue is there is no sound. One could expect to hear something from the setup() routine, which tries to play a sound without a button push.

This sketch will NEVER make a sound. Not even a peep.

That’s because it is using commands attached to an object defined by the Volume3 library. But the object is NOT defined in the code, nor is it initialized properly.

As I’ve explained in prior posts.

The TS needs to concentrate on getting sound out of the setup() routine. Once this is working, a pleasant surprise may be that the push button code starts working.

The problem is NOT the push button.
We all agree. My post about the print for the button was to verify to him that his button was working so he could check it off of his mental checklist and focus more on your point, which I agree is where the real problem is. :)
 

Thread Starter

Killerbee65

Joined May 15, 2017
256
If I am u understanding right, you are saying the way this code is setup os what is making it difficult to use a button? I got the concept of setup() that you explained thank you.
 

djsfantasi

Joined Apr 11, 2010
9,156
If I am u understanding right, you are saying the way this code is setup os what is making it difficult to use a button? I got the concept of setup() that you explained thank you.
Who are you addressing this to?

Your problems have nothing to do with setup(). Your problems have nothing to do with the button. While not the best way, your button code will work. If you follow MisterBill’s suggestion, you’ll see that your button is working.

The problem is that you’re not using the Volume3 library correctly. Look at the sample code I supplied.
 

Thread Starter

Killerbee65

Joined May 15, 2017
256
Who are you addressing this to?

Your problems have nothing to do with setup(). Your problems have nothing to do with the button. While not the best way, your button code will work. If you follow MisterBill’s suggestion, you’ll see that your button is working.

The problem is that you’re not using the Volume3 library correctly. Look at the sample code I supplied.
I am addressing it to you, you basically said what I was thinking it's just I didn't really know how to say it or rather write it.
 

Thread Starter

Killerbee65

Joined May 15, 2017
256
Also fyi, this is a code I found online. I am solely using it for the purpose of understanding it and hopefully being able to replicate it. As of right now I haven't dedicated much time to trying to understand the code due to me splitting my attention the 3 other codes anand forums but I will get around to it.
 

Deleted member 115935

Joined Dec 31, 1969
0
I assume you're referring to me? I did mention. In a few of my threads that I am only a beginner, for a comparison, I am only just learning my ABC'S while people that take their time and help me have most likely already written books (figuratively speaking). It is also hard for me to understand concepts I can't physically dissect and learn, hence why I have so many forums up. I am not looking for a cut and dry answer, I appreciate all the time these people put into helping me. To those who have stuck this far, thank you I have learned so much from you all and I am very much a better "programmer" than what I was when I started.
Hi

thats very honest of you, thank you.

How are you at Arduino ?
It is much easier to get up and going with than a lot of other languages.

Id strongly suggest that you break this problem into parts,

As your new ish to Arduino,
why not have a go at the examples on the Arduino site,
then try modifying them. As Carl Sagen said, small steps.

for instance,
take the button example, and get that to run,
then modify it. Say how about to use a different input pin for the switch ?

then how about changing the button program such that the led goes off when you press the button, not on,

show us those, and your going to be a long way towards what you want to do,

Good luck

One other thing

If you ask 10 people how to get from A to B , you will end up with quiet a few routes,
As you say you have many forums open ..
 
Top