Led activating sequentially

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
vetenskapsman
 
Posts: 1
Joined: Fri Mar 18, 2011 11:44 am

Led activating sequentially

Post by vetenskapsman »

Hi!

We are stuck in our science project and we are in desperate need of your help! We need to be able to sequentially control eight LEDs using an Arduino Uno. The problem is we have no idea of how to write a suitable code. The LEDs are to be activated in intervals with specific time for on/off for each one. In the first sequence the LEDs must have a special timing unlike the following which will have the same. We have read about delay, loop and interrupt but are unsure of how to use them to fit our purpose.

Best regards

User avatar
Franklin97355
 
Posts: 23939
Joined: Mon Apr 21, 2008 2:33 pm

Re: Led activating sequentially

Post by Franklin97355 »

Start off by writing down what you want to happen in as much detail as you can then take chunks of that and write code that will accomplish that. When you have a piece of code load and test it and make changes if it does not do what you need. Work in small segments, test often.

User avatar
len17
 
Posts: 394
Joined: Sat Mar 14, 2009 7:20 pm

Re: Led activating sequentially

Post by len17 »

There are a few ways to do what you want, but...
vetenskapsman wrote: In the first sequence the LEDs must have a special timing unlike the following which will have the same.
That seems to fit with the Arduino's setup() and loop() functions - setup() only runs once at startup, so put the first LED sequence there, and put the other sequence in loop() so it runs repeatedly.

The code to light LEDs sequentially would look something like this:

Code: Select all

digitalWrite(ledpin1, HIGH);
delay(time1);
digitalWrite(ledpin1, LOW);
digitalWrite(ledpin2, HIGH);
delay(time2);
digitalWrite(ledpin2, LOW);
// etc.
Look at the Arduino tutorials on this site. I think there's one that turns multiple LEDs on & off.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”