/*
Project: Pull Up/Down Demo
Description: Demonstrates button wiring and
pin setup for pull up or pull down
Creation date: 5/1/23
Author: AnonEngineering
License: Beerware
*/
const int PULL_DN_BTN = 4;
const int PULL_UP_BTN = 5;
int oldPullDnState = HIGH; // pin will idle low
int oldPullUpState = LOW; // pin will idle high
void setup() {
Serial.begin(9600);
pinMode(PULL_DN_BTN, INPUT); // pulldown, needs external resistor
pinMode(PULL_UP_BTN, INPUT_PULLUP); // pullup, uses internal resistor
Serial.println("Ready...\n");
}
void loop() {
int pullUpState = digitalRead(PULL_UP_BTN);
int pullDnState = digitalRead(PULL_DN_BTN);
if (pullUpState != oldPullUpState || pullDnState != oldPullDnState) {
oldPullUpState = pullUpState;
oldPullDnState = pullDnState;
Serial.print("Pull up pin state is:\t");
//Serial.println(pullUpState);
Serial.println(pullUpState ? "HIGH" : "LOW");
Serial.print("Pull down pin state is:\t");
//Serial.println(pullDownState);
Serial.println(pullDnState ? "HIGH" : "LOW");
Serial.println();
}
delay(50); // debounce
}