Have the lepton 3.5 with an H7 board, this program runs fine but instead of having a three position switch that selects the palette at startup (the if/else), I want to use a single push button to move between the three palettes during normal operation (without having to restart board).
# On Off On switch
import sensor, image, time, math, tv, pyb
# Set GPIO input
switchColorOne = pyb.Pin("P9", pyb.Pin.IN, pyb.Pin.PULL_UP)
switchColorTwo = pyb.Pin("P8", pyb.Pin.IN, pyb.Pin.PULL_UP)
switchButton = pyb.Pin("P7", pyb.Pin.IN, pyb.Pin.PULL_UP) # This is the button
# Set threshold_list by switch
if switchColorOne.value() == 0 | switchColorTwo.value() == 0:
# Color Tracking Thresholds (L Min, L Max, A Min, A Max, B Min, B Max)
threshold_list = [( 70, 100, -30, 40, 20, 100)]
else:
# Color Tracking Thresholds (Grayscale Min, Grayscale Max)
threshold_list = [(220, 255)]
print("Resetting Lepton...")
# These settings are applied on reset
sensor.reset()
print("Lepton Res (%dx%d)" % (sensor.ioctl(sensor.IOCTL_LEPTON_GET_WIDTH),
sensor.ioctl(sensor.IOCTL_LEPTON_GET_HEIGHT)))
print("Radiometry Available: " + ("Yes" if sensor.ioctl(sensor.IOCTL_LEPTON_GET_RADIOMETRY)
else "No"))
# Set color palette by switch
if switchColorOne.value() == 0:
sensor.set_pixformat(sensor.RGB565)
elif switchColorTwo.value() == 0:
sensor.set_pixformat(sensor.GRAYSCALE)
else:
sensor.set_color_palette(sensor.PALETTE_IRONBOW)
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time=5000)
clock = time.clock()
tv.init(triple_buffer=False) # Initialize the tv.
tv.channel(8) # For wireless video transmitter shield
while(True):
clock.tick()
img = sensor.snapshot()
tv.display(sensor.snapshot()) # Take a picture and display the image.
I tried this:
if switchButton == False:
sensor.reset()
value = (value + 1)%3
if value == 0:
threshold_list = [( 70, 100, -30, 40, 20, 100)]
sensor.set_color_palette(sensor.PALETTE_IRONBOW)
sensor.set_pixformat(sensor.RGB565)
elif value == 1:
threshold_list = [( 70, 100, -30, 40, 20, 100)]
sensor.set_pixformat(sensor.RGB565)
else:
threshold_list = [(220, 255)]
sensor.set_pixformat(sensor.GRAYSCALE)
I wasn’t sure where to put it, it didn’t work kept getting errors. I’ve taken a python 101 type class but this stuff is a little over my head. Someone mentioned interrupts, I looked at this micropython documentation on gpio interrupts and this openmv python documentation on interrupt handlers but I am having a hard time grasping. Google isn’t helping much, I get mostly results on python GUI buttons.
Also, there’s some blob tracking code in there, I was just experimenting.
Any help pointing me in the right direction, or just assurance that I need to learn interrupter handling and callback functions, would be very appreciated.