Wiring Forum
http://wiring.org.co/cgi-bin/yabb/YaBB.pl
Programming Questions & Help >> Syntax >> Leds in sequence then in reverse
http://wiring.org.co/cgi-bin/yabb/YaBB.pl?num=1205876658

Message started by sidgug on 03/18/08 at 21:44:17

Title: Leds in sequence then in reverse
Post by sidgug on 03/18/08 at 21:44:17
I've had this program working well in the Arduino environment. I'm now trying to port it over to the Wiring environment but can't get it to compile.

I'm assuming parts of the code need to modified but can't work out which parts.

Can someone please look at the code and suggest what mods are required?

Thanks in advance.


int timer = 10;                                          
int pins[] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }; // an array of pin numbers
int num_pins = 12;                                       // length of the array

void setup()
{
 int i;

 for (i = 0; i < num_pins; i++)          // the array elements from 0 to num_pins - 1
   pinMode(pins[i], OUTPUT);             // set each pin as an output
}

void loop() {
 int i;
 
 for (i = 0; i < num_pins; i++) {        // loop through each pin...
   digitalWrite(pins[i], HIGH);          // turning pin on,
   delay(timer);                         // wait,
   digitalWrite(pins[i], LOW);           // turning pin off.
 }
 for (i = num_pins - 1; i >= 0; i--) {   // now in reverse
   digitalWrite(pins[i], HIGH);
   delay(timer);
   digitalWrite(pins[i], LOW);
 }
}

Title: Re: Leds in sequence then in reverse
Post by barragan on 03/19/08 at 00:21:36
"pins" is reserved in Wiring, change your array name to something else, like "myPins".
Thatīs it.

Title: Re: Leds in sequence then in reverse
Post by sidgug on 03/19/08 at 01:37:56
Thanks Hernando.

Now compiles and works perfectly!

Wiring Forum » Powered by YaBB 2.5 AE!
YaBB Forum Software © 2000-2010. All Rights Reserved.