Lighting test code question

Do you have a question on how to do something.
Ask in here.
Post Reply
User avatar
joshlawless
Posts: 138
Joined: Thu May 23, 2013 2:52 pm

Lighting test code question

Post by joshlawless »

Can you see a reason why this isn't setting "b" equal to 0 to 4095 and back to 0 by steps of 1? This test code won't work for me (although if I pass a value in the code, e.g., CustomExpansion(0x41, 0, 2048), it works fine).

Code: Select all

//global variable
 int a = 0;
 int b = 0;


void loop()
{
    a = a++;
    if (a<4096) {b = a;}
    else {b = 8191 - a ;}
    if (a==8192) {
      a = 0; 
      b = 0;
    }
  
     CustomExpansion(0x41, 0, b);
}
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Lighting test code question

Post by rimai »

Did you change the code original post?
This code works.
The original one doesn't.
Roberto.
User avatar
joshlawless
Posts: 138
Joined: Thu May 23, 2013 2:52 pm

Re: Lighting test code question

Post by joshlawless »

I did, but didn't think helped. I changed the "if (a=8192)" to "if (a==8192)", but didn't see any improvement. I think because it takes so long to iterate through one loop(), I couldn't tell that the intensity was increasing (changing the increment from 1 to 128 allows it to ramp each channel up and down much faster).

If I try to run the whole ramp up and ramp down inside of one loop() (e.g., with a for () loop), the controller crashes and gets stuck in a reboot loop. I gather there's some limit on how much can be accomplished in one iteration through the main loop. Can you recommend any good learning resources on the Arduino environment that would be helpful for learning this kind of thing?
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Lighting test code question

Post by rimai »

Yes, we have a 1s watchdog timer setup.
Roberto.
Post Reply