electronics - Arduino LED chaser freezes after a few loops? -


i using 3 led sequencer circuit below arduino uno r3.

enter image description here

led 1 connected pin 2, led 2 pin 3, led 3 pin 4. r1/r2/r3 330 ohm, 1/4 w each.

the code is:

int mypins[] = {2,3,4};           // set pin array pins 2 through 4  void setup() {     (int thispin = 0; thispin < (sizeof(mypins)); thispin++)     {         pinmode(mypins[thispin],output); // set each pin in array output mode.     } }  void loop() {     (int thispin = 0; thispin < (sizeof(mypins)); thispin++)    // loop every pin , switch on & off.     {         digitalwrite(mypins[thispin], high);  // set led on.         delay(100);                           // keep on 100 ms.         digitalwrite(mypins[thispin], low);   // set led off 50 ms , goto next one.         delay(50);     } } 

this seems work fine in begining. leds blink on/off in sequence 13 times , led connected pin 2 stays on. when re-upload sketch or click menu items on ide, loop restarts.

why happening, due noise in circuit?

p.s.: on 4th iteration of loop() seems led connected pin 4 stays on 200 ms instead of 100 ms, before 13th iteration on board tx led flashes once.

int thispin = 0; thispin < (sizeof(mypins)); thispin++ 

huh, nope. read how sizeof() operator works. want sizeof(mypins) / sizeof(mypins[0]) instead.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -