Skip to content

[11] Distance module

Description

Module designed for measuring distance to an obstacle. It uses infrared laser sensor to avoid limitations of ultrasonic counterparts.
With included 8 color LED, module can be used for car headlights or distance indication.

Features:

  • Laser distance sensing (range 3-130 cm)
  • 8 individual controllable RGB lights

Totem Module 11


Code examples

Arduino projects: 11_distance

TotemModule11 module;
Function usage (click to expand)

/* Distance */
// Read distance in millimeters
float distMM = module.getMM();
// Read distance in centimeters
float distCm = module.getCm();
// Read distance in foot
float distFoot = module.getFoot();
// Read distance in inches
float distInch = module.getInch();
// Check if some objet is detected
bool inRange = module.isDetected();
/* All RGB lights control */
// Set all LED to "Totem" colors
module.rgb.colorTotem();
// Set all LED to green color
module.rgb.color(0, 255, 0);
module.rgb.color(0x00FF00);
// Turn all LED on
module.rgb.on();
// Turn all LED off
module.rgb.off();
// Set all LED to on
module.rgb.set(HIGH);
// Toggle all LED state on / off
module.rgb.toggle();
// Check if any LED is on
bool isOn = module.rgb.isOn();
// Enable bright mode
module.rgb.setBrightMode(true);
/* Single RGB light control */
// Set LED 1 to color red
module.rgb[0].color(255, 0, 0);
// Set LED 4 to color green
module.rgb[3].color(0, 255, 0);
// Set LED 8 to color blue
module.rgb[7].color(0, 0, 255);


Functions

Distance

(distance) module.getMM()

Get distance between module and barrier in millimeters.
Returns:
distance - millimeters to object ~[30:1300]mm. 0 - not detected.

(distance) module.getCm()

Get distance between module and barrier in centimeters.
Returns:
distance - centimeters to object ~[3:130]cm. 0 - not detected.

(distance) module.getFoot()

Get distance between module and barrier in foot.
Returns:
distance - foot to object (float) ~[0.098:4.265]ft. 0 - not detected.

(distance) module.getInch()

Get distance between module and barrier in inches.
Returns:
distance - inches to object (float) ~[1.181:51.181]inch. 0 - not detected.

(isDetected) module.isDetected()

Check if object is in sensing range (detected).
Returns:
isDetected - object detected [true:false].

All RGB lights control

module.rgb.colorTotem()

Set all LED to "Totem" colors (blue, yellow, green).

module.rgb.color(red, green, blue)

module.rgb.color(hex)

Set LED color with automatic RGB or HEX parameter. More convenient to use compared to ones with explicit format.
Alpha value in hex is ignored.
Parameter:
red - amount of red color [0:255]
green - amount of green color [0:255]
blue - amount of blue color [0:255]
hex - hexadecimal color code [0x000000:0xFFFFFF]

module.rgb.on()

Turn all LED on to last used color.

module.rgb.off()

Turn all LED off.

module.rgb.set(state)

Set all LED to specific state (on / off).
Parameter:
state - state on / off [HIGH:LOW] or [true:false]

module.rgb.toggle()

Toggle all LED between on / off states.

(state) module.rgb.isOn()

Check if any of RGB light is on.
Returns:
state - is any LED on [true:false] or [HIGH:LOW].

module.rgb.setBrightMode(state)

Disable multiplexing if all LED is set to the same color. This results in much more brightness.
This mode is required to be enabled each time module is powered up. This is disabled by default to match brightness when using color, colorX commands.
Parameter:
state - bright mode is on [true:false]. Default: false

Single RGB light control

Individual LED can be accessed by specifying index: module.rgb[0].on().
LED from 1 to 8 is identified as indexes 0-7.
Accessing "without index" will affect all LED.


Low level commands

These are low level TotemBUS commands accepted by module. Is not required when using objective API described above.

Command Parameters Description
distance Returns:(int) Get distance to object in mm
rgbAll/totem None Set LED to Totem colors
rgbAll/bright (bool) Enable bright LED mode
rgbAll (byte, byte, byte) Set all LED color
rgbX (byte, byte, byte, byte) Set specific LED color