Pages: [1]   Go Down
Author Topic: How to change loop or create a second loop  (Read 416 times)
0 Members and 1 Guest are viewing this topic.
Slovenia
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi. I'm new at arduino and programming smiley I wanna to learn it so i wrote a simple digital output for two leds to  blink on and off in 1 second delay. I wanna add a third led to blink independent on those two in loop, but i don't know how to do it  smiley-confuse


Tnx for help in advance smiley
Logged

USA, FL
Offline Offline
God Member
*****
Karma: 14
Posts: 689
A life? Where can I download one of those?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How to use this forum

We would have to see your code.  Please, post it in code tags.
Logged

//LiNK

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26496
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There's a very simple example of how to blink a LED without using "delay()" in the examples in the IDE.
You can extend the technique to several LEDs, but I advise you to start with just two.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Slovenia
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
int led1 = 0;
int led2 = 1;
int led3 = 2;

void setup()
{
  pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
}

void loop()
{
  digitalWrite(led1, HIGH);
  delay(1000);
 
  digitalWrite(led1, LOW);
 
  digitalWrite(led2, HIGH);
  delay(1000);
 
  digitalWrite(led2, LOW);
  delay(1000);
  digitalWrite(led3, HIGH);
  digitalWrite(led3, LOW);
}
« Last Edit: April 03, 2013, 01:10:41 pm by primoz-2 » Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 118
Posts: 4337
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Please edit that post, select the code and click the code tag button (# above the smileys)

Have you looked at the BlinkWithoutDelay example as suggested ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

New Jersey
Offline Offline
Faraday Member
**
Karma: 70
Posts: 3734
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Use of delay will prevent you doing what you're trying to do. AWOL's advice will take you right to the solution though.
Logged

Slovenia
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Tnx for answers! Awol i don't understand what u mean with: without using "delay()" in the examples in the IDE. I just delete delay();  or how? Sorry i'm newbe smiley
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26496
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Look at the blink without delay example in the IDE.
It performs a slow flash of a LED without calling delay().
Play around with the example, and/or have a look at Nick Gammon's blink tutorial.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Slovenia
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok i will  smiley-razz Tnx again for help smiley-wink
Logged

Pages: [1]   Go Up
Jump to: