When I try typing in my code, I get an error. Here it is:
exit status 1
variable or field 'setup' declared void
When I try typing in my code, I get an error. Here it is:
exit status 1
variable or field 'setup' declared void
Do you think it might help if we could see your code ?
Please follow the advice given in the link below when posting code . Use code tags when posting code here to make it easier to read and copy for examination
Sure, Here is my code:
const int buzzPin = 11;
const int trigPin = 9;
const int echoPin = 10;
long duration;
int distance;
void setup {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
pinMode(buzzPin, OUPUT);
}
void loop() {
// Setting up the Distance Sensor:
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration*0.034/2;
Serial.print("Distance: ");
Serial.println(distance);
//Buzzer sound making
do {
tone(buzzPin, distance, 1);
}
while(1);
}
Why do users choose to ignore the advice on posting code ?
The easier you make it to read and copy your code the more likely it is that you will get help
Please follow the advice given in the link I posted
This is my setup:
void setup {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
pinMode(buzzPin, OUPUT);
}
This is the error message:
Arduino: 1.8.15 (Windows Store 1.8.49.0) (Windows 10), Board: "Arduino Uno"
distanceMusic:8:6: error: variable or field 'setup' declared void
void setup {
^~~~~
distanceMusic:9:27: error: expected '}' before ';' token
pinMode(trigPin, OUTPUT);
^
distanceMusic:10:10: error: expected constructor, destructor, or type conversion before '(' token
pinMode(echoPin, INPUT);
^
distanceMusic:11:3: error: 'Serial' does not name a type
Serial.begin(9600);
^~~~~~
distanceMusic:12:10: error: expected constructor, destructor, or type conversion before '(' token
pinMode(buzzPin, OUPUT);
^
distanceMusic:13:1: error: expected declaration before '}' token
}
^
exit status 1
variable or field 'setup' declared void
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
You need parenthesis after setup in order to make it a function definition instead of a variable definition:
void setup() {
You're already using the correct syntax for loop()...
@gablos are you deliberately ignoring the advice to use code tags when posting code and error messages ?
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.