import board
import digitalio
import time
import neopixel
import adafruit_as7341
import busio
import storage
import math
from adafruit_debouncer import Debouncer
#sensor
i2c = busio.I2C(board.GP27, board.GP26)
sensor = adafruit_as7341.AS7341(i2c)
sensor.gain = adafruit_as7341.Gain.GAIN_0_5X
# def bar_graph(read_value):
# scaled = int(read_value / 1000)
# return f"[{read_value:5d}] " + (scaled * "*")
switch_pin = digitalio.DigitalInOut(board.GP16)
switch_pin.direction = digitalio.Direction.INPUT
switch_pin.pull = digitalio.Pull.UP
switch = Debouncer(switch_pin)
run_pin = digitalio.DigitalInOut(board.GP17)
run_pin.direction = digitalio.Direction.INPUT
run_pin.pull = digitalio.Pull.UP
run = Debouncer(run_pin)
led = digitalio.DigitalInOut(board.GP5)
led.direction = digitalio.Direction.OUTPUT
pico_led = digitalio.DigitalInOut(board.LED)
pico_led.direction = digitalio.Direction.OUTPUT
pixel_pin = board.GP15
pixels = neopixel.NeoPixel(board.GP15, 1)
fluor_pixel_pin = board.GP14
fluor_pixels = neopixel.NeoPixel(board.GP14, 1)
"""
comment
"""
#mode = 1,2,3,4 (blank, measure, blank fluorescence, measure fluor)
mode = 1
blank_list = []
export_blank_list = []
raw_measure_list = []
export_measure_list = []
blanked_measure_list = []
export_blanked_measure_list = []
blank_fluor_list = []
export_blank_fluor_list = []
raw_measure_fluor_list = []
export_measure_fluor_list = []
blanked_measure_fluor_list = []
export_blanked_measure_fluor_list = []
rgbw_colour = [(255,0,0),(0,255,0),(0,0,255),(255,255,255),(0,0,0)]
# this is a test for color change or something idk the rbg led only has 3 wavelength ranges anyways? so idk
def rainbowtest():
rainbow = [
(126 , 1 , 0),(114 , 13 , 0),(102 , 25 , 0),(90 , 37 , 0),(78 , 49 , 0),(66 , 61 , 0),(54 , 73 , 0),(42 , 85 , 0),
(30 , 97 , 0),(18 , 109 , 0),(6 , 121 , 0),(0 , 122 , 5),(0 , 110 , 17),(0 , 98 , 29),(0 , 86 , 41),(0 , 74 , 53),
(0 , 62 , 65),(0 , 50 , 77),(0 , 38 , 89),(0 , 26 , 101),(0 , 14 , 113),(0 , 2 , 125),(9 , 0 , 118),(21 , 0 , 106),
(33 , 0 , 94),(45 , 0 , 82),(57 , 0 , 70),(69 , 0 , 58),(81 , 0 , 46),(93 , 0 , 34),(105 , 0 , 22),(117 , 0 , 10)]
while True:
rainbow = rainbow[-1:] + rainbow[:-1]
pixels.fill(rainbow[1])
time.sleep(0.1)
def absorption(blank, sensor):
n = 0
absorbance_list = []
while n < len(blank):
blankvalue = blank[n]
sensorvalue = sensor[n]
if sensorvalue == 0:
sensorvalue = 0.01
if blankvalue == 0:
blankvalue = 0.01
if blankvalue > sensorvalue:
absorbance = -math.log10(sensorvalue/blankvalue)
else:
absorbance = 0
absorbance_list.append(absorbance)
n += 1
return absorbance_list
def sensoring():
index = 0
for color in rgbw_colour:
ch415 = sensor.channel_415nm
ch445 = sensor.channel_445nm
ch480 = sensor.channel_480nm
ch515 = sensor.channel_515nm
ch555 = sensor.channel_555nm
ch590 = sensor.channel_590nm
ch630 = sensor.channel_630nm
ch680 = sensor.channel_680nm
chclr = sensor.channel_clear
chnir = sensor.channel_nir
sensor_list = [ch415,ch445, ch480, ch515, ch555, ch590, ch630, ch680, chclr, chnir]
# print(f"F1 - 415nm/Violet {bar_graph(ch415)}")
# print(f"F2 - 445nm//Indigo {bar_graph(ch445)}")
# print(f"F3 - 480nm//Blue {bar_graph(ch480)}")
# print(f"F4 - 515nm//Cyan {bar_graph(ch515)}")
# print(f"F5 - 555nm/Green {bar_graph(ch555)}")
# print(f"F6 - 590nm/Yellow {bar_graph(ch590)}")
# print(f"F7 - 630nm/Orange {bar_graph(ch630)}")
# print(f"F8 - 680nm/Red {bar_graph(ch680)}")
# print(f"Clear {bar_graph(chclr)}")
# print(f"Near-IR (NIR) {bar_graph(chnir)}")
# print("\n------------------------------------------------")
print(f"sensoring")
if mode == 1:
pixels.fill(color)
blank_list.append((color, ch415, ch445, ch480, ch515, ch555, ch590, ch630, ch680, chclr, chnir))
export_blank_list.append(f"{color}, {ch415}, {ch445}, {ch480}, {ch515}, {ch555}, {ch590}, {ch630}, {ch680}, {chclr}, {chnir}")
print(f"{color}, {ch415}, {ch445}, {ch480}, {ch515}, {ch555}, {ch590}, {ch630}, {ch680}, {chclr}, {chnir}")
if mode == 2:
pixels.fill(color)
raw_measure_list.append((color, ch415, ch445, ch480, ch515, ch555, ch590, ch630, ch680, chclr, chnir))
export_measure_list.append(f"{color}, {ch415}, {ch445}, {ch480}, {ch515}, {ch555}, {ch590}, {ch630}, {ch680}, {chclr}, {chnir}")
# print(f"{color}, {ch415}, {ch445}, {ch480}, {ch515}, {ch555}, {ch590}, {ch630}, {ch680}, {chclr}, {chnir}")
blanked_measure_list.append((color, ch415-blank_list[color][1], ch445-blank_list[color][2], ch480-blank_list[color][3], ch515-blank_list[color][4], ch555-blank_list[color][5], ch590-blank_list[color][6], ch630-blank_list[color][7], ch680-blank_list[color][8], chclr-blank_list[color][9], chnir-blank_list[color][10]))
export_blanked_measure_list.append(f"{color}, {ch415-blank_list[color][1]}, {ch445-blank_list[color][2]}, {ch480-blank_list[color][3]}, {ch515-blank_list[color][4]}, {ch555-blank_list[color][5]}, {ch590-blank_list[color][6]}, {ch630-blank_list[color][7]}, {ch680-blank_list[color][8]}, {chclr-blank_list[color][9]}, {chnir-blank_list[color][10]}")
print((f"{color}, {",".join(str(x) for x in absorption(blank_list[index][:1], sensor_list))}"))
if mode == 3:
fluor_pixels.fill(color)
# blank_fluor_list.append((color, ch415, ch445, ch480, ch515, ch555, ch590, ch630, ch680, chclr, chnir))
# export_blank_fluor_list.append(f"{color}, {ch415}, {ch445}, {ch480}, {ch515}, {ch555}, {ch590}, {ch630}, {ch680}, {chclr}, {chnir}")
print(f"{color}, {ch415}, {ch445}, {ch480}, {ch515}, {ch555}, {ch590}, {ch630}, {ch680}, {chclr}, {chnir}")
if mode == 4:
fluor_pixels.fill(color)
raw_measure_fluor_list.append((color, ch415, ch445, ch480, ch515, ch555, ch590, ch630, ch680, chclr, chnir))
export_measure_fluor_list.append(f"{color}, {ch415}, {ch445}, {ch480}, {ch515}, {ch555}, {ch590}, {ch630}, {ch680}, {chclr}, {chnir}")
# print(f"{color}, {ch415}, {ch445}, {ch480}, {ch515}, {ch555}, {ch590}, {ch630}, {ch680}, {chclr}, {chnir}")
# blanked_measure_fluor_list.append((color, ch415-blank_fluor_list[color][1], ch445-blank_fluor_list[color][2], ch480-blank_fluor_list[color][3], ch515-blank_fluor_list[color][4], ch555-blank_fluor_list[color][5], ch590-blank_fluor_list[color][6], ch630-blank_fluor_list[color][7], ch680-blank_fluor_list[color][8], chclr-blank_fluor_list[color][9], chnir-blank_fluor_list[color][10]))
# export_blanked_measure_fluor_list.append(f"{color}, {ch415-blank_fluor_list[color][1]}, {ch445-blank_fluor_list[color][2]}, {ch480-blank_fluor_list[color][3]}, {ch515-blank_fluor_list[color][4]}, {ch555-blank_fluor_list[color][5]}, {ch590-blank_fluor_list[color][6]}, {ch630-blank_fluor_list[color][7]}, {ch680-blank_fluor_list[color][8]}, {chclr-blank_fluor_list[color][9]}, {chnir-blank_fluor_list[color][10]}")
# print(f"{color}, {ch415-blank_fluor_list[color][1]}, {ch445-blank_fluor_list[color][2]}, {ch480-blank_fluor_list[color][3]}, {ch515-blank_fluor_list[color][4]}, {ch555-blank_fluor_list[color][5]}, {ch590-blank_fluor_list[color][6]}, {ch630-blank_fluor_list[color][7]}, {ch680-blank_fluor_list[color][8]}, {chclr-blank_fluor_list[color][9]}, {chnir-blank_fluor_list[color][10]}")
print((f"{color}, {",".join(str(x) for x in absorption(blank_fluor_list[index][:1], sensor_list))}"))
index += 1
time.sleep(0.1)
print(", ".join(export_blank_list))
def scanner( ):
# pixels.fill((0,0,0))
# fluor_pixels.fill((0,0,0))
if mode == 1 or mode == 2:
# blank and measure
# print("a")
# pixels.fill(((mode) * (255/4), 255, 255))
print(f"mode = {mode}")
if mode == 3 or mode == 4:
# fluor blank and measure
# print("b")
# fluor_pixels.fill(((mode) * (255/4), 255, 255))
print(f"mode = {mode}")
# rainbowtest()
sensoring()
# while True:
# # print("On!")
# led.value = True
# pico_led.value = True
# time.sleep(0.5)
# # print("Off!")
# led.value = False
# pico_led.value = False
# time.sleep(0.5)
cycle = 1
while True:
switch.update()
run.update()
if switch.fell:
pico_led.value = True
print('switch Just pressed')
if mode >= 4:
mode = 1
else:
mode += 1
if mode == 4:
pixels.fill((0,0,0))
fluor_pixels.fill((0,100,0))
if mode == 3:
pixels.fill((0,0,0))
fluor_pixels.fill((0,100,100))
if mode == 2:
pixels.fill((100,100,100))
fluor_pixels.fill((0,0,0))
if mode == 1:
pixels.fill((100,100,200))
fluor_pixels.fill((0,0,0))
print(mode)
if run.fell:
print('run Just pressed')
scanner()
if switch.rose:
# print('Just released')
pico_led.value = False
pixels.fill((0,0,0))
fluor_pixels.fill((0,0,0))
# if switch.value:
# # print('not pressed')
# else:
# print('pressed')