Trouble with for loop to add 1 plus random value issue

See below

What Arduino (or compatible) board are you using?

What ‘pin’ is your LED on? Better yet, provide complete code!

lloyddean:
What Arduino (or compatible) board are you using?

What ‘pin’ is your LED on? Better yet, provide complete code!

Arduino nano 3.0

In this line for(int i = 0; i < mixer; i+diming++) the diming is not being added so the length of the for(loop is to long. Or something else is off. But my loops are coming out at like 20 seconds +.

int led = 11;
int burst; //short burst of light
int big;
int srumble;
int brumble;
int mixer;
int diming;
int delaymix;
int dark;

void setup() {                
 
  pinMode(led, OUTPUT);     
}


void loop() {
  burst = random(10,500); //Short burst of lightning value
  big = random(1000,4000);//long burst of lightning value
  srumble = random(10,40);//lower light lighting value
  brumble = random(10,255);//higher light lightning value
  mixer = random(burst,big);//random pick of short or long bursts of lightning
  dark = random(1,12);
  
  delay(dark);//delay of darkness
  
  for(int i = 0; i < mixer; i+diming++)
  {
  diming = random(10,500);
  analogWrite(led, random(srumble,brumble));//Turn on LED for short or long burst
  delay(diming);//random number delay to remain at set brightness value
}
  digitalWrite(led, LOW);    // turn the LED off
}
i+diming++

i never get’s incremented, so

i < mixer;

Will never evaluate false;

So how can I increment i by diming+1 each time.

mcreefer: So how can I increment i by diming+1 each time.

If you had a variable i, how would you add diming + 1 to it?

I have 2 varuables in use here. One is set above the the for(int loop. I will call it var1. and the second is inside the for(int loop. I will call it var2

I want to do something like this for

(int i = 0; i < var1; i++)
But I want i to increase by 1+var2
for(int i = 0; i < mixer; i+1+var2)

I know thats wrong but I’m just trying to be clear.

Arrch:

mcreefer: So how can I increment i by diming+1 each time.

If you had a variable i, how would you add diming + 1 to it?

You have it dead on except I don't think my i is variable in this case. Dimming is the variable and yes I want to add diming+1 to i.

mcreefer:
So how can I increment i by diming+1 each time.

So here you have i starting at zero and increasing by i+diming every time until i >= mixer.
Also every time around, diming is post-incremented (1 added -after- it is used.

  for(int i = 0; i < mixer; i+diming++)

Looks to me like i+diming++ should simply be diming++.

GoForSmoke:

mcreefer:
So how can I increment i by diming+1 each time.

So here you have i starting at zero and increasing by i+diming every time until i >= mixer.
Also every time around, diming is post-incremented (1 added -after- it is used.

  for(int i = 0; i < mixer; i+diming++)

Looks to me like i+diming++ should simply be diming++.

Tried this and its still not coming back false. Just staying in one loop
The value of mixer is anywhere from 10 to 4000. The value of dimming is anywhere from 10 to 500. So if i is only increased by one and the delay(diming) could be as high as 500 that would be 4000x500mS since it would only be adding 1 to i every loop.

Now let say the mixer came up at 4000. and my dimming came up at 500 the first loop. I would want the value of i to increase to 501. Then the next loop dimming came up at 100. I would want the value of i to increase from 501 to 602.

Does that make since?>

I did a test and set mixer to 500 and dimming to 100-500 on random. The light still won't turn off. For some reason its not adding a value to i or maybe its just chainging the value of i each time and not adding the next value to the old one and just replacing it.

Yeah because what I wrote is wrong. The last term needs to be i += diming++. Sorry, my bad.

OMG ITS PERFECT!!! I just about tossed my laptop off my lap jumping for joy.... You guys have no idea how much I value this. This blows away anyone elses lightning mode. I'll post a video and code in a second.

http://www.youtube.com/watch?v=d_XacUxhpeY

So would this be correct to add another var?

for(int b = 0; b < 600000; b += var1++ + var2++)

Yup. The expression doesn't even have to involve b, you can change b inside the loop.

But why ask when you have an Arduino?

For looser loop forms check out while and do-while.

Thanks again for your help.