ir function stuck

hi there.my first post, i hope i'm in the right place.
just started using arduino for my graduation project at my university.
i like to manage my own stuff, so i searched and searched and i put learned the language a bit, and put together a little program.
basically what it does, is control a stepper. the setup is an easydriver, stepper motor, ir sensor with remote control and a light sensor.using the stepper library, controlling is a charm.
the problem is,that i have now put it all in a single program so they work together and i stumbled upon a fault.i have to say i'm pretty much stuck.
i'm finding this difficult to explain, so i'll try my best.
when my program is doing something, it's reading the changes in lighting, but when when the motor is not moving, it just gets stuck inside the getIRKey function.when i press any buton on the remote, the light sensor changes it's value also starting to read again.
i have deleted everything not important, like the stepper motor controls, to get the code it's simplest form possible. any help is appreciated! thank you

#include <LiquidCrystal.h>     /
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);   
#define LIGHT_PIN A0                   
#define IR_PIN 12                      
#define LED_PIN 13                     

int desired = 100;          
int button;                 
int start_bit = 2200;     
int bin_1 = 1000;          
int bin_0 = 400;          

void setup()                
{
  pinMode(LED_PIN, OUTPUT);       
  digitalWrite(LED_PIN, LOW);     
  pinMode(IR_PIN, INPUT);        
      
  lcd.begin(16, 2);               
  lcd.setCursor(0, 0);            
  lcd.print("Desired:");           
  lcd.setCursor(10,0);        
  lcd.print(desired);              
  lcd.setCursor(15,0);
  lcd.print("%"); 
  lcd.setCursor(0, 1);
  lcd.print("Actual:");  
  lcd.setCursor(15,1);        
  lcd.print("%");           
}                                

void loop()                     
{
  lcd.setCursor(10,0);
  lcd.print(desired);
  lcd.print("  ");                
  light();                            
  getIRKey();
}                                   

int light()
{
  int val_light = analogRead(LIGHT_PIN);              
  val_light = map(val_light, 0, 1023, 0, 100);       
  lcd.setCursor(10, 1);                               
  lcd.print(val_light,DEC);                          
  lcd.print("  ");                                    
  return val_light;                                  
}

void getIRKey() 
{
  int data[12];                                         
  int i;                                                
  while (pulseIn(IR_PIN, HIGH) < start_bit);            
  for(i = 0 ; i < 11 ; i++)                             
    data[i] = pulseIn(IR_PIN, HIGH);                     
  for(i = 0 ; i < 11 ; i++)                             //Parse them
  {	    
    if(data[i] > bin_1)                                 //is it a 1?
      data[i] = 1;
    else if(data[i] > bin_0)                            //is it a 0?
      data[i] = 0;
    else
      break;                                        //Flag the data as invalid; I don't know what it is! Return -1 on invalid data
  }
  int result = 0;
  for(i = 0 ; i < 11 ; i++)                            
      if(data[i] == 1) result |= (1<<i);
                                  
      switch(result)                        
      {
      case 64:                            
        desired=100;                       
        break;                                 
      case 1088:                           
        desired=0;                          
        break;      
      case 128:                           
        if (desired < 100) {  desired=desired++; }
        break;
       case 1152:                          
        if (desired > 0) {desired=desired--;}
        break;
      }
   return; 
  }
  for(i = 0 ; i < 11 ; i++)                            
      if(data[i] == 1) result |= (1<<i);

You are missing curly braces. Without them, to us mere mortals, the intent is not clear.

      case 64:                            
        desired=100;                       
        break;                                 
      case 1088:                           
        desired=0;                          
        break;      
      case 128:                           
        if (desired < 100) {  desired=desired++; }
        break;
       case 1152:                          
        if (desired > 0) {desired=desired--;}
        break;

Magic numbers suck.

  lcd.print(desired);
  lcd.print("  ");                
  light();                            
  getIRKey();

Print the value modified by the getIRKey() function, then call the getIRKey() function. Do you not see a problem with this order?

i have deleted everything not important, like the stepper motor controls, to get the code it's simplest form possible.

So, in this code, there is no motor moving/not moving, so that problem has gone away. What problem does this code have?

Ken Shirrif wrote a nice IR library, using interrupts. Why are you not using it?

thank you for your reply.i copied this code as it was from sparkfun.worked in a standalone version, using just the remote, and didnt think it had any flaws. can't do anything about the numbers.they were 144 145 146 etc originally,but since my remote control went haiwyre, those are the pulses it receives.

i will look into that with the value.ty

and lastly, i tried using the library, but even in it's untouched mode, i.e. copy paste it gave me errors.

  while (pulseIn(IR_PIN, HIGH) < start_bit);

Will wait until you get a pulse so you will not be moving your motor when you are waiting for a pulse.

You will need to interleave checking for pulses with updating your stepper for this to work.

HTH.

1 looked into the value and function calling, not a problem, since desired is a global variable

2 even with while (pulseIn(IR_PIN, HIGH) < start_bit); deleted, still does the same thing

what do you mean by interleave?

UPDATE: PaulS thank you! i'm sorry.i downloaded the irremote found on ken's website, but didnt check that there is a new version for arduino 1.0. compiled the demo program.works.i'm implementing it now into mine.
i'll be back with results

UPDATE2: THANK YOU PAUL.played around with irremote, works like a charm! problem solved!