This page has sections of code for doing things you might want in your programs. You may want to use them as procedures in your program. Make sure that they are put before any code that calls them.

This section of code will read the sensors on the wall sensor board. The global statements are defined so that you can access and display the lit and unlit values plus the resulting leftSensorValue, rightSensorValue, and frontSensorValue fields outside of the procedure. for use in your program or for diagnostic purposes

def readSensors(): # read wall sensors
    #Values are derived by subtracting the lit value of a sensor 
    # from the unlit value 
    global leftSensorValue, rightSensorValue, frontSensorValue
    global leftSensorLit, rightSensorLit, frontSensorLit
    global leftSensorUnlit, rightSensorUnlit, frontSensorUnlit
    global leftval, rightval, frontval

    leftSensorUnlit = leftSensor.read_u16()
    rightSensorUnlit = rightSensor.read_u16()
    sidesEmitter.value(1)
    time.sleep_us(75)
    leftSensorLit = leftSensor.read_u16()
    rightSensorLit = rightSensor.read_u16()
    sidesEmitter.value(0)
    
    frontSensorUnlit = frontSensor.read_u16()    
    frontEmitter.value(1)
    time.sleep_us(75)
    frontSensorLit = frontSensor.read_u16()
    frontEmitter.value(0)
    time.sleep_us(75)

    leftSensorValue = (leftSensorLit - leftSensorUnlit) # 
    rightSensorValue = (rightSensorLit- rightSensorUnlit) # 
    frontSensorValue = (frontSensorLit- frontSensorUnlit)
    

This section of code will read the sensors on the line follower board

def readSensors(): # Read line and side marker sensors
    global leftSensorValue, rightSensorValue
    global radiusSensorValue, startSensorValue
    global leftSensorUnlit, rightSensorUnlit 
    global radiusSensorUnlit, startSensorUnlit

    emitter.value(0)
    radiusEmitter.value(0)
    leftSensorUnlit = leftSensor.read_u16()
    rightSensorUnlit = rightSensor.read_u16()
    startSensorUnlit = startSensor.read_u16()
    radiusSensorUnlit = radiusSensor.read_u16()
    
    emitter.value(1)
    time.sleep_us(15)
    leftSensorLit = leftSensor.read_u16()
    rightSensorLit = rightSensor.read_u16()
    startSensorLit = startSensor.read_u16()
    emitter.value(0)
    
    radiusEmitter.value(1)
    time.sleep_us(15)
    radiusSensorLit = radiusSensor.read_u16()
    radiusEmitter.value(0)

    leftSensorValue = (leftSensorUnlit - leftSensorLit)
    rightSensorValue = (rightSensorUnlit - rightSensorLit)
    startSensorValue = (startSensorUnlit - startSensorLit)
    radiusSensorValue = (radiusSensorUnlit - radiusSensorLit)

This section of code will repeatedly flash the LEDs on the mezzanine board and the three indicator LEDs on either sensor board. For the line sensor board it will also briefly flash the line and marker illumination LEDs

def flashLEDs():
    i = 0
    while True:
        print ("flash LEDs", i)
        i = i + 1
        leftMezzLED.value(1) # left Mezzanine LED
        rightMezzLED.value(1)
        onBoardLED.value(1) # mini LED on Pico processor board
        time.sleep(1)
        leftMezzLED.value(0)
        rightMezzLED.value(0) # right Mezzanine LED
        onBoardLED.value(0)
        time.sleep(1)
        leftSensorLED.value(1) # Left LED on either sensor board
        time.sleep(0.5)
        centreSensorLED.value(1) # Centre LED on either sensor board
        time.sleep(0.5)
        rightSensorLED.value(1) # Right LED on either sensor board
        time.sleep(1)
        leftSensorLED.value(0)
        centreSensorLED.value(0)
        rightSensorLED.value(0)
        emitter.value(1)      # Line sensor line illumination LEDs
        time.sleep(0.1)
        emitter.value(0)
        radiusEmitter.value(1) # Line sensor marker illumination LED
        time.sleep(0.1)
        radiusEmitter.value(0)