| ||
Shopping Cart
![]() |
Home | Products | Teensy | Blog | Forum |
You are here:
Teensy
![]() ![]() ![]() |
|
SoftPWM LibrarySoftPWM, written by Brett Hagman, can create additional PWM outputs on any pin. The signal frequency is relatively slow (default 30 Hz), which is mostly useful for controlling the brightness of LEDs.
Hardware RequirementsSoftPWM can control up to 20 pins. Any digital pin may be used.
SoftPWM is compatible with Teensy 3.6, Teensy 3.5, Teensy 3.2, Teensy 3.1, Teensy 3.0, Teensy LC, Teensy 2.0, and Teensy++ 1.0 & 2.0. SoftPWM does not work with Teensy 1.0.
Basic UsageSoftPWMBegin(SOFTPWM_NORMAL);Begin using SoftPWM. This function must be called first. The input can be SOFTPWM_NORMAL or SOFTPWM_INVERTED. SoftPWMSet(pin, value);Write the PWM on a pin. The value may be between 0 to 255. If fade times have been defined, the PWM will change gradually. SoftPWMSetFadeTime(pin, fadeUpTime, fadeDownTime);Set speed a PWM pin changes. fadeUpTime and fadeDownTime may be between 0 to 4000 milliseconds. SoftPWMSet(pin, polarity);Change the polarity on a single pin. Example ProgramSoftPWM comes with several examples. Open the from File > Examples > SoftPWM.CPU Usage & Interrupt LatencySoftPWM uses a timer and interrupt routine, which consumes considerable CPU time.TODO: actually measure CPU usage (maybe try changing the number of channels...) Latency sensitive libraries, like Servo and NewSoftSerial, will likely be disrupted by SoftPWM. More DetailsPlease refer to the official SoftPWM documentation for more details. |