i have this problem of
Exit status 1
'PinMode' cannot be used as a function
This is the code
int TrigPin = 9;
int EchoPin = 8;
int buzzerpin = 7;
int PinMode = 6;
long duration;
float Duration;
void setup()
{
PinMode()(TrigPin, OUTPUT);
PinMode()(EchoPin, INPUT);
PinMode()(buzzerPin, OUTPUT);
}
void loop()
{
digitalWrite(TrigPin, LOW);
delayMicroseconds(2);
digitalWrite(TrigPin, HIGH);
delayMicroseconds(10);
digitalWrite(TrigPin, LOW);
duration = pulsein(EchoPin,HIGH);
distance = 0.034*(duration/2);
if ((distance < 100) && (distance >9))
{
digitalWrite(buzzerPin,HIGH);
delay(100)
digitalWrite(buzzerPin,LOW
delay(distance*5);
}
else
if (distance <10)
{
digitalWrite(BuzzerPin,HIGH);
}
else
{
digitalWrite(buzzerPin,LOW
}
}
Please help me
PinMode()(TrigPin, OUTPUT);
Should be
PinMode(TrigPin, OUTPUT);
EDIT :
Whoops !
That will teach me to look closer
See later replies
You've got an int variable called PinMode. When you put PinMode() with the brackets after, it thinks you're trying to use it as a function. You can't do that.
Also, there's a built-in Arduino function called pinMode() - it doesn't have a capital P but it's probably confusing you even more than you are already.
ok i changed that PinMode
To this but it still has that same problem
int TrigPin = 9;
int EchoPin = 8;
int buzzerpin = 7;
int PinMode = 6;
long duration;
float Duration;
void setup()
{
PinMode(TrigPin, OUTPUT);
PinMode(EchoPin, INPUT);
PinMode(buzzerPin, OUTPUT);
}
void loop()
{
digitalWrite(TrigPin, LOW);
delayMicroseconds(2);
digitalWrite(TrigPin, HIGH);
delayMicroseconds(10);
digitalWrite(TrigPin, LOW);
duration = pulsein(EchoPin,HIGH);
distance = 0.034*(duration/2);
if ((distance < 100) && (distance >9))
{
digitalWrite(buzzerPin,HIGH);
delay(100)
digitalWrite(buzzerPin,LOW
delay(distance*5);
}
else
if (distance <10)
{
digitalWrite(BuzzerPin,HIGH);
}
else
{
digitalWrite(buzzerPin,LOW
}
}
I don't see that you use that variable anywhere.
If it's supposed to be an input pin, I suggest that you are consistent in your naming. The other pins are named xxxPin, so call this also something like that.
To set the mode of a pin, use pinMode, not PinMode.
Also, that black error area is a scrollable window. There's much more information above the couple of lines you can see:
/Users/arduinouser/Documents/Arduino/test/test.ino: In function 'void setup()':
test:10:26: error: 'PinMode' cannot be used as a function
PinMode(TrigPin, OUTPUT);
^
test:11:25: error: 'PinMode' cannot be used as a function
PinMode(EchoPin, INPUT);
^
test:12:11: error: 'buzzerPin' was not declared in this scope
PinMode(buzzerPin, OUTPUT);
^~~~~~~~~
/Users/arduinouser/Documents/Arduino/test/test.ino:12:11: note: suggested alternative: 'buzzerpin'
PinMode(buzzerPin, OUTPUT);
^~~~~~~~~
buzzerpin
test:12:28: error: 'PinMode' cannot be used as a function
PinMode(buzzerPin, OUTPUT);
^
/Users/arduinouser/Documents/Arduino/test/test.ino: In function 'void loop()':
test:22:14: error: 'pulsein' was not declared in this scope
duration = pulsein(EchoPin,HIGH);
^~~~~~~
/Users/arduinouser/Documents/Arduino/test/test.ino:22:14: note: suggested alternative: 'pulseIn'
duration = pulsein(EchoPin,HIGH);
^~~~~~~
pulseIn
test:23:3: error: 'distance' was not declared in this scope
distance = 0.034*(duration/2);
^~~~~~~~
/Users/arduinouser/Documents/Arduino/test/test.ino:23:3: note: suggested alternative: 'isSpace'
distance = 0.034*(duration/2);
^~~~~~~~
isSpace
test:28:16: error: 'buzzerPin' was not declared in this scope
digitalWrite(buzzerPin,HIGH);
^~~~~~~~~
/Users/arduinouser/Documents/Arduino/test/test.ino:28:16: note: suggested alternative: 'buzzerpin'
digitalWrite(buzzerPin,HIGH);
^~~~~~~~~
buzzerpin
test:30:3: error: expected ';' before 'digitalWrite'
digitalWrite(buzzerPin,LOW
^~~~~~~~~~~~
test:36:16: error: 'BuzzerPin' was not declared in this scope
digitalWrite(BuzzerPin,HIGH);
^~~~~~~~~
/Users/arduinouser/Documents/Arduino/test/test.ino:36:16: note: suggested alternative: 'buzzerpin'
digitalWrite(BuzzerPin,HIGH);
^~~~~~~~~
buzzerpin
test:40:16: error: 'buzzerPin' was not declared in this scope
digitalWrite(buzzerPin,LOW
^~~~~~~~~
/Users/arduinouser/Documents/Arduino/test/test.ino:40:16: note: suggested alternative: 'buzzerpin'
digitalWrite(buzzerPin,LOW
^~~~~~~~~
buzzerpin
test:41:3: error: expected ')' before '}' token
}
^
exit status 1
'PinMode' cannot be used as a function
OK, I've got a bit more time to discuss this now:
This might seem like a lot of errors but most of them are basically the same: you need to pay attention to the fact that C / C++ is case sensitive.
Capital letters matter.
If you declare something as buzzerpin, you can't later refer to it as BuzzerPin or buzzerPin. The case is just as important as the spelling and has to match exactly.
You've made the same mistake with a lot of your variable and function names.