Hi Community,
iam writing a Library out of my developing sketch - (transfer functionality to library thing)
my problem is - i want to use constants to define the used pins of an object of the library.
so i declared constant variables in my 'MotorFaderControl.h' file like this:
/**
* Class Definition:
**/
class MotorFaderControl
{
public: // public methods
//Constructor
MotorFaderControl(byte iPin_ServoTrack, byte iPin_Direction, byte iPin_Speed, byte iPin_Break);
//Destructor
~MotorFaderControl();
// get Current Position
word getCurrentPosition();
private: // per object data
const byte pin_ServoTrack;
const byte pin_Direction;
const byte pin_Speed;
const byte pin_Break;
word wCurrentPosition;
unsigned long ulTimeLastAction;
// private methods
word getPosDif(word wValue1, word wValue2);
};
in the .cpp file i want to set them this way:
MotorFaderControl::MotorFaderControl(byte bPin_ServoTrack, byte bPin_Direction, byte bPin_Speed, byte bPin_Break)
{
pin_ServoTrack = bPin_ServoTrack;
pin_Direction = bPin_Direction;
pin_Speed = bPin_Speed;
pin_Break = bPin_Break;
wCurrentPosition = 0;
ulTimeLastAction = 0;
/* I have read that this initialization should be not in the Contstructor but better in an 'begin' function.
pinMode(pin_ServoTrack, INPUT);
pinMode(pin_Direction, OUTPUT );
pinMode(pin_Speed, OUTPUT );
pinMode(pin_Break, OUTPUT );
ulTimeLastAction = millis();*/
}
but when i try to compile my library-test sketch
/****************************************************************************************************
MotorFaderControl Library Test sketch
This sketch should Control a Motor of a Motorfader.
Created: 09.06.2012
copyright by Stefan Krueger
written by Stefan Krueger s-light.eu
Last modified: 17.06.2012 12:00
By Stefan Krueger s-light.eu
changelog / history :
09.06.2012 00:00 created library out of developing project 'Motorfader_Test_2012_06_09__11_45__v17.ino'
09.06.2012 15:30 created test sketch
10.06.2012 12:00 first tests
****************************************************************************************************/
#include <MotorFaderControl.h>
/**
* Fader
* Constructor : (byte bPin_ServoTrack, byte bPin_Direction, byte bPin_Speed, byte bPin_Break);
**/
MotorFaderControl myMFC_Fader1(A2, 12, 3, 9);
MotorFaderControl myMFC_Fader2(A3, 13, 11, 8);
void setup()
{
/**************************************************/
/* Setup Pins */
/**************************************************/
/**************************************************/
/* Initialise all the Variables */
/**************************************************/
//myMFC_Fader1.begin();
//myMFC_Fader1.begin();
/**************************************************/
/* Welcom @ Start Up! */
/**************************************************/
Serial.begin(9600);
Serial.println();
Serial.println("Welcome to MotorFaderControl Library Test Sketch!");
Serial.println("system is starting.!");
Serial.println(":-)");
Serial.println();
Serial.println("Go!");
}
void loop()
{
delay(500);
}
i get the following errors:
MotorFaderControl.cpp: In constructor 'MotorFaderControl::MotorFaderControl(byte, byte, byte, byte)':
MotorFaderControl.cpp:56: error: uninitialized member 'MotorFaderControl::pin_ServoTrack' with 'const' type 'const byte'
MotorFaderControl.cpp:56: error: uninitialized member 'MotorFaderControl::pin_Direction' with 'const' type 'const byte'
MotorFaderControl.cpp:56: error: uninitialized member 'MotorFaderControl::pin_Speed' with 'const' type 'const byte'
MotorFaderControl.cpp:56: error: uninitialized member 'MotorFaderControl::pin_Break' with 'const' type 'const byte'
..
MotorFaderControl.cpp:66: error: assignment of read-only data-member 'MotorFaderControl::pin_ServoTrack'
MotorFaderControl.cpp:68: error: assignment of read-only data-member 'MotorFaderControl::pin_Direction'
MotorFaderControl.cpp:69: error: assignment of read-only data-member 'MotorFaderControl::pin_Speed'
MotorFaderControl.cpp:70: error: assignment of read-only data-member 'MotorFaderControl::pin_Break'
if i understand this thread right - it was the same / similar problem -
but i dont understand how to get this to work for me -
can someone help to understand the thing?
what is the right way to get the idea of use constant declarations to work with the library and the constructor initialization?!
sunny greetings
stefan
[edit]thanks to PaulS i had the wrong error messages copied.. now thats right..[/edit]