Hello i need help with my code i dont know what i did wrong but for some reason i am getting an error message. Saying a “function definition is not allowed here before ’ ’ token” this code is suppose to be for an ultrasonic parking sensor. Please can anyone help ive tried everything.
Below is the full error message and the code that i am using.
Arduino: 1.6.9 (Windows 10), Board: “Arduino/Genuino Uno”
D:\Arduino\Sketches\Ultrasonic_Sensor_Sketch\Ultrasonic_Sensor_Sketch.ino: In function ‘void setup()’:
Ultrasonic_Sensor_Sketch:25: error: a function-definition is not allowed here before ‘{’ token
void setup () {
^
Ultrasonic_Sensor_Sketch:36: error: a function-definition is not allowed here before ‘{’ token
void loop () {
^
Ultrasonic_Sensor_Sketch:82: error: expected ‘}’ at end of input
}
^
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.
int tonePin = 4; // Tone (Buzzer pin)
int trigPin = 9; // Trig (Ultrasonic pin)
int echoPin = 10; // Echo (Ultrasonic pin)
int clockPin = 11; // Clock (74HC595 IC pin)
int latchPin = 12; // Latch (74HC595 IC pin)
int dataPin = 13; // Data (74HC595 IC pin)
byte possible_patterns [9] = {
B00000000,
B00000001,
B00000011,
B00000111,
B00001111,
B00011111,
B00111111,
B01111111,
B11111111,
};
int proximity = 0;
int duration;
int distance;
void setup () {
Serial.begin (9600);
pinMode (trigPin, OUTPUT);
pinMode (echoPin, INPUT);
pinMode (clockPin, OUTPUT);
pinMode (latchPin, OUTPUT);
pinMode (dataPin, OUTPUT);
pinMode (tonePin, OUTPUT);
}
void loop () {
digitalWrite (latchPin, LOW);
digitalWrite (trigPin, HIGH);
delayMicroseconds (1000);
digitalWrite (trigPin, LOW);
duration = pulseIn (echoPin, HIGH);
distance = (duration/2)/29.1;
if (distance >= 45 || distance <= 0) {
Serial.println ("Out of range");
}
else {
Serial.print (distance);
Serial.println (" cm");
}
proximity = map (distance, 0, 45, 8, 0);
Serial.println (proximity);
if (proximity <= 0) {
proximity = 0;
}
else if (proximity >= 3 && proximity <= 4) {
tone (tonePin, 200000, 200);
}
else if (proximity >= 5 && proximity <= 6) {
tone (tonePin, 5000, 200);
}
else if (proximity >= 7 && proximity <= 8) {
tone (tonePin, 1000, 200);
}
shiftOut (dataPin, clockPin, MSBFIRST, possible_patterns [proximity]);
digitalWrite (latchPin, HIGH);
delay (600);
noTone (tonePin);
}