/* * LilyPad tutorial: sound * * Uses a LilyPad speaker module to produce simple musical notes * For a chart of the frequencies of different notes see: * http://www.phy.mtu.edu/~suits/notefreqs.html */ int ledPin = 13; // LED is connected to digital pin 13 int speakerPin = 9; // speaker connected to digital pin 9 void setup() { pinMode(ledPin, OUTPUT); // sets the ledPin to be an output pinMode(speakerPin, OUTPUT); // sets the speakerPin to be an output } void loop() // run over and over again { scale(); // call the scale() function delay(1000); // delay for 1 second } void beep (unsigned char speakerPin, int frequencyInHertz, long timeInMilliseconds) // the sound producing function { int x; long delayAmount = (long)(1000000/frequencyInHertz); long loopTime = (long)((timeInMilliseconds*1000)/(delayAmount*2)); for (x=0;x