mirror of
https://github.com/brendanhaines/ECEN5458_Project.git
synced 2024-12-26 10:57:55 -07:00
WIP: add debugging stuff to hwtest.py
This commit is contained in:
parent
249bc5c4e1
commit
2ad585c0fb
|
@ -20,15 +20,21 @@ if __name__ == "__main__":
|
|||
mux_io[2] = digitalio.DigitalInOut(board.D22)
|
||||
mux_io[3] = digitalio.DigitalInOut(board.D23)
|
||||
|
||||
print("a")
|
||||
|
||||
for ii, io in enumerate(mux_io):
|
||||
io.switch_to_output()
|
||||
|
||||
print("b")
|
||||
|
||||
i2c = busio.I2C(board.SCL, board.SDA)
|
||||
adc = ADS.ADS1015(i2c)
|
||||
adc_mux = AnalogIn(adc, ADS.P0)
|
||||
white_cal = [0]*8
|
||||
black_cal = [5]*8
|
||||
|
||||
print("c")
|
||||
|
||||
def get_reflectivity(chan):
|
||||
chan = int(chan)
|
||||
global mux_io
|
||||
|
@ -38,48 +44,82 @@ if __name__ == "__main__":
|
|||
io.value = mux[ii]
|
||||
return adc_mux.voltage
|
||||
|
||||
print("d")
|
||||
|
||||
def get_normalized_reflectivity(chan):
|
||||
global white_cal
|
||||
global black_cal
|
||||
|
||||
return (get_reflectivity(chan) - black_cal[chan]) / (white_cal[chan] - black_cal[chan])
|
||||
|
||||
print("e")
|
||||
|
||||
brightness_idx = np.arange(8)
|
||||
brightness = [get_normalized_reflectivity(c) for c in range(8)]
|
||||
|
||||
print("f")
|
||||
|
||||
plt_source = ColumnDataSource(data=dict(x=brightness_idx, y=brightness))
|
||||
|
||||
print("g")
|
||||
|
||||
# Set up plot
|
||||
plot = figure(plot_height=400, plot_width=400, title="my sine wave",
|
||||
tools="save",
|
||||
x_range=[0, 7], y_range=[0, 5])
|
||||
|
||||
print("h")
|
||||
|
||||
plot.line('x', 'y', source=plt_source, line_width=3, line_alpha=0.6)
|
||||
|
||||
print("i")
|
||||
|
||||
def update_data(*args, **kwargs):
|
||||
brightness = [get_normalized_reflectivity(c) for c in range(8)]
|
||||
plt_source.data = dict(x=brightness_idx, y=brightness)
|
||||
|
||||
print("j")
|
||||
|
||||
def cal_white(*args, **kwargs):
|
||||
global white_cal
|
||||
white_cal = [get_reflectivity(c) for c in range(8)]
|
||||
update_data()
|
||||
|
||||
print("k")
|
||||
|
||||
def cal_black(*args, **kwargs):
|
||||
global black_cal
|
||||
black_cal = [get_reflectivity(c) for c in range(8)]
|
||||
update_data()
|
||||
|
||||
print("l")
|
||||
|
||||
cal_white_button = Button(label="Cal White")
|
||||
|
||||
print("m")
|
||||
|
||||
cal_white_button.on_click(cal_white)
|
||||
|
||||
print("n")
|
||||
|
||||
cal_black_button = Button(label="Cal Black")
|
||||
cal_black_button.on_click(cal_black)
|
||||
|
||||
print("o")
|
||||
|
||||
controls = column(cal_white_button, cal_black_button)
|
||||
|
||||
print("p")
|
||||
|
||||
curdoc().add_root(row(controls, plot, width=800))
|
||||
|
||||
print("r")
|
||||
|
||||
curdoc().title = "test"
|
||||
|
||||
print("s")
|
||||
|
||||
|
||||
# while True:
|
||||
# time.sleep(0.1)
|
||||
# update_data()
|
||||
|
|
Loading…
Reference in New Issue
Block a user