24 lines
807 B
C++
24 lines
807 B
C++
const int buttonPin = 0; // Assuming BUT1 is connected to GPIO 0
|
|
const int ledPin = 8; // Assuming the user LED is connected to GPIO 8
|
|
//test1
|
|
void setup() {
|
|
Serial.begin(115200);
|
|
Serial.println("Setup started");
|
|
pinMode(buttonPin, INPUT_PULLUP); // Set the button pin as input with an internal pull-up resistor
|
|
pinMode(ledPin, OUTPUT); // Set the LED pin as output
|
|
Serial.println("Setup completed");
|
|
}
|
|
|
|
void loop() {
|
|
int buttonState = digitalRead(buttonPin); // Read the state of the button
|
|
|
|
if (buttonState == LOW) {
|
|
Serial.println("Button is pressed");
|
|
digitalWrite(ledPin, HIGH); // Turn on the LED
|
|
} else {
|
|
Serial.println("Button is not pressed");
|
|
digitalWrite(ledPin, LOW); // Turn off the LED
|
|
}
|
|
|
|
delay(2000); // Add a 2-second delay between readings
|
|
} |