Fix the piezo tone function

Code translated into JS from
https://www.sparkfun.com/products/7950#comment-4eaad84d757b7fd351006efb

Code adapted from my project at NodeBots yesterday. Note that I no longer have one in front of me, so testing is difficult and ymmv. It also likely needs a bit more work as the duration isn't quite right yet.