Basic Exercise - Push Button and turn on the LED!

Status
Not open for further replies.

xsia

New member
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
  }
}


IMG_20150627_155202.jpg

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!
 
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.
 
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 )?
 
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
  }
}
 
or use the Arduino numbering: replace PD6 with 11, and PB0 with 0
 
Last edited:
Status
Not open for further replies.
Back
Top