Blink sketch LED pin

MacroMachines

Well-known member
So every time I test out a teensy that is new or that I haven't used in a while I go to the blink sketch and it doesn't work and I get worried thinking that the teensy is busted, only to remember after a few minutes that the pin number is not 11 as it is in the sketch, but 13.

In the next teensyduino update, would you be willing to make the blink pin 13 so that newbies and myself don't have this little moment of worry?
 
As far as I remember, there is a constant defined as LED_PIN which "adapts" automatically, depending on the CPU selected in the IDE menu. Using that one instead of a fixed pin number should fix the problem.
 
Which isn't currently defined in the Teensy example sketch, which has caught a couple of people out since that one defaults to pin 11.
 
Haha, I thought it was just me, but I guess not. I tend to forget to change the ledPin definition too.
 
Oh, those aren't on github. Or they weren't.... but they are NOW. I've just uploaded here:

https://github.com/PaulStoffregen/Arduino-examples-for-Teensyduino

Before you submit a pull request, please consider that Arduino 1.0.6 and 1.6.x do NOT allow these to be customized for different boards, platforms, etc. They are simply 1 set of examples used for ALL boards.

If 01.Basics/blink.ino is changed to use LED_BUILTIN, that change will be seen for ALL boards. If someone install an older or poorly maintained board which doesn't define LED_BUILTIN (as it should) to the same copy of Arduino where they're installed Teensyduino, that change will break the example. Likewise, if someone follows a tutorial on some random website that tells them to open 01.Basics/Blink, they'll see different code than the simple number.

Great care should be used when editing these shared examples. Usually I try to limit myself to editing just pin numbers or adding comments.
 
I think the suggestion is not so much changing the definition to using LED_BUILTIN necessarily, but just changing the example found in the IDE from examples->teensy->tutorial1->blink which reads:

Code:
/* LED Blink, Teensyduino Tutorial #1
   http://www.pjrc.com/teensy/tutorial.html
 
   This example code is in the public domain.
*/

// Teensy 2.0 has the LED on pin 11
// Teensy++ 2.0 has the LED on pin 6
// Teensy 3.0 has the LED on pin 13
const int ledPin = 11;

to use pin 13, leaving the Arduino examples intact. Or actually, as those examples are only installed with Teensyduino and are in the teensy->examples section, you could use LED_BUILTIN in that tutorial with relative safety.
 
Back
Top