Really newbish question...

Hey, I am working on my lil random machine that I am making for fun, and I need some help with syntax. I am extremely new (about 2 days into circuitry design, layout, and programming) so I am really green.

I am trying to digitalWrite on all pins in a series except for 1 pin (ill name it light), and then I want I want that 1 pin to either go up in series or down in series according to another switch I have. (that one works :P)

I am wondering if this would work... (shorthanding to the part that doesn't work)

int light = 12;

digitalWrite((5, 12) - light, HIGH);
delay(250);
digitalWrite(light, LOW);
light = light + 1;
if (light == 13) {(light = 5);}

I am brand new to programming so I almost expect that line of code to be wrong, specifically the "((5,12) - fred," part, but I am not sure what is the correct syntax... help would be awesome. :slight_smile:

Lol

"specifically the "((5,12) - fred," part,"

I mean to say "((5,12) - light,"

Here, I will write out what I would like it to do longhand.

int light = 12;

void setup()
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);

void loop()
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(light, LOW);
delay(250);
light = light - 1;
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(12, HIGH);
digitalWrite(light, LOW);

etc.. etc...

Since the pin numbers are consecutive, you can use for loops:

void setup()
{
   for(int i=5; i<=12; i++)
   {
      pinMode(i, OUTPUT);
   }
}
void loop()
{
   for(int i=5; i<=12; i++)
   {
      if(i == light)
        digitalWrite(i, LOW);
      else
        digitalWrite(i, HIGH);
   }
   delay(250);
   light--;
   if(light < 5)
      light = 12;
}

Thank you very much!

Is there any guides online that you know of that go into further detail about the for command?? I really like to know why everything works together :slight_smile: and I am not familiar with the for command (I didn't even know it existed hehe). I will also do research on my own. Thank you again :slight_smile:

Is there any guides online that you know of that go into further detail about the for command?

Here's one:
http://arduino.cc/en/Reference/For
Lots more useful information if you check out:

Google is your friend.

Search on 'C for' and learn all about it.