How do i put together several programs?

Plz help!
I´m new at his and realy need some help. How do i put två programs together? I´m working with a program for a motor and light. I´m stuck at the loop :frowning:

This is how i wrote:

int motorPin = 9; // define the pin the motor is connected to
//LED Pin Variables
int ledPins = {2,3,4,5,6};

void setup()
{ pinMode(motorPin, OUTPUT);
//Set each pin connected to an LED to output mode (pulling high (on) or low (off)
for(int i = 0; i < 5; i++) //this is a loop and will repeat eight times
pinMode(ledPins*,OUTPUT); //we use this to set each LED pin to output*

  • } //the code this replaces is below*
    void loop() // run over and over again
    { motorPin = motorOnThenOff()}
    {ledPins {oneAfterAnotherLoop()} //led

void motorOnThenOff(){

  • int onTime = 2500; //the number of milliseconds for the motor to turn on for*

  • int offTime = 30000; //the number of milliseconds for the motor to turn off for*

  • digitalWrite(motorPin, HIGH); // turns the motor On*

  • delay(onTime); // waits for onTime milliseconds*

  • digitalWrite(motorPin, LOW); // turns the motor Off*

  • delay(offTime); // waits for offTime milliseconds*
    }
    // led
    void oneAfterAnotherLoop(){

  • int delayTime = 200; //the time (in milliseconds) to pause between LEDs*

  • //make smaller for quicker switching and larger for slower*

//Turn Each LED on one after another

  • for(int i = 0; i <= 7; i++){*
    _ digitalWrite(ledPins*, HIGH); //Turns on LED #i each time this runs i*_
    * delay(delayTime); //gets one added to it so this will repeat*
    * } //8 times the first time i will = 0 the final*
    * //time i will equal 7;*

//Turn Each LED off one after another
* for(int i = 7; i >= 0; i–){ //same as above but rather than starting at 0 and counting u*
* //p*
* //we start at seven and count down*
_ digitalWrite(ledPins*, LOW); //Turns off LED #i each time this runs i*
* delay(delayTime); //gets one subtracted from it so this will repeat*
* }
}*_

First, read the sticky notes which are the first two posts on this forum. They lay out the ground rules for using this forum.
Second, format your code in the Arduino IDE using Ctrl-T while your cursor is in the source code window.
Third, then post your code using the Code message icon (#).
Fourth: the code:

 for(int i = 0; i < 5; i++)       //this is a loop and will repeat eight times
      pinMode(ledPins,OUTPUT); //we use this to set each LED pin to output
  }                                   //the code this replaces is below

isn’t going to do much because you aren’t stepping through the array. Try:

 for(int i = 0; i < 5; i++)       //this is a loop and will repeat eight times
      pinMode(ledPins[i],OUTPUT); //we use this to set each LED pin to output
  }                                   //the code this replaces is below

and see if that helps.

Fifth, what are you trying to do here??

{ledPins {oneAfterAnotherLoop()}  //led

Sixth, the code:

  for(int i = 0; i <= 7; i++){
    digitalWrite(ledPins, HIGH);  //Turns on LED #i each time this runs i
    delay(delayTime);                //gets one added to it so this will repeat 
  }                                  //8 times the first time i will = 0 the final

is probably going to be a problem since you only have 5 ledPins. You have the same array issue here, too (ledPin is an array and need an index subscript here). The same problem is repeated later.

Work on these issues for now.

what I know regarding multiple program to be run simultaneously... that is not possible in arduino uno.. if u wanna to have more than one void loop(never ending loop) then go for scheduler which is supported by arduino duo........

as I am new learner ..... please excuse me if I am wrong :stuck_out_tongue:

You can't load two separate programs into an Arduino at the same time.

What you need to do is write a new program that includes the parts you need from the separate programs. There is no need to consider a scheduler - they just introduce different problems that are much more difficult to solve.

With careful planning it is easy to have an Uno manage several things at the same time.

...R

isn't going to do much because you aren't stepping through the array.

The forum software has mangled the indices into italics, they're there in the original.

Basically how you want to do this is by creating time schedules in your loop that do not affect the loop.

to run each function you made in the loop you just put them in as such and it will run :slight_smile: goodluck!

void loop()
{
 motorOnThenOff();
oneAfterAnotherLoop();
}