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

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

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 ATtiny817 breakout.

This example will not work with the ATtiny817 breakout 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 ATtiny817, such as pin 12 to match the wiring diagram:

int led = 12;           // 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 ATtiny8x7 breakout these are pins 0, 1, 9, 12, 13
*/

#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 2021-10-20 12:04:17 -0400.

This page (PWM) was last updated on Nov 28, 2021.

Text editor powered by tinymce.