Show:

BO.io.Potentiometer Class

Creates an interface to an analog input sensor. This may be a potentiometer (dial) or any other analog input that is connected to a single analog pin.

Constructor

BO.io.Potentiometer

(
  • board
  • pin
  • enableSmoothing
)

Parameters:

  • board IOBoard

    A reference to the IOBoard instance that the servo is attached to.

  • pin Pin

    A reference to the Pin the potentiometer is connected to.

  • enableSmoothing Boolean

    True to enable smoothing, false to disable. Default is false.

Methods

addEventListener

(
  • type
  • listener
)

Parameters:

  • type String

    The event type

  • listener Function

    The function to be called when the event is fired

clear

()

Resets the minimum, maximum, and average values.

dispatchEvent

(
  • type
  • optionalParams
)

Parameters:

  • type Event

    The Event object.

  • optionalParams Object

    Optional parameters passed as an object. return {boolean} True if dispatch is successful, false if not.

hasEventListener

(
  • type
)

Parameters:

  • type String

    The event type return {boolean} True is listener exists for this type, false if not.

onPinChange

() private

removeEventListener

(
  • type
  • listener
)

Parameters:

  • type String

    The event type

  • listener Function

    The function to be called when the event is fired

setRange

(
  • minimum
  • maximum
)

Scale from the minimum and maximum input values to 0.0 -> 1.0. This is useful for sensors such as a flex sensor that may not return the full range of 0 to 1.

Parameters:

  • minimum Number

    The new minimum range (must be less than the maximum).

  • maximum Number

    The new maximum range.

Properties

average

Number

[read-only] Get the (pre-filtered) average value of the potentiometer.

maximum

Number

[read-only] Get the (pre-filtered) maximum value read by the potentiometer.

minimum

Number

[read-only] Get the (pre-filtered) minimum value read by the potentiometer.

preFilterValue

Number

[read-only] Get the value of the potentiometer before filters are applied.

value

Number

[read-only] The current value of the potentiometer.

Events

change

BO.io.PotEvent.CHANGE

The change event is dispatched when the potentiometer value changes.

Event Payload:

  • target BO.Potentiometer

    A reference to the Potentiometer object

Example:

pot.addEventListener(PotEvent.CHANGE, onValueChange);

function onValueChange(event) {
    console.log("value = " + event.target.value);
}