Tutorial3 PushbuttonPullup typo

duff

Well-known member
Code:
/* Pushbutton with Pullup, Teensyduino Tutorial #3
   http://www.pjrc.com/teensy/tutorial3.html


   This example code is in the public domain.
*/


void setup() {                
  Serial.begin(38400);
  pinMode(8, INPUT);[COLOR=#ff0000]<---- shouldn't this be INPUT_PULLUP?[/COLOR]
}


void loop()                     
{
  if (digitalRead(8) == HIGH) {
    Serial.println("Button is not pressed...");
  } else {
    Serial.println("Button pressed!!!");
  }
  delay(250);
}
 
Well, if you look at the page that is mentioned in line 2 of the sketch (http://www.pjrc.com/teensy/tutorial3.html), you'll see that the hardware design specifies an EXTERNAL pull-up resistor.

The pinMode INPUT_PULLUP specifies that the Teensy will use an INTERNAL pull-up resistor built into the processor, so you don't have to put an external one.

As long as none of the resistors is too small (let's say less than 100 Ohms), it doesn't hurt to have both of them. It just consumes more power when the button is pressed. So, having an external resistor in place, you can either use INPUT or INPUT_PULLUP, as long as you only have a button connected to the pin. For more advanced use cases, you might want to turn off the internal pull-up completely, which is done with pinMode INPUT.

However, if you don't have an external pull-up resistor, pinMode INPUT won't work and you will have to use INPUT_PULLUP. Check this page of the original Arduino docs for more information: http://arduino.cc/en/Tutorial/DigitalPins
 
Last edited:
Well, if you look at the page that is mentioned in line 2 of the sketch (http://www.pjrc.com/teensy/tutorial3.html), you'll see that the hardware design specifies an EXTERNAL pull-up resistor.

True, but Tutorial3 "Pushbutton" points to the same url and uses just INPUT also so it would seem to me that this example would use INPUT_PULLUP feature. Seems kinda convoluted to me. Or maybe include "add an external resistor" in the description.
 
Back
Top