Arduino Forum

Using Arduino => Installation & Troubleshooting => Topic started by: Khalid on Sep 04, 2011, 06:28 pm

Title: AnalogButtons.h library and Issues with 12 button custom Keypad
Post by: Khalid on Sep 04, 2011, 06:28 pm
Hello to all... I have made a custom Keypad with 12 buttons. I am using  AnalogButtons.h library by Neil DUdman. (
As per the procedure given by Neil i enabled the
Code: [Select]
 //AnalogButtons::configure(ANALOG_PIN); //delay(1000); line of code and found the Minimum and Maximum values of all 12 buttons and modified the sketch accordingly for all 12 buttons.

Then i commented the above line , Compile the sketch uploaded into Arduino and checked in the serial monitor for the the button pressed. Buttons from 1 to 10 when pressed giving me indication on the Serial monitor but button 11 and 12 gives no indication.
Following is the complete sketch. Please help.
Code: [Select]
#include "AnalogButtons.h"

#define ANALOG_PIN 0

// A call back function that you pass into the constructor of AnalogButtons, see example
// below. Alternitivly you could extend the Button class and re-define the methods pressed()
// or held() which are called
void handleButtons(int id, boolean held)
 if (held) {
   Serial.print("button id="); Serial.print(id); Serial.println(" was pressed and held");
 } else{
   Serial.print("button id="); Serial.print(id); Serial.println(" was pressed only");

AnalogButtons analogButtons(ANALOG_PIN, 30, &handleButtons);
Button b1 = Button(1, 47,50);
Button b2 = Button(2, 84, 87);
Button b3 = Button(3, 127, 130);
Button b4 = Button(4, 194, 198);
Button b5 = Button(5, 303,309);
Button b6 = Button(6, 405, 410);
Button b7 = Button(7, 546, 549);
Button b8 = Button(8, 690, 695);
Button b9 = Button(9, 780,785);
Button b10 = Button(10, 864, 870);
Button b11 = Button(11, 925, 935);
Button b12= Button(12, 955, 965);
// Default hold duration is 1 second, lets make it 5 seconds for button5
//Button b5 = Button(5, 860, 875, 5);

void setup()
 Serial.println("Testing your Analog buttons");

void loop()
 // To check values when button are pressed
 // To configure the MAX/Min values for each
 // Button, uncomment this line, make sure you've called Serial.begin(9600);
 // Then in turn hold town each botton, noting the max/min values
 //AnalogButtons::configure(ANALOG_PIN); //delay(1000);
Title: Re: AnalogButtons.h library and Issues with 12 button custom Keypad
Post by: Khalid on Sep 04, 2011, 08:17 pm
As i have no good experience with C++, I have just checked the AnalogButtons.h file and found:'
Code: [Select]

#include <WProgram.h>

#define MAXBUTTONS 10

class Button
  int id;
  int BUTTON_L;
  int BUTTON_H;   

Should i change the value of
Code: [Select]
#define MAXBUTTONS 10 to
Code: [Select]
#define MAXBUTTONS 12