budryerson / TFMini-Plus

Arduino library for the Benewake TFMini-Plus and TFMini-S LiDAR distance sensors.
66 stars 23 forks source link

How to use TFmini plus distance reading as a threshold? #30

Closed CrowX35 closed 3 years ago

CrowX35 commented 3 years ago

Hi! I'm working on an obstacle avoidance system using TFmini plus. I want to know how do you obtain the getDistance value as an integer in order to turn on and off an LED depending upon the distance. My code doesn't seem to work.

image

budryerson commented 3 years ago

Dear Crow,

The getData() function returns a PASS/FAIL boolean value. The variable tfDist is seen by getData() as a pointer. The function uses the pointer to set the value of the variable. Your code could look more like:

tfmp.getData( tfDist)  # ignore the boolean return
val = int( tfDist)     # recast the variable as an integer

or skip a step and just send val:

uint16_t val
tfmp.getData( val)

Please let me know whether that helps or not.

Bud Ryerson San Francisco

CrowX35 commented 3 years ago

It works. Thank you so much!