Class Dac

extends Object
Digital-to-Analog channel for generating a voltage on a GPIO pin.

Class summary


constructor pin/any --initial-voltage/float=
Initializes a DAC channel.

Constructors

constructor pin/any --initial-voltage/float=0.0
Initializes a DAC channel.
The pin is a GPIO number. The DAC reserves the pin and releases it again when the DAC is closed.
If provided, sets the output of the dac to the given initial-voltage. Otherwise, the pin is set to emit 0V.
Passing a Pin is deprecated; provide the integer GPIO number instead. The Pin form will be removed in a future release.

Statics

Phase shift constant of the cosine wave generator: 0°

Phase shift constant of the cosine wave generator: 180°

Scale factor for the cosine wave generator that yields full amplitude.

Scale factor for the cosine wave generator that yields half amplitude.

Scale factor for the cosine wave generator that yields 1/4 amplitude.

Scale factor for the cosine wave generator that yields 1/8 amplitude.

Methods

close -> none
Closes the DAC channel releases the associated resources.

cosine-wave --frequency/int --scale/int=COSINE-WAVE-SCALE-1 --phase/int=COSINE-WAVE-PHASE-0 --offset/float=0.0 -> none
Starts a cosine wave generator on the DAC channel.
The frequency must be in range [130 .. 5500].
The phase must be either COSINE-WAVE-PHASE-0 or COSINE-WAVE-PHASE-180.
By default, the wave is centered at VCC/2, independent of the scale. By providing an offset, the wave can be shifted vertically. The offset must be in range [-1.0 .. 1.0], where -1.0 means that the wave is centered at 0V (cutting off anything that tips below), and 1.0 means that the wave is centered at VCC (cutting off anything that tips above).
The ESP32 has only one wave generator. Behavior is undefined if multiple DAC channels use it at the same time.

Whether this DAC channel is closed.

operator == other/any -> bool
Whether this object is equal to the other.
By default, identical is used for equality.
Inheritance
Classes overwrite this operator to get an equality specific to their needs. Equality operators often compare the type and field contents. For example:

class Pin:
  number/int

  constructor .number:

  operator == other:
    if other is not Pin: return false
    return number == other.number
A class doesn't have to follow the above format, but it must keep the operator in sync with any hash-code method. That is, if a class has a hash-code member, then the equality and hash-code must agree. If two instances are equal (a == b), then their hash codes must also be equal (a.hash-code == b.hash-code).

set voltage/float -> none
Sets the output voltage of the DAC channel to voltage.

Stringifies this object.
Inheritance
Objects that need a human-friendly string representation should overwrite this method. The default string is based on the internal class-ID.

Fields

pin / any