Problem with 16x4 LCD displaying on row 2

Hello guys, I am trying to use the code bellow to display 2 graphic bars, one on line 0 and another on line 2 with some text on line 1 and another text on line3. I cannot get the bar graph to work on line 2 nomatter what I do.

If I put the two garph bars one on line 0 and the other one on line 1 or line 3 it works but not on line 2.

I really need it to be on line 2.

Anyone could help me?

Thanks
Filipe

/* 
* Simple 2-channel VU-meter with peak detect - by mira308sw - 2013
* a crazy sketch for 16x2 lcd display
*/

#include <LiquidCrystal.h>

/* Modify the pin number below to meet your board
*/
#define IN_LEFT    0  // analog input for left channel
#define IN_RIGHT   1  // analog input for right channel

LiquidCrystal lcd(7,8,9,10,11,12);  

/* Other minor configurable value
*/
#define T_REFRESH    100            // msec bar refresh rate
#define T_PEAKHOLD   3*T_REFRESH    // msec peak hold time before return

/* local variable
*/
byte  fill[6]={ 0x20,0x00,0x01,0x02,0x03,0xFF };      // character used to fill (0=empty  5=full)
byte  peak[7]={ 0x20,0x00,0x04,0x05,0x06,0x07,0x20 }; // character used to peak indicator
int   lmax[2];                                        // level max memory
int   dly[2];                                         // delay & speed for peak return

void  bar  ( int row,int lev )
{
  lcd.setCursor( 0,row );
  lcd.write( row ? 'R' : 'L' );
  for( int i=1 ; i<16 ; i++ )
  {
    int f=constrain( lev      -i*5,0,5 );
    int p=constrain( lmax[row]-i*5,0,6 );
    if( f )
      lcd.write( fill[ f ] );
    else
      lcd.write( peak[ p ] );
  }
  if( lev>lmax[row] )
  {
    lmax[row] = lev;
    dly[row]  = -(T_PEAKHOLD)/T_REFRESH;                // Starting delay value. Negative=peak don't move
  }
  else
  {
    if( dly[row]>0 )
      lmax[row] -= dly[row]; 

    if( lmax[row]<0 )
      lmax[row]=0;
    else
      dly[row]++;
  }
}

byte block[8][8]=
{
  { 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10 },  // define character for fill the bar
  { 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18 },
  { 0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C },
  { 0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E },

  { 0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08 },  // define character for peak level
  { 0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04 },
  { 0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02 },
  { 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01 },
};

void  setup  ( void )
{
  lcd.begin( 16,4 );
  for( int i=0 ; i<8 ; i++ )
    lcd.createChar( i,block[i] );
}

long  lastT=0;

void  loop  ( void )
{
  if( millis()<lastT )
    return;
  lastT += T_REFRESH;    
  int anL = map( sqrt( analogRead( IN_LEFT  )*16 ),0,128,0,80 );  // sqrt to have non linear scale (better was log)
  int anR = map( sqrt( analogRead( IN_RIGHT )*16 ),0,128,0,80 );
  bar( 0,anL );

  lcd.setCursor(0, 1);
  lcd.print("Direct PWR ");

  bar( 2,anR );

  lcd.setCursor(0, 3);
  lcd.print("Refl PWR ");  

 
}

The 16x4 devices use a different memory addressing scheme for the lower two rows of characters compared to the 20x4 devices. For all the gory details follow the LCD Addressing link at http://web.alfredstate.edu/weimandn.

Unfortunately the LiquidCrystal library does not deal with that difference and hence the cursor positioning does not work correctly on the lower two rows. This could account for your problem in displaying the graph on row 2 but I am surprised that it doesn't also affect row 3.

Don