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 LED

Totem Module 11


Code examples

Arduino projects: 11_distance

Module11 module;
Function usage (click to expand)

/* Distance */
// Read distance in millimeters
float distMM = module.distance.getMM();
// Read distance in centimeters
float distCm = module.distance.getCm();
// Read distance in foot
float distFoot = module.distance.getFoot();
// Read distance in inches
float distInch = module.distance.getInch();
// Check if some objet is detected
bool inRange = module.distance.inRange();
/* All RGB LED 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 LED control */
// Set LED 1 to color red
module.rgb.colorX(0, 255, 0, 0);
// Set LED 4 to color green
module.rgb.colorX(3, 0, 255, 0);
// Set LED 8 to color blue
module.rgb.colorX(7, 0, 0, 255);


Functions

Distance

(distance) module.distance.getMM()

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

(distance) module.distance.getCm()

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

(distance) module.distance.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.distance.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.distance.inRange()

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

All RGB LED control

module.rgb.colorTotem()

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

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

Set all LED color. It consists of red, green, blue colors.
Alternatives:
color(hex) - use 24-bit HEX color code
HEX (hexadecimal) color code is similar to HTML color code.
24-bit: 0xAABBCC0xAA (170 red), 0xBB (187 green), 0xCC (204 blue).
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 LED 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 LED control

module.rgb.colorX(number, red, green, blue)

Set single LED to specific color. It consists of red, green, blue colors.
Alternatives:
colorX(number, hex) - use 24-bit HEX color code
HEX (hexadecimal) color code is similar to HTML color code.
24-bit: 0xAABBCC0xAA (170 red), 0xBB (187 green), 0xCC (204 blue).
Parameter:
number - LED array number [0:7]
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]

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