int readUltrasonicDistance (int triggerPin, int echoPin)
why does the "int triggerPin, int echoPin"
is in the () and not in diffrent line like this:
int readUltrasonicDistance
int triggerPin
int echoPin
if someone can help me here thx alot!
int readUltrasonicDistance (int triggerPin, int echoPin)
why does the "int triggerPin, int echoPin"
is in the () and not in diffrent line like this:
int readUltrasonicDistance
int triggerPin
int echoPin
if someone can help me here thx alot!
It declares variables in a way that assigns them for a different purpose in each case. To know why, you need to study some C.
Needs more context, but it looks like it might be a function declaration, saying that the readUltrasonicDistance function has the two inputs with those other names for the next block of code.
I agree, you are not following the forum guidelines for asking a question. In particular, snippets of code are rarely useful because they truncate valuable context.
int ultra = 0;
int readUltrasonicDistance (int triggerPin, int echoPin)
{
pinMode(triggerPin, OUTPUT);
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
return pulseIn(echoPin, HIGH);
}
void setup()
{
Serial.begin(9600);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
}
void loop()
{
ultra = 0.006783 * readUltrasonicDistance(13, 13);
Serial.print(ultra);
if (ultra >= 80) {
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
Serial.println(" : Safe");
}
if (ultra > 35 && ultra < 80) {
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
Serial.println(" : Beware");
}
if (ultra <= 35) {
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
Serial.println(" : Dangerous");
}
delay(10);
}
here is the code
@anon57585045 @DaveX
Thank you. Google "C++ local variables".
Thanks. @anon57585045 and I guessed correctly.
Look up how C++ functions work.
alr tysm for helping ! @anon57585045 @DaveX
The reason why we don't want to answer here, it's because it's like writing the same textbook that has been written and refined 1000x. You will get a better answer there, and a good answer wouldn't fit here due to space limitations.
No idea what a "alr tysm" is...
alr = alright , tysm = thank you so much
Did you mean "alr == alright , tysm == thank you so much"?
And one output?
You'll find your list of helpers gets shorter and shorter, the more you continue with this gibberish.
Members have the ability to set you to "ignore", and will never see your posts.
It's a free world, up to you.
Welcome to Y2K. : ) Pager code is out. 143. SMS is in.
This will take (receive) two arguments (inputs)
(triggerPin, echoPin)
into the function readUltrasonicDistance
, and as we all learned in maths, a function can receive multiple inputs, but only one real output. The output of readUltrasonicDistance
is the int
:
return pulseIn(echoPin, HIGH);
It could be more if the function returns a structure.
Yes. To the detriment of the centuries-defined "y=f(x)"
A function still returns just one structure, array, object or whatever.
And the OP was asking about the inputs.
I would be the "xy problem."
Redeemed!