Trinket Pro pin 13 LED Fade

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
fixitnate
 
Posts: 4
Joined: Thu Sep 24, 2015 6:41 pm

Trinket Pro pin 13 LED Fade

Post by fixitnate »

Just got my first Arduino stuff ever tonight, messing around with a Trinket Pro 5V. Have successfully gotten to the point where I can upload. I'm messing around with the "Fade" example program, which addresses pin 9. I've changed that to pin 13 and I know the hardware is capable of fading the LED in and out because the bootloader does it. All I've gotten so far is SOLID ON, SOLID OFF. Serial output indicates values are counting from 0-255-0 as programmed.

So what am I missing?

Code: Select all

int ledPin = 13;    // LED connected to digital pin 9

void setup() {
  // nothing happens in setup
  // wanna bet, plinko?
  Serial.begin(9600);
  Serial.println("And so it begins.");
}

void loop() {
  // fade in from min to max in increments of 5 points:
  for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);
    Serial.println(fadeValue);
    // wait for 30 milliseconds to see the dimming effect
    delay(30);
  }

  // fade out from max to min in increments of 5 points:
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);
    Serial.println(fadeValue);
    // wait for 30 milliseconds to see the dimming effect
    delay(30);
  }
}
Thanks!
Nate

<EDIT>
Same code does work with an LED hooked to pin 10 which is marked with a ~, so now I wonder if the bootloader is Captain Specialpants and is the only thing able to fade pin 13?
</EDIT>

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Trinket Pro pin 13 LED Fade

Post by adafruit_support_mike »

The bootloader bit-bangs the PWM instead of using the Arduino library's analogWrite() commands.

Only specific pins are eligible for use with analogWrite(). It uses the compare-match feature of the internal timers, and those outputs are wired to specific pins (the ones marked with ~).

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”