I am trying to run this code:
int pingPin = 7;
int speakerPin = 9;
int length = 100; // the number of notes
char notes[] = "CgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCgCg"; // a space represents a rest
int beats[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,};
int tempo = 300;
void playTone(int tone, int duration) {
for (long i = 0; i < duration * 1000L; i += tone * 2) {
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tone);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tone);
}
}
void playNote(char note, int duration) {
char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };
// play the tone corresponding to the note name
for (int i = 0; i < 8; i++) {
if (names == note) {
_ playTone(tones*, duration);_
_ }_
_ }_
_}_
void setup(){
_ pinMode(speakerPin, OUTPUT);_
_}_
void loop()
_{_
_ long duration, inches, i;_
_ // The PING))) is triggered by a HIGH pulse of 2 or more microseconds._
_ // We give a short LOW pulse beforehand to ensure a clean HIGH pulse._
_ pinMode(pingPin, OUTPUT);_
_ digitalWrite(pingPin, LOW);_
_ delayMicroseconds(2);_
_ digitalWrite(pingPin, HIGH);_
_ delayMicroseconds(5);_
_ digitalWrite(pingPin, LOW);_
_ // The same pin is used to read the signal from the PING))): a HIGH*_
* // pulse whose duration is the time (in microseconds) from the sending*
* // of the ping to the reception of its echo off of an object.*
* pinMode(pingPin, INPUT);*
* duration = pulseIn(pingPin, HIGH);*
* // convert the time into a distance*
* inches = microsecondsToInches(duration);*
* if (inches <= 10) i == 1*
* ;for (int i; i < length; i) {*
_ if (notes == ' ') {
delay(beats * tempo); // rest
* } else {_
playNote(notes, beats _ tempo);
* }*_
* // pause between notes*
* delay(tempo / 10);*
}
long microsecondsToInches (long microseconds)
{
* // According to Parallax's datasheet for the PING))), there are*
* // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per*
* // second). This gives the distance travelled by the ping, outbound*
* // and return, so we divide by 2 to get the distance of the obstacle. // See:http://www.parallax.com/dl/docs/prod/acc/2801 PINGv1.3.pdf*
* return microseconds / 74 / 2;*
* }*
and this error:
In function 'void loop()':
error: a function-definition is not allowed here before '{' token
comes up.
Can someone please tell me why?