View Single Post
  #6   Spotlight this post!  
Unread 16-02-2008, 22:55
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,740
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: Programing IR board problem

Maybe something, such as,
Code:
static int counter = 0;
...
 
 //**** Check the IR Sensor for a new command
  sensorReading  = PORTJ>>4;  // Combined digital inputs 15-18
 
  if (latch == 1) 
  {
    if (sensorReading == 0)
    {
      latch = 0; // Take only the 1st reading to avoid being caught by a half & half state of the IR sensor
    }
  }
  else if (sensorReading != 0)
  {
       latch = 1;
 
       if (sensorReading == 8)      IR_cmd = 1;
       else if (sensorReading == 4) IR_cmd = 4;
       else if (sensorReading == 2) IR_cmd = 2;
       else if (sensorReading == 1) IR_cmd = 3;
 
        printf("IR_cmd = %d\r\n", IR_cmd);
}
 
if (IR_cmd == 0)
{
 counter = 0;  // To initialize counter whenever cmd 1 finishes executing
}
 
 switch(IR_cmd)
 {
    case 0:
          break;
 
    case 1:
        if (counter <= 50)
        {
            pwm01 = pwm02 = 255;
            counter++;
        }
        else
        {
           IR_cmd = 0;  // So cmd 1 won't try to repeat itself
            pwm01 = pwm02 = 127;
        }
        break;
 
    case 2:
       pwm01 = 200;
       pwm02 = 55;
       break;
 
    case 3:
        pwm01 = 55;
        pwm02 = 200;
        break;
 
    case 4:
        relay1_fwd = 1;
    }
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 16-02-2008 at 23:06.