don't understand why you would switch. just set the frequency for each buzzer. If it's zero, it shouldn't do anything
guess you haven't looked at the code in post #11. loop() is repeatedly called. It can check if the timer has expired and do something.
You can do it only once is what I meant,
For example instead of
You could do
while (currentMillis - startMillis <= switchInterval){
currentMillis = millis();
if (chorusFrequency == 0.00){
noTone(chorusPin);
tone(mainPin, mainFrequency);
} else if (pinSwitch){
noTone(chorusPin);
tone(mainPin, mainFrequency);
} else {
noTone(mainPin);
tone(chorusPin, chorusFrequency);
}
}
And noTone() is not even necessary as it will be done automatically by the other tone() command (if it’s the built in function)
So could be as short as
while (millis() - startMillis <= switchInterval) {
if (chorusFrequency == 0) tone(mainPin, mainFrequency);
else if (pinSwitch) tone(mainPin, mainFrequency);
else tone(chorusPin, chorusFrequency);
}
But as I said I don’t know why you would call tone repeatedly
I didn't think tone() could run on multiple pins at the same time? Haven't been working with arduinos for very long, I saw the code you posted but have to look at it for a bit longer to understand what's going on. I wasn't trying to purposely ignore it, I do appreciate the help
on esp32 tone with a zero freq, logs an error and calling noTone with out a tone playing also logs an error..
would never had notice them but I was debugging the core..
added a non-blocking tone music player to nesso mazes..
~q
I see what you mean now. Not needing noTone() makes sense now, too. I thought I needed to turn it off each time before moving to the next tone(). The code looks much better, too
if it can't why not just use one pin?
That was my question here
I honestly don't have a good explanation for using two. Was desperation to try getting this to work? Will definitely switch to just using one if it's not necessary.
Seems the tone library can get your two sounds in parallel so if that’s what you need you should go for that
Yeah I'll have to play around with it later now that I know it exists lol. It'd be a lot easier than what I've been trying to do.
char s [90];
char p [20];
char q [20];
char r [20];
dtostrf (key, 8, 2, q);
dtostrf (freq, 8, 2, r);
sprintf (s, "chorusFreq: %-3s %s Hz, octave %2d, key %s",
note, r, octave, q);
Serial.println (s);
Just to make sure I'm understanding this correctly, are 's, p, q, r' just meant to store the values for 'Serial.println (s)'? Haven't used 'dtostrf' or 'sprintf' before. What's the purpose of the 8 & 2 in this part? Is it similar to 'fixed' and 'setprecision' in C++ except for input?
dtostrf (key, 8, 2, q);
dtostrf (freq, 8, 2, r);
sprintf doesn't support the "%f" specifier. dtostrf() generates a formatted string for a float/double. The 8, 2 are equivalent to "%8.2f".
dtostrf (freq, 8, 2, r); formats a float to have 8 characters and 2 decimal digits into the r char array
Assuming OP is on a small AVR indeed.
@drowsyflakes - could you confirm which Arduino you are using?
Currently using an arduino uno for this project
Apart from the need if this chieck: do not test a float with ==.
A very small rounding error may cause this to be never true....
Always test if a float is in a certain interval...
float delta =0.001;
if (-delta < myFloat and myFloat < delta) {
{
doSomething;
}
So then indeed %f is not supported.
You are welcome.
Have fun!
This is true in general and a good practice.
In this case though the value comes from the frequency calculation function where OP does
And as IEEE-754 represents the value zero exactly (the bit pattern for +0 is an exponent field full of zeros and a mantissa full of zeros. The sign bit alone distinguishes +0 from −0. In both cases the numerical value is zero without approximation) so testing == 0 in his case will work.
Very interesting!
I did not try before to examine the exact IEEE-754 binary representations of +0.0, 0.0, and −0.0. This time, being inspired by your post, I have experimented and have found the following:
for +0.0 : 0x0;
for 0.0 : 0x0
for -0.0 : 0x80000000 (MSB =1 indicates sign bit)