Color Input

COLORINPUT provides interfaces to an I2C-connected Color Input sensor.

Add Input Device

Item

Description

Color Input

Provides interfaces to an I2C-connected Color Input sensor.

The bb_port pin is used in addition to the I2C port to control the LED on the color sensor.

color_number(): Returns a value from 1 to 9 that represents the color the sensor is detecting.

The numbers represent the colors per the following mapping:

1: Red

2: Green

3: Blue

4: Cyan

5: Magenta

6: Yellow

7: Black

8: White

9: Gray

red(): Returns a value from 0 to 255 that represents the intensity of the RED color level being detected.
green(): Returns a value from 0 to 255 that represents the intensity of the GREEN color level being detected.
blue(): Returns a value from 0 to 255 that represents the intensity of the BLUE color level being detected.
gray(): Returns a value from 0 to 255 that represents the gray level being detected, where 0 is black and 255 is white.

CE products: from colorinp import *

TI-Nspire CX II: from ti_hub import *

 

 

The function to create the object is pasted from the menu.

var=color_input("bb_port")

Command:

var=color_input("bb_port")

Command
Syntax:

var=color_input("bb_port")

Python
Code
Sample:

TI Nspire CX II:

from ti_hub import *

c1 = color_input("BB 2")

value = c1.color_number()

if (value == 1):

••print("Red!")

else:

••print("Not red")

 

CE products:

from colorinp import *

c1 = color_input("BB 2")

value = c1.color_number()

if (value == 1):

••print("Red!")

else:

••print("Not red")

Range:

Describe:

Creates an object for the color_input sensor. The sensor is attached to the I2C port and the “bb_port” is the pin on the breadboard port for the pin to control the LED in the sensor.

Result:

Type or
Addressable
Component:

Control

 

var.color_number()

Command:

var.color_number()

Command
Syntax:

var.color_number()

Range:

Describe:

Returns the a value between 1 – 9 from the color sensor.

1 – red

2 – green

3 – blue

4 – cyan

5 – magenta

6 - yello

7 – black

8 - white

9 – gray

Result:

Type or
Addressable
Component:

Control

 

var.red()

Command:

var.red()

Command
Syntax:

var.red()

Range:

Describe:

Returns a value between 0 and 255 representing the “red” component of the color under the sensor.

Result:

Type or
Addressable
Component:

Control

 

var.green()

Command:

var.green()

Command
Syntax:

var.green()

Range:

Describe:

Returns a value between 0 and 255 representing the “green” component of the color under the sensor.

Result:

Type or
Addressable
Component:

Control

 

var.blue()

Command:

var.blue()

Command
Syntax:

var.blue()

Range:

Describe:

Returns a value between 0 and 255 representing the “blue” component of the color under the sensor.

Result:

Type or
Addressable
Component:

Control

 

var.gray()

Command:

var.gray()

Command
Syntax:

var.gray()

Range:

Describe:

Returns a value between 0 and 255 representing the “gray component of the color under the sensor.

Result:

Type or
Addressable
Component:

Control