0

So I found a code I would like to use and not sure how to edit the code properly.

#include <Debounce.h>

void matrix(char matrix[7]) {
  int map[10];
  map[0] = 2;
  map[1] = 3;
  map[2] = 4;
  map[3] = 5;
  map[4] = 6;
  map[5] = 7;
  map[6] = 8;
  map[7] = 9;  

  int i=0;
  for(i=0;i<=7; i++) {
   if(matrix[i] == 0x30) { // 0x31=1, 0x30=0
      Serial.println(map[i]);
      digitalWrite(map[i],LOW);
   }
   else digitalWrite(map[i],HIGH);
  }
}

void show(int number) {
  switch(number) {
    case 0:
      matrix("11111100");
      break;
    case 1:
      matrix("01100000");
      break;
    case 2:
      matrix("11011010");
      break;
    case 3:
      matrix("11110010");
      break;
    case 4:
      matrix("01100110");
      break;
    case 5:
      matrix("10110110");
      break;
    case 6:
      matrix("10111110");
      break;
    case 7:
      matrix("11100000");
      break;
    case 8:
      matrix("11111110");
      break;
    case 9:
      matrix("11110110");
      break;
    default:
      matrix("00000010");
      break;
  }
}

#define t1 13
#define t2 12

Debounce debouncert1 = Debounce( 20 , t1 ); 
Debounce debouncert2 = Debounce( 20 , t2 ); 

void setup()   {
  Serial.begin(9600); 

  // initialize the digital pin as an output:
  pinMode(13, INPUT);
  pinMode(12, INPUT);
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
}

int setCountPlus(int count){
  if(count == 9){
    count = 1;
  }
  else{
    count++;
    count %= 10;
  }
  return count;
}

int setCountMinus(int count){
  if(count==1){
    count = 9;
  }
  else{
  count--;
  count %= 10;
  }
  return count;
}

void loop()
{
  int i=-1;
  show(i);
  while(1){
    debouncert1.update();
    debouncert2.update();
    if(debouncert1.read()){
      i=setCountPlus(i);
    }
    if(debouncert2.read()){
      i=setCountMinus(i);
    }
    if(i==10){
      i=1;
    }
    show(i);
    delay(250);
  }
}

as for the errors.

sketch 65: error: 'Debounce' does not name a type
sketch 66: error: 'Debounce' does not name a type
sketch .ino: In function 'void loop()':
sketch 108: error: 'debouncert1' was not declared in this scope
sketch 109: error: 'debouncert2' was not declared in this scope

Any help would be great on fixing the code to stop getting errors.

  • Where did you believe that Debounce was supposed to be found? – Ignacio Vazquez-Abrams Dec 14 '14 at 17:29
  • You need to install the Decounce library first. – Gerben Dec 14 '14 at 18:35
1

In the description of Debounce, you'll find the hint that this library is outdated and no longer maintained.

Its successors, Bounce1 and, more recently, Bounce2 are available from a github repository by Thomas Fredericks, Bounce-Arduino-Wiring.

Instead of simply downloading and unzipping the archive to ${HOME}/sketchbook/libraries, you might want to consider that this is the right moment to get familiar with git repositories as an easily updatable source for third-party libraries.

Supposed that you're on a GNU/Linux system with git installed, you would

cd /${HOME}/sketchbook/libraries
git clone https://github.com/thomasfredericks/Bounce-Arduino-Wiring.git

to obtain a clone of the necessary data.

If the name of the directory of the library contains dashes (-), you'll have to change this name: remove the dashes or replace them with underscores (_). Names with dashes aren't valid!

Once in a while, you would change to the directory of the respective library and simply run git pull to update your local copy to the latest version of the repository.

1

Depending on the switch type: -SPDT (SIngle Pole Double Throw) - You would use a Cross Coupled NAND Gates (Flip Flop, Set Reset) This will set true to the side it sees power at from the switch and if it bounces it can't change state until the switch touch the other contact.

-SPST (Single Pole Single Throw) - You can use a software debounce where you would detect a signal and then wait for 10ms then read again and if there is a signal still, it is a debounced signal. --OR-- You can use capacitors to help extend the life of a signal.

so debounce code

bool sw13=false;
bool sw12=false;
while(1){
if(digitalRead(13)==HIGH && !sw13){
  delay(20); //Delay For 20ms
  if(digitalRead(13)==HIGH){
    i=setCountPlus(i);
    sw13=true;
  }
}else{
    sw13=false;
}
if(digitalRead(12)==HIGH && !sw12){
  delay(20); 
  if(digitalRead(12)==HIGH){
    i=setCountMinus(i);
    sw12=true;
  }
}else{
    sw12=false;
}
if(i==10){
  i=1;
}
//show(i);
delay(250);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.