Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9147115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:54:35+00:00 2026-06-17T10:54:35+00:00

I have a project that requires eight DIFFERENT lights to cycle between on and

  • 0

I have a project that requires eight DIFFERENT lights to cycle between on and off at random times with random fade in, random fade out and random on/off durations. My strategy is to fade on, leave on for a random time, fade off, leave off for a random time, repeat. While right now I’ve got a random pin selected before each for loop, I’d like to use a for-loop to randomly choose a pin on which to run the WHOLE on/off cycle.

Here’s my pseudocode. Or maybe it IS my code.

void setup() {
    int pin = 0;
    int fadeIn = 0;
    int fadeOut = 0;
    int onDuration = 0;
    int offDuration = 0;
}
void loop() {    
pin = random(2,8)
onDuration = random(2000,15000)
    for (fadeIn=0;fadeIn<255;i++) {
        analogWrite(pin,fadeIn)
    }
delay(onDuration)
pin = random(2,8)
offDuration = random(1000,7000)
    for (fadeOut=254;fadeOut>0;fadeOut--) {
        analogWrite(pin,fadeOut)
    }
delay(offDuration)
} 

The loop (on, then off) would be one instance of a cycle. If I wanted a SECOND instance of the cycle to kick off on another pin WHILE the first cycle was running, is that something I can do programmatically? or would I need eight controllers, each fading the light in and out at the same time?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:54:36+00:00Added an answer on June 17, 2026 at 10:54 am

    In your code above, the fading in and fading out are not for a random time. Is that what you intended? If so, you’ll need to add delays at each iteration of the loops.

    Anyway, this is something you can do without 8 separate boards.

    Because it’s embedded, you can’t multithread very easily. You’ll need to implement your own task scheduler and each LED has to be thought of as its own task. Then you just keep track of the state each different LED is in (fading in, on, fading out, or off.) As you bounce between the different tasks, control each LED accordingly to the state.

    As far as a timing based task scheduler, you have different options. Perhaps the easiest is to implement a periodic timer interrupt. The AVR datasheets explain this pretty well. For Arduino, there’s some libraries you can also use. For example:
    http://playground.arduino.cc/code/timer1

    Another option is to do something similar to this:
    http://arduino.cc/forum/index.php?PHPSESSID=3e72433bc4375ee6c20d56f3998762ca&topic=5686.msg44073#msg44073

    Just some suggestions. Sounds like an interesting project. Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on a project that requires downloading a zipped file off
I have a project that requires different types of iterations. One is function recursion
I have a project that requires the following. Four arrays will be declared in
I have a project that requires some configuration files. I want to keep the
I have recently just created Java project using Eclipse that requires 2 JAR files
$(.container).hover( function(){ $(.child-1).hide(0); $(.child-2).show(0); },function(){ $(.child-1).show(0); $(.child-2).hide(0); }); A project I have requires that
I have a project that I have divided quite aggressively into different layers. I
I have a project that requires that I run some code when the application
I have a project that requires lots of image processing and wanted to add
I have a project that requires us to maintain several MySQL databases on multiple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.