User Tools

Site Tools


Digispark Pro PWM Features

PWM on the Pro:

NOTE: These features are only present in Digistump Arduino IDE Release 1.5.8C and higher

The Digispark Pro supports 2 channels of PWM (timers) that can be connected to 3 pins (channel A) or 2 pins (channel B) - the output must be the same on all pins that share the same channel and any, many, all or no pins can be connected to the channel.

See the pinout diagram for which pins correspond to which channels:


The standard Arduino analogWrite function works with the Pro. Using analogWrite(pin,value) where pin is the pin number, and value is the PWM value you want to set that pin to - works just like a regular Arduino and sets that pin to that value and disconnects all other pins on that channel from the PWM channel. This means with analogWrite you can have one pin on each channel active at a time.

Note: Pin 8 PWM functionality is accessed only with analogWrite - since it is the only pin on that channel the other functions below are not needed

Special PWM functions:

The Digispark Pro also has the following special functions available for use with the PWM functionality on Pins 0-4 (these are not used for Pin 8 - see note above):


Where “channel” is either “CHANNELA” or “CHANNELB” and value is a value from 0-255 to set that PWM channel to ex) pwmWrite(CHANNELA,125);

This sets that channel (or timer) to the PWM value specified and it will be output to any pins you connect with the pwmConnect() function.


Where pin is the pin number (0,1,2,3, or 4) that you want to connect to its PWM channel.


Where pin is the pin number (0,1,2,3, or 4) that you want to disconnect from its PWM channel.


Disconnect all pins from their PWM channel.


void setup() {
  pwmConnect(0);//connect pin 0 to its channel (A)
  pwmConnect(1);//connect pin 1 to its channel (B)
  pwmWrite(CHANNELA,127); //set channel A to 1/2 PWM output - therefore pin 0 is at 50% PWM output 
  pwmWrite(CHANNELB,63); //set channel B to 1/4 PWM output - therefore pin 1 is at 25%  output
  pwmConnect(4);//connect pin 4 to its channel (B) - pin 4 is now also at 25% output
  pwmWrite(CHANNELB,255); //set channel B to 100% PWM output - therefore pin 1 and 4 are at 100%  output
  pwmDisconnect(1);//disconnect pin 1 from its channel (B) - pin 1 is no longer outputting the PWM signal
  pwmConnect(2);//connect pin 2 to its channel (A)  pin 2 is now also at 50% PWM output 
  pwmConnect(3);//connect pin 3 to its channel (A)  pin 3 is now also at 50% PWM output 
  pwmReset(); //all pins are disconnected from their channels and no longer outputting the PWM signal

// the loop routine runs over and over again forever:
void loop() {

digispark/tutorials/propwm.txt · Last modified: 2016/06/09 12:03 (external edit)