Code Issue

I'm a beginner working on a project where I'd like to make a push button link to a servo (make it sweep when pushed) and a background melody with a piezo. I've gotten the two parts to work separately but when put together, only the melody works. When I take the 'sing' command out of the loop, the push button/servo work fine but when I put them in theres an issue... any ideas on what I'm doing wrong? any help would be greatly appreciated!

Thanks :slight_smile:

void loop()
{
press1 = digitalRead(buttonPin); // check state of button, if pressed servo should move (while holding down)
if (press1 == LOW)
{
myservo.write(160);
}
else {
myservo.write(20);
}
sing(1); // sing songs (melodies)
sing(1);
sing(2);

}

Please post complete code (what is sing?); if sing is a library, please provide a link.

Please properly indent your code (use menu tools->auto format in the IDE) before copying code.

And please use code tags:
type
** **[code]** **

paste your code after that
type
** **[code]** **
after the pasted code