u8glib (u8gilb_64128N) with push button sketch, changing to "u8g"

Hello,

I am using the (1.6.4) version of the Arduino IDE and also I am using a library from here and constructor U8GLIB_64128N u8g (LCD_CD, LCD_DAT, LCD_RES) on my monitor which I have matched it up to device "u8g_dev_st7565_64128n_hw_spi" on the u8glib supported devices page.

This constructor has run the included test sketches to display "hello world!" and other test sketches successfully.

I have a board based on a DUE which has thus far behaved identically and I have some buttons on the board I want to test with a my LCD monitor.

My question is how I can use the U8glib constructor with the test sketch located here to work on my Arduino Due board?

I am getting confused about renaming "lcd" to "u8g" and when this is or is not allowed. The current errors seem to want lcd changed to u8g. This code from the original sketch is commented out here. And the pins have been changed to pins which have worked with the test other test sketches.

/* YourDuino.com Example Software Sketch
 TEST LCD Display with Pushbuttons
 Based on code by Mark Bramwell and debouncing by peterstrobl
 terry@yourduino.com */

/*-----( Import needed libraries )-----*/
//#include <LiquidCrystal.h>
#include "U8glib.h"
#define  LCD_DAT         63  // data / instruction register select
#define  LCD_RES         51  // reset
#define  LCD_CS          50  // chip select

U8GLIB_64128N u8g(50, 63, 51);

/*-----( Declare objects )-----*/
//LiquidCrystal lcd(8, 9, 4, 5, 6, 7); //These are the pins used on this shield

/*-----( Declare Constants )-----*/
#define btnRIGHT  71
#define btnUP     23
#define btnDOWN   24
#define btnLEFT   70
#define btnSELECT 42
#define btnNONE   43

/*-----( Declare Variables )-----*/
int lcd_key       = 0;
int adc_key_in    = 0;
int adc_key_prev  = 0;

void setup()   /*----( SETUP: RUNS ONCE )----*/
{
  u8g.setFont(u8g_font_unifont);
  u8g.setColorIndex(1);
  
  lcd.begin(16, 2);              // start the lcd object
  
  lcd.setCursor(0,0);
  lcd.print("Push A Button!"); 
  
  lcd.setCursor(10,1);
  lcd.print("A="); // For display of A0 Analog values from button push
  
}/*--(end setup )---*/

void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{
  lcd.setCursor(7,1);            // move cursor to second line "1" and 7 spaces over
  lcd.print(millis()/1000);      // display seconds elapsed since power-up

  adc_key_prev = lcd_key ;       // Looking for changes
  lcd_key = read_LCD_buttons();  // read the buttons

  if (adc_key_prev != lcd_key)
  {
    lcd.setCursor(12,1); 
    lcd.print("    ");         // Blank, display returned Analog value of button
    lcd.setCursor(12,1); 
    lcd.print(adc_key_in); 
  }

  lcd.setCursor(0,1);            // move to the begining of the second line

  switch (lcd_key)               // depending on which button was pushed, we perform an action
  {
  case btnRIGHT:
    {
      lcd.print("RIGHT ");
      break;
    }
  case btnLEFT:
    {
      lcd.print("LEFT   ");
      break;
    }
  case btnUP:
    {
      lcd.print("UP    ");
      break;
    }
  case btnDOWN:
    {
      lcd.print("DOWN  ");
      break;
    }
  case btnSELECT:
    {
      lcd.print("SELECT");
      break;
    }
  case btnNONE:
    {
      lcd.print("NONE  ");
      break;
    }
  }/* --(end switch )-- */

}/* --(end main loop )-- */

/*-----( Declare User-written Functions )-----*/

int read_LCD_buttons()
{
  adc_key_in = analogRead(0);      // read the value from the sensor 
  delay(5); //switch debounce delay. Increase this delay if incorrect switch selections are returned.
  int k = (analogRead(0) - adc_key_in); //gives the button a slight range to allow for a little contact resistance noise
  if (5 < abs(k)) return btnNONE;  // double checks the keypress. If the two readings are not equal +/-k value after debounce delay, it tries again.
  // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
  // we add approx 50 to those values and check to see if we are close
  if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
  if (adc_key_in < 50)   return btnRIGHT;  
  if (adc_key_in < 195)  return btnUP; 
  if (adc_key_in < 380)  return btnDOWN; 
  if (adc_key_in < 555)  return btnLEFT; 
  if (adc_key_in < 790)  return btnSELECT;   
  return btnNONE;  // when all others fail, return this...
}

My error messages
Arduino: 1.6.4 (Windows 8), Board: "Arduino Due (Native USB Port)"

sketch_dec16a.ino: In function 'void setup()':
sketch_dec16a:36: error: 'lcd' was not declared in this scope
sketch_dec16a.ino: In function 'void loop()':
sketch_dec16a:48: error: 'lcd' was not declared in this scope
Multiple libraries were found for "U8glib.h"

Used: C:\Users\Javier\Documents\Arduino\libraries\U8glib

Not used: C:\Users\Javier\Documents\Arduino\libraries\arduino_95561

'lcd' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

Any help would be appreciated, Thank you!

sketch_dec16a:36: error: 'lcd' was not declared in this scope

Well, where is it declared?
The lcd with global scope I can see is commented-out.

Hello AWOL,

The LiquidCrystal lcd line which looks like this was commented out with high hopes

/*-----( Declare objects )-----*/
//LiquidCrystal lcd(8, 9, 4, 5, 6, 7); //These are the pins used on this shield

The new u8glib constructor line was intended to take it's place

U8GLIB_64128N u8g(50, 63, 51);

With the u8g constructor line in the sketch, I tried to change things like lcd.begin to u8g.begin with no luck. If just that change to just the ".begin" is made the error codes look like this

Arduino: 1.6.4 (Windows 8), Board: "Arduino Due (Native USB Port)"

sketch_dec17b.ino: In function 'void setup()':
sketch_dec17b:36: error: no matching function for call to 'U8GLIB_64128N::begin(int, int)'
sketch_dec17b.ino:36:18: note: candidate is:
In file included from sketch_dec17b.ino:8:0:
C:\Users\Javier\Documents\Arduino\libraries\U8glib/U8glib.h:82:13: note: uint8_t U8GLIB::begin()
     uint8_t begin(void) { is_begin = 1; return u8g_Begin(&u8g); }
             ^
C:\Users\Javier\Documents\Arduino\libraries\U8glib/U8glib.h:82:13: note:   candidate expects 0 arguments, 2 provided
sketch_dec17b:38: error: 'lcd' was not declared in this scope
sketch_dec17b.ino: In function 'void loop()':
sketch_dec17b:48: error: 'lcd' was not declared in this scope
no matching function for call to 'U8GLIB_64128N::begin(int, int)'

If I am reading this error message correctly I think the u8g.begin() line is not supposed to look the way it does in my sketch. That line at the very least.

Thank you for your response!