I am having issues with a script I modified. I’m getting an ”
Ping_Library_Example:9: error: expected unqualified-id before ‘if'”
I’m sure I have some little syntax error somewhere, any ideas what?
The orrigional script, by the way, has “void loop” instead of “if”. This same probably also occurs when using when, with the same error. Any ideas?
#include <Ping.h>
Ping ping = Ping(13,74,29);
void setup(){
Serial.begin(115200);
}
if(digitalRead == HIGH){
ping.fire();
Serial.print("Microseconds: ");
Serial.print(ping.microseconds());
Serial.print(" | Inches ");
Serial.print(ping.inches());
Serial.print(" | Centimeters: ");
Serial.print(ping.centimeters());
Serial.println();
}
Arduino programs need a
loop()function to run; simply replacing the function with anifcondition doesn’t work. Try putting theifblock inside aloop()function.Additionally,
digitalReadis a function, and you need to tell it what pin to read from. e.g.,digitalRead(5)to read from pin 5.Try something like this:
(change 5 to whatever pin you want to read from, or assign that value to a variable and pass that in)