I want a code a script on the raspberry pi that would read the analog values from the Sharp Distance Sensor the model is GP2Y0A21YK0F, the Sharp Distance Sensor is interface to the MCP3002 ADC chip and the Raspberry Pi, This is how the circuit is built
All the connection that I have done are the same within this image, the only difference is I just have to substitute the potentiometer for the Infrared Distance Sensor
this is what I tried to do:
import time
import botbook_mcp3002 as mcp #
def readSharpdistancesensor():
global sharpdistancesensor
sharpdistancesensor = mcp.readAnalog() #
def main():
while True: #
readSharpdistancesensor() #
print("The current sharpdistancesensor value is %i " % sharpdistancesensor) #
time.sleep( 0.5) # s
if name = = “main”:
main()
The objective for this code is to get the Sharp Distance Sensor to detect an object and return a distance value so what would be the right code for this