You need to assign a value to the variable distance in loop instead of just printing it.
the variable cm and is declared in readPing() and is out of scope in loop(). Declare cm global.
You need to assign a value to the variable distance in loop instead of just printing it.
the variable cm and is declared in readPing() and is out of scope in loop(). Declare cm global.