Another question with classes

now that my first class (le_led) works :smiley: I would like to develop a second one which contains an array of objects of the first’s class type.

I don’t know exactly how to do it. What I want to create is an array of leds which contains 8 objects of the le_led class. I’m not sure how I should initialize the object within the array. (I post my try which doesn’t work and the class le_led)

I’m very very thankful for your help :slight_smile:

le_line.h

#include <WProgram.h>
#include “le_led.h”

class le_row{

public:
le_row(int row_len);
le_led row_arr;
};

le_line.cpp

#include “le_line.h”
#include “le_led.h”

le_row::le_row(int row_len){

row_arr[row_len];
for (int i=0; i<row_len; i++){
row_arr*; *

  • }*
    }
    [/quote]
    ****** le_led.h
    > //
    > //le_led.h
    > //
    > // Need to include Arduino core header WProgram.h so that typedef
    > // for byte is known
    > //
    > #include <WProgram.h>
    >
    > class le_led
    > {
    > public:
    > le_led(byte led_in_r, byte led_in_g, byte led_in_b);
    > void change_r(byte led_in_r);
    > void change_g(byte led_in_g);
    > void change_b(byte led_in_b);
    > //void change(byte led_in, int led_rgb);
    > byte get_r();
    > byte get_g();
    > byte get_b();
    > //void get(int led_rgb);
    > private:
    > byte led_r;
    > byte led_g;
    > byte led_b;
    > };
    *****
    le_led.cpp
    > //
    > // le_led.cpp
    > //
    > // Include le_led.h so that class definition is known
    > //
    > #include “le_led.h”
    >
    > le_led::le_led(byte led_in_r, byte led_in_g, byte led_in_b){
    *> *
    > led_r = led_in_r;
    > led_g = led_in_g;
    > led_b = led_in_b;
    *> *
    > }
    >
    > void le_led::change_r(byte led_in_r) { led_r = led_in_r; }
    > void le_led::change_g(byte led_in_g) { led_g = led_in_g; }
    > void le_led::change_b(byte led_in_b) { led_b = led_in_b; }
    >
    > byte le_led::get_r() { return led_r; }
    > byte le_led::get_g() { return led_g; }
    > byte le_led::get_b() { return led_b; }

http://www.arduino.cc/playground/Code/LED#FAQ

You should create the array in the sketch and pass it down to the constructor, or enable a default constructor for the le_led and initialize the array inside the library by setters.

:)