Pin isolation...

So, I am a total newbie when it comes to working with any language other that html. Plus, I just bought by first Deumilanove today, so this is the first time I’ve really sat down with the Arduino language. So, the logic of it makes sense to me. I can find my way about and see (kind of) what is doing what. But I’m totally unfamiliar with the commands and the syntax and actually writing anything that actually works. As such, I have the following problem: I started from the basic Blink tutorial and managed to succeed in getting a single led to blink from pin 13. Then I added in a couple of lines to add in a second led off pin 12. I want to be able to have each pin blink individually and at different rates, with the ultimate aim of having a full array of leds blinking separately. How, then, do I isolate each pin within the code and set its parameters individually?

Here’s what I’ve got so far…

int ledPin = 13;
int ledPin2 = 12;
int value = LOW;
long previousMillis = 0;
long interval = 1000;

void setup()
pinMode(ledPin, OUTPUT);
pinMode(ledPin2, OUTPUT);


void loop()

if (millis() - previousMillis > interval) {
previousMillis = millis();

if (value == LOW)
value = HIGH;
value = LOW;

digitalWrite(ledPin, value);
digitalWrite(ledPin2, value);

The lines in red are the ones I’ve added. I’ve seen a couple of people using ‘for’ commands, but I’m not sure how those work exactly.

Another question along the same lines is: how would I set the init value for pin 12 as HIGH? I tried to insert a an init value2 and just copy the rest of the code (inserting value2 where appropriate), but it didn’t seem to like that very much.

Any help would be much appreciated.

Does this do as described?

const unsigned int INTERVAL1 = 1000;//this is a constant and can not be assigned a new value
const unsigned int INTERVAL2 = 1000;//this is a constant and can not be assigned a new value

int ledPin1 = 13; //LED connected to pin 13
int ledPin2 = 12; //LED connected to pin 12
boolean ledState1 = LOW; //store the state of ledPin1
boolean ledState2 = HIGH; //store the state of ledPin2

long previousMillis1 = 0;//used to store the time the previous state-toggle happened
long previousMillis2 = 0;//used to store the time the previous state-toggle happened

void setup()
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
digitalWrite(ledPin1, ledState1);
digitalWrite(ledPin2, ledState2);

void loop()
//is there INTERVAL since the last state-toggle?
if (millis() - previousMillis1 > INTERVAL1) {
previousMillis1 = millis(); //log time

//invert the state of the ledState1
if (ledState1 == LOW){
ledState1 = HIGH;
} else {
ledState1 = LOW;
digitalWrite(ledPin1, ledState1);
if (millis() - previousMillis2 > INTERVAL1) {
previousMillis2 = millis(); //log time
ledState2 = !ledState2; //invert the state of ledState2 (read: ledState2 becomes the opposite of ledState2)
//write the states to the pins
digitalWrite(ledPin2, ledState2);

A version that uses Hardware Abstraction

#include <LED.h> //LED
#include <TimedAction.h> //TimedAction

LED led1 = LED(13);//LED at pin 13
LED led2 = LED(12);//LED at pin 12

TimedAction ledBlinker1 = TimedAction(1000,toggle1); //trigger blink1 every second if checked
TimedAction ledBlinker2 = TimedAction(800,toggle2); //trigger blink2 every 800 millisecond if checked

void setup(){

void loop(){
ledBlinker1.check(); //time to toggle?
ledBlinker2.check(); //time to toggle?

void toggle1(){ led1.toggle(); }
void toggle2(){ led2.toggle(); }