Recommend addition to Arrays page → http://arduino.cc/en/Reference/Array
Declaring an array of instances for a class. Example → LED hardware abstraction class
//create array of LED instances
LED led[5] = {LED(8), LED(9), LED(10), LED(11), LED(12)};
A sample sketch for the Knight Rider page → http://www.arduino.cc/en/Tutorial/KnightRider
using the LED hardware abstraction library
/*
||
|| Knight Rider 4
||
|| @Sketch by Capt.Tagon showing use of LED class
|| and an array of instances thereof.
||
|| Using LED abstraction library by Alexander Brevig
|| http://www.arduino.cc/playground/Code/LED
||
|| @description
|| Demonstrates the functionality of the LED class
||
|| attributes
|| .getState() returns current LED state
||
|| digital methods
|| .on() turns LED on
|| .off() turns LED off
|| .toggle() changes current LED state
||
|| analog methods -> use on ATmega168 Arudino pins 3, 5, 6, 9, 10, and 11
|| .setValue() sets PWM 0-255 value
|| .fadeIn(millis) on PWM pin, fades in over millis time
|| .fadeOut(millis) on PWM pin, fades out over millies time
||
|| create array of LED instances and play Knight Rider with them
||
*/
#include <LED.h>
//create array of LED instances
LED led[5] = {LED(8), LED(9), LED(10), LED(11), LED(12)};
int count = 0;
int timer = 100;
void setup(){
Serial.begin(9600); // Serial debugging output
}
void loop(){
for (count = 0;count < 4;count ++) {
Serial.println(count); // print count up
led[count].on();
delay(timer);
led[count].off();
delay(timer);
}
for (count = 4;count > 0;count --) {
Serial.println(count); // print count down
led[count].on();
delay(timer);
led[count].off();
delay(timer);
}
}