Go Down

Topic: Trying to solve debounce problem (Read 878 times) previous topic - next topic

fire1

Hi thanks for the reply

HazardsMind I have tried to change some mistakes were in my coding and I have done your suggestion , but still having the same problem . and I have posted the code again after fixing some problems .

Code: [Select]

/*
debounce.cpp - Library for solving debounce problem
Created by Hisham Alfadel , February 26 , 2013
Released for the public usage and I hope you enjoy with it
*/

int debounce::reset(int M){
  //Return the counter to B = 0 and LED switch it off
  Serial.println("B = 0");
  digitalWrite(ledPin,LOW);
  M = 0;
return M ;
}

int debounce::button_state( char button , int H ){
  //check the for HIGH
  if(button == '1'){
    //Serial.println("I'm here" + B );
    //check the number is less than 6
    if(H < 6){
      H = H + 1;
     Serial.println("High");
    }
  }
  if (button == '0'){
    H = reset(H);
    Serial.println("Reset");
    Serial.println(H);
  } 
  return H;
}


Code: [Select]

/*
debounce.h - Library for solving debounce problem
Created by Hisham Alfadel , February 27 , 2013
Released for the public usage and I hope you enjoy with it

This code is used to solve the problem of the debounce situation
the code will use the logarithm of :" If it's high add 1 to counter
until it's rised to Five else fall down to Zero
*/

#ifndef debounce_h
#define debounce_h

#include "Arduino.h"
//Definitions are placed here
class debounce{
public:
debounce( char button , int H);
int B = 0; //This is used for the increament
unsigned int D = 0; //This is for the serial output

}

#endif


Code: [Select]

#include <debounce.h>

const unsigned int ledPin= 13;
char button_try;
int B = 0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(ledPin,OUTPUT);
 
}

void loop() {
  // put your main code here, to run repeatedly:
  button_try=Serial.read();
  B = debounce.button_state(button_try,B); 
  //then should put here if statement to get it right
  if(B == 5){
      digitalWrite(ledPin1,HIGH);
     }
}

PaulS

Your class STILL does not have members reset() or button_state() declared. You can't implement methods that have not been declared.

And you certainly can't call them without an instance of the class.

JoshSG

Hi,
     @Fire1 I would suggest to please use or buy a Latch not the Debounce Button/Switch to avoid problem. :smiley-mr-green:

Thanks,

Josh

HazardsMind


Hi,
     @Fire1 I would suggest to please use or buy a Latch not the Debounce Button/Switch to avoid problem. :smiley-mr-green:

Thanks,

Josh

Your giving the OP, wrong information. You clearly don't know the difference between debouncing a button and latching a button. I would love to fully explain the differences in detail, but this is something you need to research for yourself, THEN come back and see if the advice your giving is correct.

OP, if you want to debounce using hardware, google button debounce hardware. It is just a simple capacitor and resistor in the proper setup.
Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Jimmy60

I don't see you reading any buttons. I see you using serial data incorrectly. You don't need to debounce this, you need to learn more about reading and handling serial input.


Go Up