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

Thread: Basic Exercise - Push Button and turn on the LED!

  1. #1
    Junior Member
    Join Date
    Jun 2015
    Posts
    3

    Basic Exercise - Push Button and turn on the LED!

    Hi all!

    This is my first post...for my first problem with teensy! I am totally new to this world...so I am sure that I am missing something simple...but I don't know what!

    I have a Teensy 2.0, what I am trying to do is connect a pushbutton to teensy and when the button is pressed the built-in led should turn on.

    Code (I am using Teensyduino)
    Code:
    void setup()
    {
      pinMode(PIN_D6, OUTPUT);       // LED
      pinMode(PIN_B0, INPUT_PULLUP); // Pushbutton
    }
    
    void loop()
    {
      if ( digitalRead(PIN_B0) == LOW ) { //Button is pressed?
        digitalWrite(PIN_D6, HIGH);   // LED on
      } else {
        digitalWrite(PIN_D6, LOW);  // LED off
      }
    }

    Click image for larger version. 

Name:	IMG_20150627_155202.jpg 
Views:	466 
Size:	74.6 KB 
ID:	4565

    I tried to rotate the pushbutton, but not work. The led never turn on.
    I am start thinking that my teensy is broken....

    Anyone can explain me what is wrong?

    Thanks to all!

  2. #2
    Senior Member
    Join Date
    Nov 2013
    Posts
    719
    Please load File->Examples->Teensy->Tutorial1->Blink, compile, upload and verify the LED on Teensy blinks fairly slowly.

    If it blinks then you can compare that code to your code and see if you can change your code enough to make it work.

    If it doesn't blink then there is something wrong with your Teensy.

  3. #3
    Junior Member
    Join Date
    Jun 2015
    Posts
    3
    Thanks for the reply.
    I already try to load blinky example and works correctly.
    The problem is that seems that do not work the input pullup features.

    There is a way to force in the breadboard digitalRead B0 to LOW ( so not via code )?

  4. #4
    Senior Member
    Join Date
    Nov 2013
    Posts
    719
    Disclaimer: I have Teensy ++2.0, Teensy 3.1 and Teensy LC - not a Teensy 2.0; So, I cannot directly test your (or my) code.

    Reviewing Teensy 2.0 pinout at https://www.pjrc.com/teensy/pinout.html I do not see 'PIN_D6' but instead 'PD6', in the "Using C language" set for Teensy 2.0

    Does the following fail the same? If so, maybe PIN_B0 is burnt out because it is difficult to believe that INPUT_PULLUP isn't supported there.

    Code:
    void setup()
    {
      pinMode(PD6, OUTPUT);       // LED
      pinMode(PB0, INPUT_PULLUP); // Pushbutton
    }
    
    void loop()
    {
      if ( digitalRead(PB0) == LOW ) { //Button is pressed?
        digitalWrite(PD6, HIGH);   // LED on
      } else {
        digitalWrite(PD6, LOW);  // LED off
      }
    }

  5. #5
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,198
    or use the Arduino numbering: replace PD6 with 11, and PB0 with 0
    Last edited by manitou; 06-28-2015 at 09:34 PM.

  6. #6
    Senior Member
    Join Date
    Nov 2012
    Location
    Boston, MA, USA
    Posts
    1,108
    Quote Originally Posted by manitou View Post
    or use the Arduino numbering: replace PD6 with 11, and PB0 with 0
    I was wondering where the bizarre numbering came from, and if it even worked. I think that is all the ancient, pre-Arduino stuff.

  7. #7
    Junior Member
    Join Date
    Jun 2015
    Posts
    3
    After some attempts finally I solved.

    The problem was...the header pins contacts of teensy!

    My teensy do not fit perfectly in the breadboard...

    FOr teensyduino there are two way:

    - Use number : https://www.pjrc.com/teensy/card2b.pdf
    - Use pre-defined costants: https://www.pjrc.com/teensy/td_digital.html

    Thanks to all!

Posting Permissions

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