Blinking LED help!

Hi everyone,

I’m new to the Arduino board. I am currently experimenting with it. I am having trouble with a small program that I wrote, hope you guys can help. The purpose of this program is to make 4 LEDs blinking fast in a circle pattern for 10 rounds. Then slow it down. Repeat. However, when it slows down it doesn’t go back to blinking fast again. It just keep slowing down until it comes to a complete stop.

int pin12 = 12;
int pin11 = 11;
int pin10 = 10;
int pin9 = 9;
int timer = 100;
int count = 0;
int maxcount = 10;
int countdown = 0;

void setup(){

  pinMode(pin12, OUTPUT);
  pinMode(pin11, OUTPUT);
  pinMode(pin10, OUTPUT);
  pinMode(pin9, OUTPUT);

void loop() {

   if (count < maxcount)
     count = count + 1;          
     count = 0;
     if (countdown = 0) {
       countdown = 1;
     else {countdown = 0;}
   if (countdown = 1) 
   {timer = timer + 25;
   else {timer = timer - 100;}

   digitalWrite(pin9, HIGH);
   digitalWrite(pin9, LOW);

   digitalWrite(pin10, HIGH);
   digitalWrite(pin10, LOW);

   digitalWrite(pin12, HIGH);
   digitalWrite(pin12, LOW);

   digitalWrite(pin11, HIGH);
   digitalWrite(pin11, LOW);

if ( countdown = 1) … you mean to have a “==” there.
That will get you to your next bug. (timer will go down by 100 each time into negative numbers, causing huge delays or near zero delays depending how delay() is written.)

You may wish to put in some serial printing as debugging info while you work out the logic…

 Serial.print(" countdown=")
 Serial.print(" timer=");

… click the little rectangle with a lollypop sticking out of the top in the toolbar to get the serial monitor running after you download your program.

Thanks Jim,

I got the program to work now. As for the serial.print command that you mention I was wondering how do you use that in the program. I included the snipet of codes you wrote into my program and I open up the serial monitor, but I don’t see anything displaying on the screen. I was wondering if you could explain how it works. Thanks for the help again.

In your setup() function, add this


The 19200 is just a baud rate, which can be set in the dropdown box that appears when you click the serial monitor (lolipop) button. That should make the commands Jim gave send output.

Thanks for the help libhart. Got it working.