Pages: [1]   Go Down
Author Topic: odd variable problem.  (Read 575 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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;
}
« Last Edit: June 15, 2008, 11:33:04 pm by mmmlinux » Logged

Las Vegas, NV
Offline Offline
God Member
*****
Karma: 0
Posts: 507
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

- Ben
Logged


0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Las Vegas, NV
Offline Offline
God Member
*****
Karma: 0
Posts: 507
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: June 16, 2008, 12:27:14 am by bens » Logged


0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Las Vegas, NV
Offline Offline
God Member
*****
Karma: 0
Posts: 507
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged


0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: June 16, 2008, 12:56:42 am by mmmlinux » Logged

Pages: [1]   Go Up
Jump to: