Pages: [1]   Go Down
Author Topic: AnalogButtons.h library and Issues with 12 button custom Keypad  (Read 903 times)
0 Members and 1 Guest are viewing this topic.
Pakistan
Offline Offline
Sr. Member
****
Karma: 6
Posts: 357
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello to all... I have made a custom Keypad with 12 buttons. I am using  AnalogButtons.h library by Neil DUdman.
http://www.arduino.cc/playground/Code/AnalogButtons
As per the procedure given by Neil i enabled the
Code:
 //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:
#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.begin(9600);
  Serial.println("Testing your Analog buttons");
  
  analogButtons.addButton(b1);
  analogButtons.addButton(b2);
  analogButtons.addButton(b3);
  analogButtons.addButton(b4);
  analogButtons.addButton(b5);
   analogButtons.addButton(b6);
  analogButtons.addButton(b7);
  analogButtons.addButton(b8);
  analogButtons.addButton(b9);
  analogButtons.addButton(b10);
   analogButtons.addButton(b11);
  analogButtons.addButton(b12);
 }
 
void loop()
{  
  // To check values when button are pressed
  analogButtons.checkButtons();
  
  // 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);
}
« Last Edit: September 04, 2011, 11:32:50 am by Khalid » Logged


Pakistan
Offline Offline
Sr. Member
****
Karma: 6
Posts: 357
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

As i have no good experience with C++, I have just checked the AnalogButtons.h file and found:'
Code:
*/

#include <WProgram.h>

#define MAXBUTTONS 10

class Button
{
public: 
  int id;
  int BUTTON_L;
  int BUTTON_H;   

Should i change the value of
Code:
#define MAXBUTTONS 10
to
Code:
#define MAXBUTTONS 12
Logged


Pages: [1]   Go Up
Jump to: