chipKIT® Development Platform

Inspired by Arduino™

problem with declaring pin in output in class constructor

Created Tue, 03 Jul 2012 18:29:43 +0000 by philippel13


philippel13

Tue, 03 Jul 2012 18:29:43 +0000

Hi,

i've observed that declare a pin in output in the class constructor seems doesn't work.

class1::class1() { pinMode(pint, OUTPUT); or TRISECLR = RE4; // RE4 as output }

If you call the same code not in the constructor but in a method it works fine.

I've searched a few hours why my code didn't works before discover that.

I'm not an expert in C++ so i don't know if it it is a normal behavior or not ...

philippe


Verdris

Thu, 05 Jul 2012 21:22:34 +0000

You need to pass the variable to the constructor. Try:

class1::class1(int pint)
{
pinMode(pint, OUTPUT); 
}

And in your sketch:

#include <class1.h>

class1 c1(9); // initializes your class and sets pin 9 to OUTPUT

void setup()
{
blah blah blah...
}

Then, all function calls will be in the format c1.function(arguments).