Processing code >> Arduino code (classes)

Hi~

General (maybe vague) question/topic here @ Processing/Arduino code.

I use Processing sometimes to develop/model designs that I will later implement in Arduino to control standalone light sculptures. I've only used simple Processing code till now so the conversion from Java >> C has been pretty easy. I've got a project now where I want to use classes, etc. and am wondering that if I get too deep in Java specific syntax that the conversion to C/C++ will be more trouble than the benefits from modeling is worth.

(fwiw - aside from the difference in how arrays are declared, most of the non-drawing specific code carries over)

So.. to use classes in Arduino, would I use a library approach? or can I define the class right in my main script a la Processing?

tx!

--Roy

Hi Roy,

C++ classes are typically declared header (.h) file and implemented in a cpp file. In java the declaration and implementation are done in the same class definition. but if you separated these out it would probably not require too much work to get the code to function in the Arduino environment. There will be differences in how you write the code, for example you would create the class without the 'new' keyword that is required in java but I would think that it wouldn't be too difficult to port a simple java class to an Arduino sketch.

As a quick test, I took this processing code:

class LED
{
  int X, Y;
  color Color;
  LED( int x, int y, color c) {
    X= x;
    Y= y;
    Color = c;
    setMode(false);
  }  
  void setMode(boolean mode) {
     // do something here  
  }
}

And converted it to C++ and dropped it into a sketch an it compiled ok in the Arduino environment class LED

class LED
{
  public:
    int X, Y;
    int Color;
    LED( int x, int y, int c) ;
    void setMode();
};


LED::LED( int x, int y, int c)
{
    X= x;
    Y= y;
    Color = c;
}  

void  LED::setMode()
{
     //do something here;  
}

Its worth a go and I would be interested to hear about how you got on. I have just posted some Processing code here that will need to be ported to the Arduino at some point and your won experiments would enlightening.