Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- # //////////////////////////////////////
- # // ultrasonicRange.py
- # // Reads the analog value of the sensor.
- # //////////////////////////////////////
- from time import sleep
- import math
- foot = 12
- inch = (1 / 12)
- mm = (inch * 25.4)
- ms = 550.0 # Time in milliseconds
- pin = "0" # sensor, A0, P9_39
- IIOPATH='/sys/bus/iio/devices/iio:device0/in_voltage'+pin+'_raw'
- f = open(IIOPATH, "r")
- ADC = (1.8 / 512) / inch
- ADC_mm = (1.8 / 512) / mm
- try:
- print("We are waiting five seconds and then starting")
- sleep(5)
- ADC = str(input("Please type ADC, Thank you!"))
- while True:
- if ADC:
- f.seek(1)
- ADC = f.read()[:-1]
- print('data = ' + ADC)
- sleep(ms / 1500)
- f.seek(1)
- ADC_mm = f.read()[:-1]
- print('data = ' + ADC_mm)
- sleep(ms / 1500)
- except KeyboardInterrupt:
- pass
- print("The end...")
- # // BBB | Pocket | AIN
- # // ----- | ------ | ---
- # // P9_39 | P1_19 | 0
- # // P9_40 | P1_21 | 1
- # // P9_37 | P1_23 | 2
- # // P9_38 | P1_25 | 3
- # // P9_33 | P1_27 | 4
- # // P9_36 | P2_35 | 5
- # // P9_35 | P1_02 | 6
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement