Hi, I am trying to understand a code that I got online, this is going pretty good, giving the fact that I don't understand programing like a pro, but I got to something that I don't understand quite well, I saw the tutorial on the arduino lessons on using a function to blink a led without delay, and I think that is what I am using, but I still don't get how to change the blinking time.
Brief explanation, the code is from a game to simulate a bomb to use in airsoft games, and in the middle of the game, if the "bomb" is armed the red led blinks. I modified the circuit and in the end of the led is a led chaser with 10 leds, but the blink signal is too fast to have the desired effect.
The person who wrote the code left some notes behind (nice guy), and the part that says led blinking goes like this:
}
//Led Blink
timeCalcVar=(millis()- iTime)%1000;
if(timeCalcVar >= 0 && timeCalcVar <= 40)
{
digitalWrite(REDLED, HIGH);
if(soundEnable)tone(tonepin,tonoActivada,largoTono);
}
if(timeCalcVar >= 180 && timeCalcVar <= 220){
digitalWrite(REDLED, LOW);
}
Can anyone explain to me how this works and how can I modify it?
Thanks a lot 
I am trying to understand a code that I got online...
Don't waste your time. By your own admission the code is junk.
Break time into 1000ms blocks...
timeCalcVar=(millis()- iTime)%1000;
Within each 1000ms block, for the first 41ms ensure REDLED is HIGH and optionally continuously restart generating a tone...
if(timeCalcVar >= 0 && timeCalcVar <= 40)
{
digitalWrite(REDLED, HIGH);
if(soundEnable)tone(tonepin,tonoActivada,largoTono);
}
Within each 1000ms block, ensure REDLED is LOW between 180 and 220...
if(timeCalcVar >= 180 && timeCalcVar <= 220)
{
digitalWrite(REDLED, LOW);
}
There are three problems with that code. The first is that the state of REDLED between 41 and 179 then between 221 and 999 is essentially undefined. The end result is that REDLED will be HIGH from 0 through 179 then LOW from 180 through 999 which is not clear from the code.
The second is that tone could be called continuously between 0 and 40. If it is a click / scratch noise will very likely be the result.
The third is that the code will go haywire as (millis() - iTime) approaches the wrap.
Ok thanks, now I think I have a starting point. 
In your IDE popdown File menu is Examples->02.Digital->BlinkWithoutDelay
It shows how to make things happen on time.
You can change the blink any way you can THINK of how.
But to save a lot of time, learn the basic language/tools and bookmark good pages to refer to later.
The big hard part is how to always know how long it's been between 2 times even across the rollover.
The Arduino trick is to use unsigned long to store time. When you subtract any unsigned long from any other, you get the difference as if you subtract start time from end time. So subtract start from end and it will always be right.
It's like a round clock. If I start at 11 and end at 2, that's clock 2 - 11 = 3 hours.
Arduino unsigned long time variables (the returns of millis() and micros()) count to over 4 billion.
Arduino millis() counts milliseconds from 0 to 49.71-some DAYS, the longest interval it can time.
Here is code that involves a button/jumper and Arduino led13 and timing. It doesn't do just what you want but it's got parts that can that work together well. I just dunno if you're ready.
// All you need to do this example is an Arduino and a button on pin 2.
// Push the button once, led lights after delay. Again, led turns off.
// Button is debounced and wired directly to ground. The button can be a
// jumper from pin 2 grounded on USB connector. Tested with jumper.
// By GoForSmoke for free public use. Using Arduino 1.0.5-r2
const byte ledPin = 13; // this is the onboard led pin
const byte buttonPin = 2;
byte setLedPin = 0;
const unsigned long ledDelay = 1000UL; // blink interval
unsigned long ledDelayStart = 0U; // 16 bit blink (on or off) time ms
// button variables
byte buttonRead; // wired for pullup -- if down then LOW, if up then HIGH
byte lastButtonRead = HIGH; // so debounce knows previous read
byte checkDebounce = 0; // only checks decounce after every button pin change
byte lastButtonState = 0; // last stable button state
byte buttonState = 0; // stable button state
// 0 = button is up after debounce
// 1 = button is down after debounce
// button debounce timing variables
const unsigned long debounceDelayMs = 100UL;
unsigned long debounceStartMs;
unsigned long msNow;
byte processState = 0; // 1st press to start, 1st release, 2nd press to stop, 2nd release
void setup()
{
Serial.begin( 115200 );
pinMode( ledPin, OUTPUT ); // default is LOW
pinMode( buttonPin, INPUT_PULLUP ); // my button connects to ground, not 5V
// however that means that when the button is pressed the pin is LOW.
}
void loop() // make sure that loop() runs fast and stays in the "now".
{
// BUTTON CODE BLOCK, it handles debouncing.
// the task is to set the variable buttonState when a Stable Button State is reached.
// other sensor code could change the same variable if desired
// read the pin which may be changing fast and often as the button bounces
buttonRead = digitalRead( buttonPin ); // momentary state
msNow = millis();
if ( buttonRead != lastButtonRead )
{
debounceStartMs = msNow;
checkDebounce = 1;
}
else if ( checkDebounce )
{
if ( msNow - debounceStartMs >= debounceDelayMs ) // stable button state achieved
{
buttonState = !buttonRead; // mission accomplished, button is stable
// note that buttonState is opposite buttonRead
checkDebounce = 0; // stop debounce checking until pin change
}
}
lastButtonRead = buttonRead;
//
// End of the BUTTON CODE BLOCK
//==================================================================================
// CONTROL CODE BLOCK that uses buttonState and processState
if ( lastButtonState != buttonState )
{
lastButtonState = buttonState;
Serial.println( F( "============================================================" ));
Serial.print( F( "processState " ));
Serial.print( processState );
Serial.print( F( " buttonState " ));
Serial.println( buttonState );
Serial.print( F( " millis " ));
Serial.println( msNow );
Serial.println( F( "============================================================" ));
switch ( processState )
{
case 0: // waits for press without blocking
if ( buttonState == 1 ) // button is pressed
{
processState = 1;
setLedPin = 1; // start led blink task
ledDelayStart = millis(); // led blink control value set in the control block
}
break;
case 1: // waits for release without blocking
if ( buttonState == 0 ) // button is released
{
processState = 2;
}
break;
case 2: // waits for press without blocking
if ( buttonState == 1 ) // button is pressed
{
processState = 3;
setLedPin = 2; // led blink control value set in the control block
}
break;
case 3: // waits for release without blocking
if ( buttonState == 0 ) // button is released
{
processState = 0; // start over
}
break;
}
}
// End of the CONTROL CODE
//==================================================================================
// LED BLINK CODE BLOCK
if ( setLedPin == 1 )
{
if ( millis() - ledDelayStart >= ledDelay )
{
digitalWrite(ledPin, HIGH );
setLedPin = 0;
}
}
else if ( setLedPin == 2 )
{
digitalWrite(ledPin, LOW );
setLedPin = 0;
}
// End of the LED BLINK CODE
//==================================================================================
// Want to add serial commands and args input?
// this is a good spot. Serial is so slow it can usually go last.
}
GoForSmoke:
In your IDE popdown File menu is Examples->02.Digital->BlinkWithoutDelay
It shows how to make things happen on time.
You can change the blink any way you can THINK of how.
But to save a lot of time, learn the basic language/tools and bookmark good pages to refer to later.
The big hard part is how to always know how long it's been between 2 times even across the rollover.
Thanks, that is a lot of info to take in you are right, but I now have surely the info to study more about this!!
Cheers 
I can demonstrate unsigned binary rollover in text using a 4-bit example if you need. The principle is the same for 8, 16 and 32 bit unsigned integers. An unsigned 0 minus an unsigned 1 equals and unsigned maximum value. Maximum value + 1 = 0. Unsigned is like a round clock.
There's this way to write code that setup() and loop() facilitate. That is to write tasks inside of loop and inside of their triggers. Some tasks trigger on time and some tasks trigger on pin changes and some tasks set variables that other tasks trigger on, it lets you break a job down to parts to handle every step and set those parts running and that's how to code a real time capable controller.