Hi all,
I wrote a little program that plays a note on the speaker whenever it receives input, but I am having a problem. The program does not play a note, but a "clicking" sound. I based myself on the play_melody example to do this (which works perfectly), but since I don't really know what I'm doing I can't see why it doesn't work.
Both calls give a different "click", so the tone value does do something.
int speakerOut = 5;
int paddleTone = 1136;
int wallTone = 956;
int inData = 0;
void setup() {
// set the pin modes
pinMode(speakerOut, OUTPUT);
// begin sending over serial port
Serial.begin(19200);
}
void loop() {
if (Serial.available() > 0) {
// read the incoming data
inData = Serial.read();
if (inData == 60) {
// paddle collision
digitalWrite(speakerOut,HIGH);
delayMicroseconds(paddleTone);
digitalWrite(speakerOut, LOW);
delayMicroseconds(paddleTone);
} else if (inData == 62) {
// wall collision
digitalWrite(speakerOut,HIGH);
delayMicroseconds(wallTone);
digitalWrite(speakerOut, LOW);
delayMicroseconds(wallTone);
}
}
}
Thanks for the help!