PROS Ultrasonic sensor

I have an ultrasonic sensor that I haven’t touched for a couple years and when I use the following code to get the sensor readings the value won’t change its reads a long number that doesn’t change.

adi_ultrasonic_t ult = adi_ultrasonic_init(PORT_PING, PORT_ECHO);
int dist = (int)(adi_ultrasonic_get(ult));

I get the following error:
Compiled src/main.c [ERRORS]
src/main.c: In function ‘delayultra’:
src/main.c:891:38: error: ‘ultrasonic’ undeclared (first use in this function)
int dist = (int)(adi_ultrasonic_get(ultrasonic));
src/main.c:891:38: note: each undeclared identifier is reported only once for each function it appears in
src/main.c: In function ‘opcontrol’:
src/main.c:1482:39: error: ‘ultrasonic’ undeclared (first use in this function)
int dist = (int)(adi_ultrasonic_get(ultrasonic));
make: *** [bin/main.c.o] Error 1
Capturing metadata for PROS Editor…
Error: Failed to build

You need an init call (eg I recommend using the c++ api though as the c one is buggy rn (

1 Like

I currently do have my init call in my initialize

The problem is you called the thing you get back from adi_ultrasonic_init ult and not ultrasonic

1 Like