The seesaw firmware that ships with the ATtiny817 breakout includes PWM capabilities on specific pins. This example fades an external LED.

Follow the steps on the Arduino page to get set up.

PWM Pins

The ATtiny817 breakout with seesaw firmware provides PWM on the following pins:

  • 0, 1, 9, 12, 13

The ATtiny816 and ATtiny1616 breakouts with seesaw firmware provides PWM on the following pins:

  • 0, 1, 7, 11, 16

Wiring

Follow the instructions to add an external LED to your existing setup.

  • Use a STEMMA QT cable to connect the STEMMA QT connector on the Qt Py to the STEMMA QT connector on the breakout.
  • Connect the + leg (longer leg) of LED to breakout pin 12
  • Connect the - leg (shorter leg) of LED to 1kΩ resistor
  • Connect 1kΩ resistor to breakout GND
If you are using an ATtinyx16, pin 12 is not a PWM pin. Connect the anode (+) pin of the LED to one of the 5 PWM capable pins listed above.

Example Code

Open up File -> Examples -> Adafruit Seesaw -> analog -> Fade.

Before you upload it to your microcontroller, you must make a change for it to work with the ATtinyxxx breakouts.

This example will not work with the ATtinyxxx breakouts as is. You must update the led pin before uploading the sketch!

Update the following line:

int led = 6;           // the PWM pin the LED is attached to

To one of the PWM capable pins on the ATtinyxxx, such as pin 1:

int led = 1;           // the PWM pin the LED is attached to

You must do this before uploading the sketch, or it won't work with your setup!

/*
  Fade

  This example shows how to fade an LED on pin 6 of a seesaw board using the analogWrite()
  function.

  The analogWrite() function uses PWM, so if you want to change the pin you're
  using, be sure to use another PWM capable pin. 
  On the SAMD09 breakout these are pins 5, 6, and 7
  On the ATtinyxy7 breakout these are pins 0, 1, 9, 12, 13
  On the ATtinyxy6 breakout these are pins 0, 1, 7, 11, 16
*/

#include "Adafruit_seesaw.h"

Adafruit_seesaw ss;

int led = 6;           // the PWM pin the LED is attached to
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by

// the setup routine runs once when you press reset:
void setup() {
  Serial.begin(115200);
  
  while (!Serial) delay(10);   // wait until serial port is opened
  
  if(!ss.begin()){
    Serial.println("seesaw not found!");
    while(1) delay(10);
  }
}

// the loop routine runs over and over again forever:
void loop() {
  // set the brightness of the LED:
  ss.analogWrite(led, brightness);

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness <= 0 || brightness >= 255) {
    fadeAmount = -fadeAmount;
  }
  // wait for 30 milliseconds to see the dimming effect
  delay(30);
}

Once you've successfully uploaded the sketch to your board, open the Serial Monitor (Tools->Serial Monitor), and the LED will begin to fade bright and dim!

This guide was first published on Oct 20, 2021. It was last updated on Sep 19, 2023.

This page (PWM) was last updated on Oct 19, 2021.

Text editor powered by tinymce.