Show:

BO.generators.Oscillator Class

The Oscillator object can be attached to a Pin or LED object to output a waveform. This is useful for blinking an LED or fading it on and off. In most cases (unless you are simply using it to blink and LED on or off), the Oscillator should be attached to a Pin or LED object associated with a PWM pin on the I/O board. See Breakout/examples/generators/oscillator.html for an example application.

Constructor

BO.generators.Oscillator

(
  • wave
  • freq
  • amplitude
  • offset
  • phase
  • times
)

Parameters:

  • wave Number

    waveform

  • freq Number

    frequency

  • amplitude Number

    amplitude

  • offset Number

    offset

  • phase Number

    phase

  • times Number

    The repeat count from 0 to infinite.

Methods

addEventListener

(
  • type
  • listener
)

Parameters:

  • type String

    The event type

  • listener Function

    The function to be called when the event is fired

autoUpdate

() private

computeValue

() private

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.

Oscillator.IMPULSE

() static

impulse

Oscillator.LINEAR

() static

linear

Oscillator.SAW

() static

saw wave

Oscillator.SIN

() static

sine wave

Oscillator.SQUARE

() static

square wave

Oscillator.TRIANGLE

() static

triangle wave

removeEventListener

(
  • type
  • listener
)

Parameters:

  • type String

    The event type

  • listener Function

    The function to be called when the event is fired

reset

()

Resets the oscillator.

start

()

Starts the oscillator.

stop

()

Stops the oscillator.

update

(
  • interval
)

By default the interval is 33 milliseconds. The Osc is updated every 33ms.

Parameters:

  • interval Number

    The update interval in milliseconds.

Properties

serviceInterval

Number

The service interval in milliseconds. Default is 33ms.

value

Number protected

[read-only] Get a generated number.

Events

update

BO.generators.GeneratorEvent.UPDATE

The update event is dispatched at the rate specified by the serviceInterval parameter (default = 33ms).

Event Payload: