Robin2:
Assume you have a variable the keeps track of how many buttons are pressed. Then something like this pseudo codeif (numButtonsPressed == 2) {
if prevNumButtonsPressed < 2) { // the number pressed has just changed
twoButtonsStartTime = millis();
}
if (millis() - twoButtonsStartTime >= millisForOneStep) {
// two feet were on the ground longer than the period of a normal step
}
else {
// assume that a step is in progress - perhaps do nothing
}
}
prevNumButtonsPressed = numButtonsPressed;
...R
THANK YOU! THIS WORKS! Here's the final code!
const int leftButtonPin = 2; //buttons
const int rightButtonPin = 3;
int buttonsPressed = 0;
int prevButtonsPressed = 0;
int twoButtonsStartTime = 0;
int millisForOneStep = 500;
int servoLeft = 5; //servo
int servoRight = 5;
int left = 0; //variables for reading button states
int right = 0;
#include <Servo.h>
Servo myservo;
int pos = 0;
void setup() {
myservo.attach(5);
pinMode(leftButtonPin, INPUT);
pinMode(rightButtonPin, INPUT);
pinMode(servoLeft, OUTPUT);
pinMode(servoRight, OUTPUT);
Serial.begin(9600);
}
void loop() {
Serial.print("Amount :");
Serial.print(buttonsPressed);
left = digitalRead(leftButtonPin);
right = digitalRead(rightButtonPin);
if (left == HIGH and right == HIGH) {
buttonsPressed = 2;
} else {
if (left == HIGH and right == LOW){
buttonsPressed = 1;
} else {
if (left == LOW and right == HIGH){
buttonsPressed = 1;
} else {
buttonsPressed = 0;
}
}
}
if (buttonsPressed== 2) {
if (prevButtonsPressed < 2) { // the number pressed has just changed
twoButtonsStartTime = millis();
}
if (millis() - twoButtonsStartTime >= millisForOneStep) {
myservo.write(100);
}
else {
myservo.write(120);
}
}
prevButtonsPressed = buttonsPressed;
}
I realized I, like always, REALLY over complicated this. I can't thank you all enough for the countless headaches you've saved me.
P.S. Am I supposed to resolve this or something?