new to programming, how would i combine scripts?

hey guys, im totally new to arduino, ive played with changing values in the example scripts to alter the affects on my circuits, but i want to combine two example scripts, to learn how i would do such a thing in my own scripts.

basically i want to combine something like the array script, and the loop script, they both use 6 leds so the circuit is already set up for it, but i want to go between the scripts, for example: show the array script for 2 cycles, and then the loop script for 2 cycles, rinse and repeat

ive done a little coding in a game called "garrys mod" and im thinking this might consist of an if statement, and a value which counts up on each loop of the script and then the if statement would switch between the scripts and then set the value to 0 when the value reaches a certain number

am i on the right lines?

Cmon this is easy!:smiley: Yes a if..else statement works fine or you could use the switch case statement.

Ex:

switch (Hello) {
    case 1:
      //do something when Hello equals 1
      break;
    case 2:
      //do something when Hello equals 2
      break;
    default: 
      // if nothing else matches, do the default
      // default is optional
  }

So basically when the variable hello = 1, the arduino executes whats in the case 1. You could use the line hello++ to increment "hello" by one when you want the second case to happen.

am i on the right lines?

Without seeing the two scripts that work separately, and your attempt to combine them, how can we say?

I think he means the two led scripts example that come with the arduino. So it should be pretty straightforward.

I think he means the two led scripts example that come with the arduino. So it should be pretty straightforward.

Certainly it should be straightforward. But, lots of examples come with the Arduino IDE. We don't know which two OP is trying to combine, or how they have been mashed up.

We can't really help until we know that.

show the array script for 2 cycles, and then the loop script for 2 cycles

What i guessed, its the arrays example and the forloopiteration.

Theelectronicguy:
Cmon this is easy!:smiley: Yes a if..else statement works fine or you could use the switch case statement.

Ex:

switch (Hello) {

case 1:
      //do something when Hello equals 1
      break;
    case 2:
      //do something when Hello equals 2
      break;
    default:
      // if nothing else matches, do the default
      // default is optional
  }




So basically when the variable hello = 1, the arduino executes whats in the case 1. You could use the line hello++ to increment "hello" by one when you want the second case to happen.

it probably is easy, but ive never had a strong hand in coding, am i right to assume theres an example script which explains switches? thanks for the advice too :smiley:

PaulS:

I think he means the two led scripts example that come with the arduino. So it should be pretty straightforward.

Certainly it should be straightforward. But, lots of examples come with the Arduino IDE. We don't know which two OP is trying to combine, or how they have been mashed up.

We can't really help until we know that.

sorry about that, i thought i sounded more clear than that, Theelectronicguy got it spot on, i was refering to the two example scripts int he library as he pointed out, but they were just example scripts