Is there a way where we can add this function to this cuurent code?
#include <Servo.h>
Servo myservo;
Servo myservo2;
Servo myservo3;
const int Button1 = 2; // the number of the pushbutton pin
const int Button2 = 3; // the number of the pushbutton pin
int pos = 15;
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
int buttonPushCounter = 0; // counter for the number of button presses
boolean currentButton = LOW;
// variables will change:
bool buttonState = 0; // variable for reading the pushbutton status
bool buttonState2 = 0;
void setup() {
Serial.begin(9600);
myservo.attach(9);
myservo2.attach(10);
myservo3.attach(11);
pinMode(Button1, INPUT);
pinMode(Button2, INPUT);
myservo.write(15);
myservo2.write(15);
delay(500);
//myservo3.write(0);
}
boolean debounce(boolean last)
{
boolean current = digitalRead(buttonPin);
if (last != current)
{
delay(5);
current = digitalRead(buttonPin);
}
return current;
}
void loop() {
buttonState = digitalRead(Button1);
if (buttonState == HIGH) {
pos = 170;
delay(500);
} else {
pos = 15;
delay(500);
}
myservo.write(pos);
myservo2.write(pos);
Serial.println(pos);
}