Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 9 of 9

Thread: Blink sketch LED pin

  1. #1
    Senior Member
    Join Date
    Dec 2014
    Posts
    134

    Blink sketch LED pin

    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?

  2. #2
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,600
    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.

  3. #3
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,292
    Quote Originally Posted by Theremingenieur View Post
    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.
    The name is "LED_BUILTIN".

  4. #4
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,938
    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.

  5. #5
    Senior Member
    Join Date
    Dec 2014
    Posts
    310
    Haha, I thought it was just me, but I guess not. I tend to forget to change the ledPin definition too.

  6. #6
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,938
    Ok, my github foo is weak. Does anybody know where the Teensy examples live in Paul's Github so I can update it?

    The standard Arduino ones are https://github.com/PaulStoffregen/Ar...hared/examples but I'm not seeing where Tutorial1/blink lives.

  7. #7
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,061
    Oh, those aren't on github. Or they weren't.... but they are NOW. I've just uploaded here:

    https://github.com/PaulStoffregen/Ar...or-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.

  8. #8
    Senior Member
    Join Date
    Dec 2014
    Posts
    310
    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.

  9. #9
    Senior Member
    Join Date
    Dec 2013
    Location
    Brasilia, Brazil
    Posts
    166
    Quote Originally Posted by PaulStoffregen View Post
    Oh, those aren't on github. Or they weren't.... but they are NOW. I've just uploaded here:

    https://github.com/PaulStoffregen/Ar...or-Teensyduino
    And is there any place on Github where I can contribute a new example for the FlightSim classes (File > Examples > Teensy > USB_FlightSim > ...)? I would like to demonstrate the usefulness of the parameter for callback functions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •