I am not able to create a delay using an empty FOR loop with the Duemilanove. While loop works fine. I verified this using a scope. Changing the constant values from 1 to 1000000 showed no significant change.
NOTE: If I added the simple "k=i;", to each loop, still no success. If I added readDigital(), then it does work. Has anyone had similar problems?
Thanks
/*
- Blink using while loop for delay
- The basic Arduino example. Turns on an LED on for one second,
- then off for one second, and so on... We use pin 13 because,
- depending on your Arduino board, it has either a built-in LED
- or a built-in resistor so that you need only an LED.
*/
int ledPin = 13; // LED connected to digital pin 13
void setup() // run once, when the sketch starts
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}
void loop() // run over and over again
{
// int i,j;
#define HMILS 1
#define HMICS 1
#define LMILS 1000
#define LMICS 1000
for (;
{
digitalWrite(ledPin, HIGH); // sets the LED on
//delayMicroseconds(1); // waits for a second
wait (HMILS,HMICS);
digitalWrite(ledPin, LOW); // sets the LED off
//delayMicroseconds(1000); // waits for a second
wait (LMILS,LMICS);
}
}
void wait (long mill, long mics)
{
long i,j; //,k;
//int k;
i=j=0;
while (i < mill) //for (i=0;i<mill;++i)
{
++i;
//k= i;//digitalRead(ledPin);
while (j < mics) //for (j=0;j<mics;++j)
{
++j;
//k= j; //digitalRead(ledPin);
}
}
}