2020-02-26 10:47:21 -07:00
|
|
|
import time
|
|
|
|
import numpy as np
|
2020-03-02 11:39:07 -07:00
|
|
|
|
|
|
|
import board
|
2020-03-02 13:40:42 -07:00
|
|
|
import busio
|
2020-03-02 11:39:07 -07:00
|
|
|
import digitalio
|
2020-02-26 10:47:21 -07:00
|
|
|
from adafruit_servokit import ServoKit
|
2020-03-02 13:39:37 -07:00
|
|
|
import adafruit_ads1x15.ads1015 as ADS
|
2020-03-02 11:39:07 -07:00
|
|
|
from adafruit_ads1x15.analog_in import AnalogIn
|
2020-02-26 10:47:21 -07:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2020-03-02 11:39:07 -07:00
|
|
|
mux = np.empty(4)
|
|
|
|
mux[0] = digitalio.DigitalInOut(board.D17).value
|
|
|
|
mux[1] = digitalio.DigitalInOut(board.D27).value
|
|
|
|
mux[2] = digitalio.DigitalInOut(board.D22).value
|
|
|
|
mux[3] = digitalio.DigitalInOut(board.D23).value
|
|
|
|
|
2020-03-02 13:40:42 -07:00
|
|
|
i2c = busio.I2C(board.SCL, board.SDA)
|
|
|
|
adc = ADS.ADS1015(i2c)
|
2020-03-02 11:39:07 -07:00
|
|
|
adc_mux = AnalogIn(adc, ADS.P0)
|
|
|
|
|
|
|
|
def get_reflectivity(chan):
|
|
|
|
chan = int(chan)
|
|
|
|
global mux
|
2020-03-02 11:43:30 -07:00
|
|
|
global adc_mux
|
2020-03-02 11:39:07 -07:00
|
|
|
mux = np.array(list(f"{chan:04b}"), dtype=int)
|
2020-03-02 11:43:30 -07:00
|
|
|
return adc_mux.voltage
|
2020-03-02 11:39:07 -07:00
|
|
|
|
|
|
|
while True:
|
|
|
|
for ii in range(8):
|
|
|
|
print(get_reflectivity(ii), end="")
|
|
|
|
print()
|
|
|
|
|
|
|
|
# servos = ServoKit(channels=16).continuous_servo
|
|
|
|
# servos[0].throttle = 0
|
|
|
|
# servos[1].throttle = 0
|
|
|
|
# servos[2].throttle = 0
|
|
|
|
# time.sleep(1)
|
|
|
|
# servos[0].throttle = 20
|
|
|
|
# servos[1].throttle = 20
|
|
|
|
# servos[2].throttle = 20
|
|
|
|
# time.sleep(1)
|
|
|
|
# servos[0].throttle = 0
|
|
|
|
# servos[1].throttle = 0
|
|
|
|
# servos[2].throttle = 0
|
2020-02-26 10:47:21 -07:00
|
|
|
|