#include <Servo.h>
const int buttonPin = 2; // The button is connected to pin 2
const int ledPin = 12; // The LED is connected to pin 12
// Variables to store the state of the button and LED
int buttonState = 0;
int ledState = LOW; // Start with the LED off
bool canPress = true;
void setup() {
// Initialize the button pin as an input
//pinMode(buttonPin, INPUT);
pinMode(buttonPin, INPUT_PULLUP);
// Initialize the LED pin as an output
pinMode(ledPin, OUTPUT);
}
void loop() {
// Read the state of the button
buttonState = digitalRead(buttonPin);
// Check if the button is pressed
if (buttonState == LOW && canPress) {
canPress = false;
// Invert the LED state
ledState = !ledState;
// Update the LED
digitalWrite(ledPin, ledState);
// Delay for debouncing
delay(1000);
}
else{
canPress = true;
}
}
/*
Servo servo1;
void setup() {
// put your setup code here, to run once:
servo1.attach(9);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
//digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
//delay(1000); // wait for a second
//digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
//delay(1000);
digitalWrite(12, HIGH);
servo1.write(0);
delay(2000);
digitalWrite(12, LOW);
servo1.write(180);
delay(2000);
digitalWrite(12, HIGH);
}
*/