ArduinoGeneral

New library for LCD & Keypad Shield

userHead fj604 2010-12-12 01:16:29 71744 Views29 Replies
I made a new library for the LCD & Keypad Shield - it is available from DFRobot.com as DFR0009:

[url=http://www.dfrobot.com/index.php?route=product/product&keyword=lcd&category_id=0&product_id=51]http://www.dfrobot.com/index.php?route=product/product&keyword=lcd&category_id=0&product_id=51[/url]

The one recommended to use with these is LCD4Bit_mod, but the standard LiquidCrystal library works just as well with modified pin numbers - use this:

[code]LiquidCrystal(8, 9, 4, 5, 6, 7) [/code]

This library inherits LiquidCrystal and adds another method: button - to read button pushed on a keypad.

I have also included an example - a simple number guessing game that you can play with the Up, Down and Select buttons.

Download the library at the URL below or from the attachment:
[url=http://uploading.com/files/d56136e9/LCDKeypad.zip/]LCDKeypad.zip - 2.7 KB[/url]

Any comments will be appreciated.
2012-06-25 11:42:38 Hi Yawstick,


I have just downloaded the library files with no problem.
As for the sketch not compiling, have you placed the library files into a folder in: Arduino/libraries/DFR_Key


You need to place the files for the library into that specific folder, otherwise it will not work.



userHeadPic Hector
2012-06-25 11:42:38 Hi Yawstick,


I have just downloaded the library files with no problem.
As for the sketch not compiling, have you placed the library files into a folder in: Arduino/libraries/DFR_Key


You need to place the files for the library into that specific folder, otherwise it will not work.



userHeadPic Hector
2012-06-25 11:42:38 Hi Yawstick,


I have just downloaded the library files with no problem.
As for the sketch not compiling, have you placed the library files into a folder in: Arduino/libraries/DFR_Key


You need to place the files for the library into that specific folder, otherwise it will not work.



userHeadPic Hector
2012-06-23 20:22:58 Nothing but problems trying to use some of  the example code for the LCD keypad.

The LCD keypad library zip file is corrupt and cant open it.

Get errors trying to compile the key grab library v2 in both version 0022 and version 1

Did get the guessing game working but its the only thing so far.
userHeadPic yawstick
2012-06-23 20:22:58 Nothing but problems trying to use some of  the example code for the LCD keypad.

The LCD keypad library zip file is corrupt and cant open it.

Get errors trying to compile the key grab library v2 in both version 0022 and version 1

Did get the guessing game working but its the only thing so far.
userHeadPic yawstick
2012-06-23 20:22:58 Nothing but problems trying to use some of  the example code for the LCD keypad.

The LCD keypad library zip file is corrupt and cant open it.

Get errors trying to compile the key grab library v2 in both version 0022 and version 1

Did get the guessing game working but its the only thing so far.
userHeadPic yawstick
2012-04-25 00:32:13 @dweston is the library working for you now?  I have moved on to Arduino 1.0.
Leigh.
userHeadPic wa5znu
2012-04-25 00:32:13 @dweston is the library working for you now?  I have moved on to Arduino 1.0.
Leigh.
userHeadPic wa5znu
2012-04-25 00:32:13 @dweston is the library working for you now?  I have moved on to Arduino 1.0.
Leigh.
userHeadPic wa5znu
2012-04-01 15:20:30 We have updated the library to work with both the old and new IDEs


[url=http://www.dfrobot.com/index.php?route=product/product&path=53&product_id=51]http://www.dfrobot.com/index.php?route=product/product&path=53&product_id=51[/url]
userHeadPic Hector
2012-04-01 15:20:30 We have updated the library to work with both the old and new IDEs


[url=http://www.dfrobot.com/index.php?route=product/product&path=53&product_id=51]http://www.dfrobot.com/index.php?route=product/product&path=53&product_id=51[/url]
userHeadPic Hector
2012-04-01 15:20:30 We have updated the library to work with both the old and new IDEs


[url=http://www.dfrobot.com/index.php?route=product/product&path=53&product_id=51]http://www.dfrobot.com/index.php?route=product/product&path=53&product_id=51[/url]
userHeadPic Hector
2012-04-01 14:18:33 Hi, what version of the IDE are you using?


You might try using Version 0022 of the IDE.


I just tried and it wont compile on IDE V1 but it will on V0022
userHeadPic Hector
2012-04-01 14:18:33 Hi, what version of the IDE are you using?


You might try using Version 0022 of the IDE.


I just tried and it wont compile on IDE V1 but it will on V0022
userHeadPic Hector
2012-04-01 14:18:33 Hi, what version of the IDE are you using?


You might try using Version 0022 of the IDE.


I just tried and it wont compile on IDE V1 but it will on V0022
userHeadPic Hector
2012-03-22 22:41:41 [quote="wa5znu"]
I've added a backlight method, to control the backlight on pin 10.
It would be nice if someone would consider adding this.

It adds one new method
  void backlight(byte level);
as in
  lcd.backlight(128);

[url=http://pastebin.com/qKQ2fnYc]http://pastebin.com/qKQ2fnYc[/url]

[/quote]

wa5znu I have attempted to carefully add the backlight method code you point to in your link above into the LCDKeypad.cpp and LCDKeypad.h files derived from the original LCDKeypad.zip library.

The result is:
[code]/*
  LCDKeypad.cpp
*/

#include "WProgram.h"

// include this library's description file

#include <LiquidCrystal.h>
#include "LCDKeypad.h"

#define BACKLIGHT 10

LCDKeypad::LCDKeypad() : LiquidCrystal(8, 9, 4, 5, 6, 7)
{
  pinMode(BACKLIGHT, OUTPUT);
  backlight(255);
}

int LCDKeypad::button()
{
  static int NUM_KEYS=5;
  static int adc_key_val[5] ={ 
    30, 150, 360, 535, 760    };
  int k, input;
  input=analogRead(0);
  for (k = 0; k < NUM_KEYS; k++)
  {
    if (input < adc_key_val[k])
    {
      return k;
    }
  }
  if (k >= NUM_KEYS)
    k = -1;    // No valid key pressed
  return k;
}

void LCDKeypad::backlight(byte level)
{
  analogWrite(BACKLIGHT, level/4);
}[/code]

and

[code]/*
  LCDKeypad.h
*/

// ensure this library description is only included once
#ifndef LCDKeypad_h
#define LCDKeypad_h

// library interface description
#define KEYPAD_NONE -1
#define KEYPAD_RIGHT 0
#define KEYPAD_UP 1
#define KEYPAD_DOWN 2
#define KEYPAD_LEFT 3
#define KEYPAD_SELECT 4

class LCDKeypad: public LiquidCrystal
{
  public:
    LCDKeypad();
    int button();
    void backlight(byte level);
};

#endif

[/code]

I then opened the GuessTheNumber.pde example, without modifying it in any way, in Arduino 1.0.

But when I attempt to verify the code I encountered an error as follows:

"In file included from LCD_GuessTheNumber.cpp:2:
/Users/.....  /Arduino/arduino-1.0/libraries/LCDKeypad/LCDKeypad.h:22: error: 'byte' has not been declared
"

Could you advise what I might be missing?
userHeadPic dweston
2012-03-22 22:41:41 [quote="wa5znu"]
I've added a backlight method, to control the backlight on pin 10.
It would be nice if someone would consider adding this.

It adds one new method
  void backlight(byte level);
as in
  lcd.backlight(128);

[url=http://pastebin.com/qKQ2fnYc]http://pastebin.com/qKQ2fnYc[/url]

[/quote]

wa5znu I have attempted to carefully add the backlight method code you point to in your link above into the LCDKeypad.cpp and LCDKeypad.h files derived from the original LCDKeypad.zip library.

The result is:
[code]/*
  LCDKeypad.cpp
*/

#include "WProgram.h"

// include this library's description file

#include <LiquidCrystal.h>
#include "LCDKeypad.h"

#define BACKLIGHT 10

LCDKeypad::LCDKeypad() : LiquidCrystal(8, 9, 4, 5, 6, 7)
{
  pinMode(BACKLIGHT, OUTPUT);
  backlight(255);
}

int LCDKeypad::button()
{
  static int NUM_KEYS=5;
  static int adc_key_val[5] ={ 
    30, 150, 360, 535, 760    };
  int k, input;
  input=analogRead(0);
  for (k = 0; k < NUM_KEYS; k++)
  {
    if (input < adc_key_val[k])
    {
      return k;
    }
  }
  if (k >= NUM_KEYS)
    k = -1;    // No valid key pressed
  return k;
}

void LCDKeypad::backlight(byte level)
{
  analogWrite(BACKLIGHT, level/4);
}[/code]

and

[code]/*
  LCDKeypad.h
*/

// ensure this library description is only included once
#ifndef LCDKeypad_h
#define LCDKeypad_h

// library interface description
#define KEYPAD_NONE -1
#define KEYPAD_RIGHT 0
#define KEYPAD_UP 1
#define KEYPAD_DOWN 2
#define KEYPAD_LEFT 3
#define KEYPAD_SELECT 4

class LCDKeypad: public LiquidCrystal
{
  public:
    LCDKeypad();
    int button();
    void backlight(byte level);
};

#endif

[/code]

I then opened the GuessTheNumber.pde example, without modifying it in any way, in Arduino 1.0.

But when I attempt to verify the code I encountered an error as follows:

"In file included from LCD_GuessTheNumber.cpp:2:
/Users/.....  /Arduino/arduino-1.0/libraries/LCDKeypad/LCDKeypad.h:22: error: 'byte' has not been declared
"

Could you advise what I might be missing?
userHeadPic dweston
2012-03-22 22:41:41 [quote="wa5znu"]
I've added a backlight method, to control the backlight on pin 10.
It would be nice if someone would consider adding this.

It adds one new method
  void backlight(byte level);
as in
  lcd.backlight(128);

[url=http://pastebin.com/qKQ2fnYc]http://pastebin.com/qKQ2fnYc[/url]

[/quote]

wa5znu I have attempted to carefully add the backlight method code you point to in your link above into the LCDKeypad.cpp and LCDKeypad.h files derived from the original LCDKeypad.zip library.

The result is:
[code]/*
  LCDKeypad.cpp
*/

#include "WProgram.h"

// include this library's description file

#include <LiquidCrystal.h>
#include "LCDKeypad.h"

#define BACKLIGHT 10

LCDKeypad::LCDKeypad() : LiquidCrystal(8, 9, 4, 5, 6, 7)
{
  pinMode(BACKLIGHT, OUTPUT);
  backlight(255);
}

int LCDKeypad::button()
{
  static int NUM_KEYS=5;
  static int adc_key_val[5] ={ 
    30, 150, 360, 535, 760    };
  int k, input;
  input=analogRead(0);
  for (k = 0; k < NUM_KEYS; k++)
  {
    if (input < adc_key_val[k])
    {
      return k;
    }
  }
  if (k >= NUM_KEYS)
    k = -1;    // No valid key pressed
  return k;
}

void LCDKeypad::backlight(byte level)
{
  analogWrite(BACKLIGHT, level/4);
}[/code]

and

[code]/*
  LCDKeypad.h
*/

// ensure this library description is only included once
#ifndef LCDKeypad_h
#define LCDKeypad_h

// library interface description
#define KEYPAD_NONE -1
#define KEYPAD_RIGHT 0
#define KEYPAD_UP 1
#define KEYPAD_DOWN 2
#define KEYPAD_LEFT 3
#define KEYPAD_SELECT 4

class LCDKeypad: public LiquidCrystal
{
  public:
    LCDKeypad();
    int button();
    void backlight(byte level);
};

#endif

[/code]

I then opened the GuessTheNumber.pde example, without modifying it in any way, in Arduino 1.0.

But when I attempt to verify the code I encountered an error as follows:

"In file included from LCD_GuessTheNumber.cpp:2:
/Users/.....  /Arduino/arduino-1.0/libraries/LCDKeypad/LCDKeypad.h:22: error: 'byte' has not been declared
"

Could you advise what I might be missing?
userHeadPic dweston
2011-12-07 14:59:13 Cool! thanks for your contributions.




I have added the library to the product page.
userHeadPic Hector
2011-12-07 14:59:13 Cool! thanks for your contributions.




I have added the library to the product page.
userHeadPic Hector