Good work! ![]()
I'm respect you solved that problem yourself.
I've only provided some direction and the achievement of wrote new code is yours. ![]()
I was a little worried only here.
The this topic covered of coding, and you was already able to make sounds and swing the servos, so we didn't ask about your schematics, but if you connect the speaker directly to the output pin of the Arduino, so it is a problem.
The Arduino's microcontroller ports (PINs) are not designed to drive loads (motors, speakers, solenoids, etc.) directly and can be damaged if you try to draw large currents.
It is recommended that the current flowing through the one port be 20mA or less.
This means that if the VCC (It means Arduino's power voltage) is 5V, a series resistance of 250Ω or more is required.
That way, the Arduino won't be damaged, but the sound can be quite quiet, maybe.
In that case, you should build a current amplifier circuit using transistors.