Options
All
  • Public
  • Public/Protected
  • All
Menu

Class PeripheralPWM<EventTypes>

We will now generate PWM. Maximum current depends on the driving mode. See io.

Type parameters

  • EventTypes: string

Hierarchy

Implements

Index

Constructors

constructor

Properties

Obniz

Obniz: Obniz

obniz to be used

timeout

timeout: number = 30 * 1000

Rsponse waiting timeout in milliseconds

Static prefixed

prefixed: string | boolean

Methods

addListener

  • addListener(event: EventTypes, fn: ListenerFn, context?: any): this
  • Parameters

    • event: EventTypes
    • fn: ListenerFn
    • Optional context: any

    Returns this

duty

  • duty(duty: number): void
  • Set pulse duty in terms of ratio.

    // Javascript Example
    var pwm = obniz.getFreePwm();
    pwm.start({io:0});
    pwm.freq(2000); // set pwm frequency to 2khz
    pwm.duty(50) // set pwm pulse width 50%

    Parameters

    • duty: number

    Returns void

emit

  • emit(event: EventTypes, ...args: Array<any>): boolean
  • Calls each of the listeners registered for a given event.

    Parameters

    • event: EventTypes
    • Rest ...args: Array<any>

    Returns boolean

end

  • end(): void
  • It stops pwm and releases io.

    // Javascript Example
    var pwm = obniz.getFreePwm();
    pwm.start({io:0});
    pwm.end();

    Returns void

eventNames

  • eventNames(): Array<EventTypes>
  • Return an array listing the events for which the emitter has registered listeners.

    Returns Array<EventTypes>

freq

  • freq(freq: number): void
  • Set frequency, not pulse duration.

    For example, this value will be 1khz with DC motor.

    // Javascript Example
    var pwm = obniz.getFreePwm();
    pwm.start({io:0});
    pwm.freq(1000); // set pwm. frequency to 1khz

    Parameters

    • freq: number

      frequency (Hz)

    Returns void

listenerCount

  • listenerCount(event: EventTypes): number
  • Return the number of listeners listening to a given event.

    Parameters

    • event: EventTypes

    Returns number

listeners

  • listeners(event: EventTypes): Array<ListenerFn>
  • Return the listeners registered for a given event.

    Parameters

    • event: EventTypes

    Returns Array<ListenerFn>

modulate

  • modulate(type: PWMModulateType, symbol_length: number, data: number[]): void
  • This modulates pwm with data.

    Modulation can be chosen from below.

    1. "am"

    am modulation

    data "1" means put out the pwm with duty ratio of 50%. "0" means stop pwm. io will be 0. Interval defines the symbol baud rate. Duty is fixed at 50%.

    This is useful to generate IR signal (Remote control). Frequency of 38kHz gets modulated with signals.

    Parameters

    • type: PWMModulateType
    • symbol_length: number
    • data: number[]

      data array. All data[index] is 0 or 1.

    Returns void

notifyFromObniz

  • notifyFromObniz(json: any): void

off

  • off(event: EventTypes, fn?: EventEmitter.ListenerFn, context?: any, once?: undefined | false | true): this
  • Parameters

    • event: EventTypes
    • Optional fn: EventEmitter.ListenerFn
    • Optional context: any
    • Optional once: undefined | false | true

    Returns this

on

  • on(event: EventTypes, fn: ListenerFn, context?: any): this
  • Add a listener for a given event.

    Parameters

    • event: EventTypes
    • fn: ListenerFn
    • Optional context: any

    Returns this

once

  • once(event: EventTypes, fn: ListenerFn, context?: any): this
  • Add a one-time listener for a given event.

    Parameters

    • event: EventTypes
    • fn: ListenerFn
    • Optional context: any

    Returns this

pulse

  • pulse(pulse_width: number): void
  • Set pulse duty

    // Javascript Example
    var pwm = obniz.getFreePwm();
    pwm.start({io:0});
    pwm.freq(2000); // set pwm frequency to 2khz
    pwm.pulse(0.5) // set pwm pulse 0.5ms.  so this is  25% ratio.

    Parameters

    • pulse_width: number

      pulse time (ms).

    Returns void

removeAllListeners

  • Remove all listeners, or those of the specified event.

    Parameters

    Returns this

removeListener

  • removeListener(event: EventTypes, fn?: EventEmitter.ListenerFn, context?: any, once?: undefined | false | true): this
  • Remove the listeners of a given event.

    Parameters

    • event: EventTypes
    • Optional fn: EventEmitter.ListenerFn
    • Optional context: any
    • Optional once: undefined | false | true

    Returns this

start

  • This starts a pwm on a given io. freq=1khz, duty=0% at start.

    io drive and pull can be configured. See more details on io

    // Javascript Example
    var pwm = obniz.getFreePwm();
    pwm.start({io:0}); // start pwm. output at io0
    pwm.freq(1000);
    pwm.duty(50);
    
    var pwm2 = obniz.getFreePwm();
    pwm2.start({io:1, drive:"open-drain", pull:"5v"});

    Parameters

    Returns void

validate

  • validate(commandUri: any, json: any): WSSchema.MultiResult
  • Parameters

    • commandUri: any
    • json: any

    Returns WSSchema.MultiResult

Generated using TypeDoc