/*
Arduino code to read a pushbutton connected to pin 2
*/
// Define the pin for the pushbutton
const int buttonPin = 2;
// Variable to store the state of the button
int buttonState = 0;
void setup() {
// Initialize the serial communication
Serial.begin(9600);
// Set the button pin as input
pinMode(buttonPin, INPUT);
}
void loop() {
// Read the state of the button
buttonState = digitalRead(buttonPin);
// Print the button state to the serial monitor
Serial.println(buttonState);
if (buttonState==1){
digitalWrite(3, HIGH);
}
else{
digitalWrite(3, LOW);
}
// Add a small delay to debounce the button
delay(50);
}