#define LED_PIN 33
#define BUT_PIN 27
//Serial.begin(): https://www.arduino.cc/reference/en/language/functions/communication/serial/begin/
void setup() {
//Initialize communication (for serial monitor)
//Serial.begin(9600); // baud rate (bits per second)
// init pins
pinMode(LED_PIN,OUTPUT);
pinMode(BUT_PIN,INPUT);
}
void loop() {
// read the actual state of the button
bool buttonPressed = digitalRead(BUT_PIN);
//printToSerialMonitor(buttonPressed);
if(buttonPressed) {
// Button is being pressed: Turn on the LED
digitalWrite(LED_PIN, HIGH);
} else {
//Button is NOT pressed: Turn off the LED
digitalWrite(LED_PIN, LOW);
}
}
void printToSerialMonitor(bool buttonPressed) {
Serial.print("Button pressed: ");
Serial.println(buttonPressed);
// Avoid overflowing the serial monitor by slowing down the loop
delay(200);
}