Combining these two sketches

Hello, I need assistance with combining these two sketches. I tried to but it isn't working correctly. The color only changes on startup. In other words, every time I adjust the color I have to reset the arduino. And it doesn't go through every color, it seems to skip a few. I'm using this RGB LCD.

#1:http://www.nuelectronics.com/download/projects/lcd_smartie_v1.pde

#2:

/*
 RGB LED w/ Potentiometer
 Created 8 May 2010
 Commented by Dave a.k.a Ka0ticstyle

 */

int potpin = A2;		  // POT connected to digital pin 2 - pos/neg are left and right connections on POT
int rpin = 3;		    // Red
int gpin = 10;		   // Green
int bpin = 11;		   // Blue
float h;			   // Hue range
int h_int;			 // Hue color
int r = 0, g = 0, b = 0;	     // Default RGB values

int val = 0;			 // Set POT value to default 0

void h2rgb(float h, int& R, int& G, int& B); // Instantiate h2rgb and it's variables  a.k.a  Hue to RGB

void setup()			  // Run once, when the sketch starts
{
  Serial.begin(9600);	    // Begin the output of data to serial
}


void loop()			   // Run over and over again
{
  val = analogRead(potpin);    // Read the pin and display the value
  h = ((float)val)/1024;	 // Get the range. pot value / 1024
  h_int = (int) 360*h;	   // Get the color hue by multiplying by 360

  h2rgb(h,r,g,b);		  // Call the h2rgb function passing it the hue value

  Serial.print("POT value: ");
  Serial.print(val);	     // Pot value
  Serial.print(" = Hue of ");
  Serial.print(h_int);	   // Color Hue value
  Serial.print(" degrees. RGB values: ");
  Serial.print(r);		 // Red value
  Serial.print(" ");
  Serial.print(g);		 // Green value
  Serial.print(" ");
  Serial.println(b);	     // Blue value

  analogWrite(rpin, r);	  // Changes red led
  analogWrite(gpin, g);	  // Changes green led
  analogWrite(bpin, b);	  // Changes blue led
  
}

void h2rgb(float h, int& R, int& G, int& B) {

  // Used HSV --> RGB function
  // HSV - Hue, Saturation, Value
  // RGB - Red, Green, Blue - example (255,255,255)
  // Function below does a bunch of math to convert HSV values to RGB
  int var_i;
  float S=1, V=1, var_1, var_2, var_3, var_h, var_r, var_g, var_b;

  if ( S == 0 )			     //HSV values = 0 ÷ 1
  {
    R = V * 255;
    G = V * 255;
    B = V * 255;
  }
  else
  {
    var_h = h * 6;
    if ( var_h == 6 ) var_h = 0;	//H must be < 1
    var_i = int( var_h ) ;		//Or ... var_i = floor( var_h )
    var_1 = V * ( 1 - S );
    var_2 = V * ( 1 - S * ( var_h - var_i ) );
    var_3 = V * ( 1 - S * ( 1 - ( var_h - var_i ) ) );

    if	( var_i == 0 ) {
	var_r = V     ;
	var_g = var_3 ;
	var_b = var_1 ;
    }
    else if ( var_i == 1 ) {
	var_r = var_2 ;
	var_g = V     ;
	var_b = var_1 ;
    }
    else if ( var_i == 2 ) {
	var_r = var_1 ;
	var_g = V     ;
	var_b = var_3 ;
    }
    else if ( var_i == 3 ) {
	var_r = var_1 ;
	var_g = var_2 ;
	var_b = V     ;
    }
    else if ( var_i == 4 ) {
	var_r = var_3 ;
	var_g = var_1 ;
	var_b = V     ;
    }
    else			 {
	var_r = V     ;
	var_g = var_1 ;
	var_b = var_2 ;
    }

    R = (1-var_r) * 255;			//RGB results = 0 ÷ 255
    G = (1-var_g) * 255;
    B = (1-var_b) * 255;
  }
}

I tried to include my attempt but it exceeded the post length limit. If you wish to see it let me know and I'll post it afterwards.

Can't help without seeing your code, not someone else's.

Here's my attempt: [tpcode]#include &lt;avr/interrupt.h&gt; #include &lt;avr/io.h&gt; #include &quot;LCD4Bi - f94baa53
(It's too long to post here)

ISR(TIMER2_OVF_vect) {  


  TCNT2  = 6;
  update_adc_key();
}

...

void update_adc_key(){
  int adc_key_in;
  char key_in;
  byte i;

  adc_key_in = analogRead(0);
  key_in = get_key(adc_key_in);
  for(i=0; i<NUM_KEYS; i++)
  {
    if(key_in==i)  //one key is pressed 
    { 
      if(button_count[i]<DEBOUNCE_MAX)
      {
        button_count[i]++;
        if(button_count[i]>DEBOUNCE_ON)
        {
          if(button_status[i] == 0)
          {
            button_flag[i] = 1; // pressed state flag ON
            button_status[i] = 1; //button debounced to 'pressed' status
          }
        }
      }
    }
    else // no button pressed
    {
      if (button_count[i] >0)
      {  
        button_count[i]--;
        if(button_count[i]<DEBOUNCE_OFF){
          button_status[i]=0;   //button debounced to 'released' status
        }
      }
    }

    // output button pressed state
    if(button_flag[i]==1)
    {
      button_flag[i]=0;      // clear flag to avoid repeats
      Serial.print('A'+i,BYTE);   // output MO button code

    }
  }

}

First problem. An ISR is supposed to be short. Yours isn't. It calls update_adc_key which does a lot of stuff including Serial.print. This isn't a good idea.

The rest is pretty confusing. However I don't see any obvious problems. Apart from this maybe:

void loop(){

  val = analogRead(potpin);    // Read the pin and display the value

The timer interrupt can fire at any time, and it does an analogRead. However the main loop might also be doing an analogRead. I don't know if analogRead is re-entrant, probably not. So this won't help.

Thanks for the help. I wrote neither sketch. And unfortunately I am still too inexperienced to understand most of the code. They both work fine alone, but when I try to combine them, I get problems. If it's not possible I guess I'll just have to use two arduinos.

Well you need to give more details than that. I'm not too good at just guessing at your intentions. You can combine them by putting them through the blender I suppose.

Can you describe your hardware setup, what you are trying to achieve, and in what way it isn't happening?

I'm using the arduino to interface LCD Smartie with my RGB LCD. This is the site I followed. They sell this LCD shield, I used it's schematic to connect my LCD to the arduino.

The second sketch is to adjust the RGB backlight on the LCD with a potentiometer. Both of these sketches work fine on their own. My problem is that when I combined the two sketches, the color only changes on startup. In other words, every time I adjust the color I have to reset the arduino for it to take effect. And it doesn't go through every color, it seems to skip a few.