I am currently trying to combine a mazerunner code with a super mario brothers code and am running into a bit of problems. My most recent error message is:
Arduino: 1.8.10 (Mac OS X), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"
/Users/brandonbruetsch/Documents/Arduino/arduino/arduino.ino: In function 'void setup()':
arduino:307:1: error: a function-definition is not allowed here before '{' token
{
^
arduino:315:18: error: a function-definition is not allowed here before '{' token
void sing(int s) {
^
arduino:365:55: error: a function-definition is not allowed here before '{' token
void buzz(int targetPin, long frequency, long length) {
^
Multiple libraries were found for "Wire.h"
Used: /private/var/folders/92/25d5dpdx3_93pj_vn5g_x3m40000gn/T/AppTranslocation/FA4D8BC0-D5A5-4256-885E-C4B40D934A2C/d/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/Wire
Multiple libraries were found for "Adafruit_GFX.h"
Used: /Users/brandonbruetsch/Documents/Arduino/libraries/Adafruit-GFX-Library
Multiple libraries were found for "Adafruit_SSD1306.h"
Used: /Users/brandonbruetsch/Documents/Arduino/libraries/Adafruit_SSD1306
Multiple libraries were found for "SPI.h"
Used: /private/var/folders/92/25d5dpdx3_93pj_vn5g_x3m40000gn/T/AppTranslocation/FA4D8BC0-D5A5-4256-885E-C4B40D934A2C/d/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI
exit status 1
a function-definition is not allowed here before '{' token
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
My Code is here:
Serial.println(" 'Mario Theme'");
int size = sizeof(melody) / sizeof(int);
for (int thisNote = 0; thisNote < size; thisNote++) {
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000 / tempo[thisNote];
buzz(melodyPin, melody[thisNote], noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
buzz(melodyPin, 0, noteDuration);
}
}
}
void buzz(int targetPin, long frequency, long length) {
digitalWrite(13, HIGH);
long delayValue = 1000000 / frequency / 2; // calculate the delay value between transitions
//// 1 second's worth of microseconds, divided by the frequency, then split in half since
//// there are two phases to each cycle
long numCycles = frequency * length / 1000; // calculate the number of cycles for proper timing
//// multiply frequency, which is really cycles per second, by the number of seconds to
//// get the total number of cycles to produce
for (long i = 0; i < numCycles; i++) { // for the calculated length of time...
digitalWrite(targetPin, HIGH); // write the buzzer pin high to push out the diaphram
delayMicroseconds(delayValue); // wait for the calculated delay value
digitalWrite(targetPin, LOW); // write the buzzer pin low to pull back the diaphram
delayMicroseconds(delayValue); // wait again or the calculated delay value
}
digitalWrite(13, LOW);
}