Hi there,
first post around here!!
I'm having some issues with a debounce program that i want to write.
Let me explain first how it should work.
I want an array of 4 bools to get everything i want from a future debounce function.
bool 0 = input, coupled to a input pin
bool 1 = input detected, will be reset after some time after bool 0 is released
bool 2 = just a single cycle pulse
bool 3 = output that should flip flop each time bool 1 becomes high
Now i have two major issues with my scetch.
1 bool 2 does not seem to come high at all.
2 the timer function does not work at all.
I suspect it has something to do with scopes, but i can't figure it out by myself.
Some tips, or a little help would be very welcome!!!
Thanks!
int input = 22;
byte button [4] = {0, 0, 0, 0};
int i = 0;
unsigned long startTime = 0;
const unsigned long delayTime = 100;
void setup() {
pinMode (input, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
button [0] = !digitalRead (input);
if (button [0] == true) {
button [1] = true;}
if (button [1] == true){
i++;
if (i == 1){
button [3] = !button[3];}
if (i == 2){
button [2] == true;}}
//else {button [2] == false;}
if (( button [1] == true) && (button [0] == false)){
startTime = millis();
if (( millis() - startTime) > delayTime){
Serial.println(startTime);
button [1] = false;
i = 0;}}
Serial.print (button[1]);
Serial.print (" ");
Serial.print (button[2]);
Serial.print (" ");
Serial.print (button[3]);
Serial.print (" ");
Serial.println(i);
}