void setup() {
pinMode(2, INPUT);
pinMode(6, INPUT_PULLUP);
pinMode(4, OUTPUT);
Serial.begin(9600); // initialize serial
}
// If not using PULLUP, then default state will be HIGH and you
// need to dampen it before sending signal to PIN using a
// 10k resistor, so pressing the button results in LOW state
void loop() {
int buttonInput2 = digitalRead(2); // Read the state of pin 2
//Serial.println("BUTTON:" + buttonInput); // Print the value to the Serial Monitor
if (buttonInput2 == LOW) {
digitalWrite(4, HIGH); // Turn off the LED
delay(100); // Simple delay for debouncing and readability
Serial.println("1OFF"); // Print the value to the Serial Monitor
} else {
digitalWrite(4, LOW); // Turn on the LED
delay(100); // Simple delay for debouncing and readability
Serial.println("1ON"); // Print the value to the Serial Monitor
}
// If using PULLUP, you are using internal voltage to power the signal
// and bring it up to a HIGH value, so pressing button connects you to ground
// resulting in a LOW state
int buttonInput6 = digitalRead(6); // Read the state of pin 6
//Serial.println("BUTTON:" + buttonInput); // Print the value to the Serial Monitor
if (buttonInput6 == LOW) {
digitalWrite(4, LOW); // Turn on the LED
delay(100); // Simple delay for debouncing and readability
Serial.println("2ON"); // Print the value to the Serial Monitor
} else {
digitalWrite(4, HIGH); // Turn off the LED
delay(100); // Simple delay for debouncing and readability
Serial.println("2OFF"); // Print the value to the Serial Monitor
}
}
// Serial.println(buttonState == HIGH ? "Button Pressed" : "Button Released");