Go Down

Topic: odd variable problem. (Read 606 times) previous topic - next topic

mmmlinux

Jun 16, 2008, 06:31 am Last Edit: Jun 16, 2008, 06:33 am by mmmlinux Reason: 1
i am writeing a function that will PWM fade a nixie tube between 2 digits. the problem i have is not actually with this, as it works per my debugging statements. but for what ever reason, when i call tube() the seccond time it wont work unless the int i give it is a actual number not a variable. tube(5); works not tube(foo);. this is annoying becuase the first time i call it with a variable it works. if any one knows why this maybe, please let me know. i am including fade() and tube().

void fade()
{
 int a;
 int start = number;
 int end = temp;
 for(int i=0;i<128;i++)
 {
  a=i;
  for(int c=0;c<128;c++)
  {
   if(a>0)
   {
    a--;
    tube(end); //this one works
    digitalWrite(12,HIGH);
   }
   if(a==0)
   {
    tube(start); //this one doesnt unless i give it something like tube(5); start could equal 5 it doesn't matter.
    digitalWrite(12,LOW);
   }
  }
 }
}
void tube(int digit)
{
 if (digit == 0)
 {
   digitalWrite(2, LOW);
   digitalWrite(3, LOW);
   digitalWrite(4, LOW);
   digitalWrite(5, LOW);
 }
// i cut some bits out for posting, its just more of this with different BCD commands. if any one knows a better way let me know
 if (digit == 9)
 {
   digitalWrite(2, HIGH);
   digitalWrite(3, LOW);
   digitalWrite(4, LOW);
   digitalWrite(5, HIGH);
 }
 return;
}

bens

Can you be more explicit than just saying "it doesn't work"?  What is "number"?

- Ben

mmmlinux

number and temp are global variables. well, it simply does not run the function, it just skips over it.

bens

#3
Jun 16, 2008, 07:26 am Last Edit: Jun 16, 2008, 07:27 am by bens Reason: 1
Have you tried putting debug print statements inside tube()?  Does your program use a lot of RAM (i.e. do you have any large arrays)?

- Ben

mmmlinux

well, debug statements shouldnt be needed inside of tube, being that it would just change the state of the nixie tube. and no, no large arrays. there is not really much more to the code then what you see. the rest is just serial data parsing.

bens

You are claiming that tube isn't getting executed when you pass it a variable but it is when you pass it a literal.  Obviously this makes no sense, so why not put a debug statement in there to figure out exactly what is going on?  My guess is that your global "number" has a bad value.

- Ben

mmmlinux

#6
Jun 16, 2008, 07:52 am Last Edit: Jun 16, 2008, 07:56 am by mmmlinux Reason: 1
well, apparently it is something weird about the number variable. i have no idea why though. as it is set then given to tube as an argument earlier in the program, then isn't touched again. EDIT: i found the problem, i got lazy and was using number to store serial data.

Go Up