Arduino micro hangs after ~20 secs [solved]

Hi,

I have an Arduino micro and use IDE 1.0.5 on Linux.

The project is about a 2x2x2 LED cube. Code so far is simple. See below.

The code lights the columns one after the other and after ~20 secs code seems to stop and all LEDs of one layer are on. Which is “impossible”.

Why does the code stop?

Thanks

Gerhard

Code:

/*

*/

int LAYER0 = 1 ;
int LAYER1 = 0 ;

int LED0 = 2 ;
int LED1 = 3 ;
int LED2 = 4 ;
int LED3 = 5 ;

int time0 ;

int len = 100 ;

// -----------------------------------------

// SETUP

void setup() {
pinMode(LED0, OUTPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LAYER0, OUTPUT);
pinMode(LAYER1, OUTPUT);

}

void loop() {

while (1) {

digitalWrite (LED0, 1) ;
digitalWrite (LED1, 0) ;
digitalWrite (LED2, 0) ;
digitalWrite (LED3, 0) ;
show() ;
digitalWrite (LED0, 0) ;
digitalWrite (LED1, 1) ;
digitalWrite (LED2, 0) ;
digitalWrite (LED3, 0) ;
show() ;
digitalWrite (LED0, 0) ;
digitalWrite (LED1, 0) ;
digitalWrite (LED2, 1) ;
digitalWrite (LED3, 0) ;
show() ;
digitalWrite (LED0, 0) ;
digitalWrite (LED1, 0) ;
digitalWrite (LED2, 0) ;
digitalWrite (LED3, 1) ;
show() ;
digitalWrite (LED0, 0) ;
digitalWrite (LED1, 0) ;
digitalWrite (LED2, 0) ;
digitalWrite (LED3, 0) ;
show() ;

}

}

void show () {

time0 = millis() ;
while (millis() - time0 < 100) {
digitalWrite (LAYER0, 1) ;
digitalWrite (LAYER1, 0) ;
delay (10) ;
digitalWrite (LAYER0, 0) ;
digitalWrite (LAYER1, 1) ;
delay (10) ;
}

}

OK,

after some more googling I found the problem.

the "int" for the time is the problem. should be "unsigned long". works now.

Gerhard

Why are you running an infinite loop inside an infinite loop()?