Basic Project Question

First, I would like to say hello to everyone on the forum! I'm new to Arduino.cc forum and to working on an Arduino. I have become quite infatuated with this little chip in a very small amount of time! However, I'm working on a little something, something and I came across a little bit of an issue. Now I don't know if it's the way the Arduino board is set up or if I'm doing something wrong, this is where I'm counting on you guys to clear this up a little for me. Just to make it easy to explain, let's say I have an LED on pin# 13 and another LED on pin# 12. When I write a basic code for them to blink it seems to only alternate blinking, both LEDs will only go one speed. So say:

digitalWrite (LED, HIGH);
delay(1000);
digitalWrite (LED, LOW);
delay(1000);
digitalWrite (LED2, HIGH);
delay(50);
digitalWrite (LED2, LOW);
delay(50);

This does not work as commanded. instead LED will run correctly and than once LED is off LED2 will blink once quickly. Why is it doing this? Is the Arduino able to run a voltage through two pins at the same time? For the project I'm working on I need two 2.5v - 5v rails for it to work but I need both of them to operate on their own and provide voltage at the same time. On the one rail is a relay that I would like to have timed to go on and off using the Arduino along with powering the other side of the project. Well let me know what you guys think it could be! Thank you in advanced!

  • Peter

do you have a resistor on led2 to limit the current. I think digital pin limits are either 40 or 70mA. search the forum for more info.

I'll have to take a look into it... Thank you! Do you know anywhere that has a breakdown or specs per section of the Arduino? I was looking for something along the lines of that, but came up with nothing. I'm going to blame most of my issues to being ignorant to the Arduino. I'm sure, I will come along sooner or later. Again, thank you for the reply!

Thanks,
-Peter

Data sheet:

http://atmel.com/dyn/resources/prod_documents/8271S.pdf

More like 20 mA continuous for the pins, not 40 or 70. It's probably rebooting, or self-destructing or something.

For some reason I don't think it did this last week when I got it, I ran the same script and I don't recall it doing that. As long as I know it's not something I did, but the unit itself messing up! On the other hand I just got this thing last week!

So, I just want to verify, that the Arduino Uno, should have no problem running 2 different pins at the same time, correct?

Absolutely! If you don't exceed the electrical limits (there are limits for groups of pins too) you can have them all on at once.

Two pins driving LEDs should be fine (with, say, a 270 ohm resistor each).

http://led.linear1.org/1led.wiz

The answers given above are correct, but in your snippet,

digitalWrite (LED, HIGH);
delay(1000);
digitalWrite (LED, LOW);
delay(1000);
digitalWrite (LED2, HIGH);
delay(50);
digitalWrite (LED2, LOW);
delay(50);

you aren't driving two leds at the same time. You are switching one on for one second, then switching it off. Then, one second later, you switch the second led on for 50 milliseconds, then switch that one off. That seems to me to agree with your observed results.

Why is it doing this?

Because that is exactly what you told it to do in the code. A processor executies only one line at a time and does not move on to the next line until it has finished. Therefore delay will in effect do nothing for a set length of time. When that time is up it will go on to the next line.

Your code does exactly as it i expected to do.

Delay(xxx) is a "blocking" function.

It will delay ALL execution for XXX ms. Nothing will happen for xxx ms.

Look at the "blink without delay" sample in the playground. It will do what you want.

Also:

Oh, okay! Well thank you for clearing it up for me! So as I figured, it's just an issue with what I'm doing. I had a feeling that was the case. Thank you for the help and the links guys! You saved me from ripping out more of my hair! Thanks again!