This video provides a basic tutorial on how to use QikEasy IR Seeker.
Here’s the Word Block program for the first part of the tutorial (for Spike App 3):
Here’s the Python code for part 1 of the tutorial (for Spike App 3):
from hub import light_matrix, port
import runloop
import color_sensor
Direction = 0
SignalStrength = 0
# IR Seeker Combine IR Data Function into the two global variables
def Ir_Combine_360_Sensor_Data(FrontDirection, FrontStrength, BackDirection, BackStrength):
global Direction, SignalStrength
if ( FrontStrength == 0 and BackStrength == 0):
Direction = 0
else:
if ( FrontStrength > BackStrength):
Direction = round( FrontDirection )
SignalStrength = round( FrontStrength )
else:
Direction = round( BackDirection ) + 9
SignalStrength = round( BackStrength )
# IR Seeker Read 360 Function
def Ir_Read_360_Sensor_Data(Channel, ReductionFactor):
rgb = color_sensor.rgbi(Channel)
Ir_Combine_360_Sensor_Data( color_sensor.reflection(Channel)//4, rgb[0]//ReductionFactor, rgb[2]//ReductionFactor, rgb[1]//ReductionFactor)
# MAIN PROGRAM
async def main():
while (1):
Ir_Read_360_Sensor_Data(port.C, 4)
print( [Direction, SignalStrength] )
await runloop.sleep_ms(200)
runloop.run(main())
Here’s the Word Block program for the second part of the tutorial (for Spike App 3):
Here’s the Python code for part 2 of the tutorial (for Spike App 3):
from hub import light_matrix, port
import runloop
import color_sensor
Direction = 0
SignalStrength = 0
DirectionToXYMap = "13,12,11,21,31,41,51,52,53,53,54,55,45,35,25,15,14,13"
x = 1
y = 1
# IR Seeker Combine IR Data Function into the two global variables
def Ir_Combine_360_Sensor_Data(FrontDirection, FrontStrength, BackDirection, BackStrength):
global Direction, SignalStrength
if ( FrontStrength == 0 and BackStrength == 0):
Direction = 0
else:
if ( FrontStrength > BackStrength):
Direction = round( FrontDirection )
SignalStrength = round( FrontStrength )
else:
Direction = round( BackDirection ) + 9
SignalStrength = round( BackStrength )
# IR Seeker Read 360 Function
def Ir_Read_360_Sensor_Data(Channel, ReductionFactor):
rgb = color_sensor.rgbi(Channel)
Ir_Combine_360_Sensor_Data( color_sensor.reflection(Channel)//4, rgb[0]//ReductionFactor, rgb[2]//ReductionFactor, rgb[1]//ReductionFactor)
print(Direction)
# Draw Pixel on LED Matrix to indicate direction
def Draw_Led_Pixel( IrSeeker360Direction ):
global x, y
light_matrix.set_pixel( x-1, y-1, 0)
if ( IrSeeker360Direction != 0 ):
x = int( DirectionToXYMap[ (IrSeeker360Direction - 1) * 3 ] )
y = int( DirectionToXYMap[ (IrSeeker360Direction - 1) * 3 + 1 ] )
light_matrix.set_pixel( x-1, y-1, 100)
# MAIN PROGRAM
async def main():
light_matrix.clear()
# Draw the cross at the center of the display
light_matrix.show([ 0, 0, 0, 0, 0] +
[ 0, 0,100, 0, 0] +
[ 0,100,100,100, 0] +
[ 0, 0,100, 0, 0] +
[ 0, 0, 0, 0, 0])
while (1):
Ir_Read_360_Sensor_Data(port.C, 4)
Draw_Led_Pixel(Direction)
await runloop.sleep_ms(200)
runloop.run(main())