Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //WITH RESISTOR ,
- //pinMode(buttonPin, INPUT);
- //digitalWrite(buttonPin, HIGH); //CLOSE
- //digitalWrite(buttonPin, LOW); //OPEN
- //
- //WITHOUT RESISTOR
- //pinMode(buttonPin, INPUT_PULLUP);
- //digitalWrite(buttonPin, LOW); //CLOSE
- //digitalWrite(buttonPin, HIGH); //OPEN
- #define buttonPinRes 3
- int buttonStateRes;
- int lastButtonStateRes = LOW;
- unsigned long lastDebounceTimeRes = 0;
- unsigned long debounceDelay = 50;
- bool resSelected = false;
- void setup()
- {
- Serial.begin(9600);
- pinMode(buttonPinRes, INPUT_PULLUP);
- }
- void loop() {
- readBtnRes();
- booleanCheck();
- }
- void readBtnRes() {
- int reading = digitalRead(buttonPinRes);
- if (reading != lastButtonStateRes) {
- lastDebounceTimeRes = millis();
- }
- if ((millis() - lastDebounceTimeRes) > debounceDelay) {
- if (reading != buttonStateRes) {
- buttonStateRes = reading;
- if (buttonStateRes == LOW) {
- resSelected = true;
- }
- }
- }
- lastButtonStateRes = reading;
- }
- void booleanCheck()
- {
- if(resSelected)
- {
- Serial.print("TRUE");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment