Hi, I'm trying to write a class and one thing isn't working. I'm trying to save a few variables to use later, but it isn't working. If i don't try to use the variable 'CS' but a number directly it works. Can someone point out what I am doing wrong. I tried to include only the functions that are used. The class is defined like this:
ADS.h
Code:
class ADS
{
public:
void PinMap(int cs, int drdy, int reset, int start); // saves all the variables that are declared in ADS.c
void Initialize(); // start spi and prepare pins
void pindown(); // used to test
private:
// for pic portability
void pinc(int pin, int lvl);
void pint(int pin, int type);// pinmode - 0 out, 1 in
};
ADS.c looks like this:
Code:
int CS, DRDY, RESET, START;
void ADS::PinMap(int cs, int drdy, int reset, int start)
{ CS, DRDY, RESET, START = cs, drdy, reset, start; }
void ADS::Initialize(){
pint(CS, 0);
pint(DRDY, 1); // PIN TYPE INPUT
pinc(CS, 1);
pint(START, 0); // PIN TYPE OUTPUT
pinc(START, 1); // PIN LOGIC STATE 1
pint(RESET, 0); // PIN TYPE OUTPUT
pinc(RESET, 1); // PIN LOGIC STATE 1
}
void ADS::pindown()
{
//pint(2,0); // IF I use a number istead of CS it works throughout the code
pinc(CS, 0);
wait(1000);
pinc(CS,1);
wait(200);
}
void ADS::pinc(int pin, int lvl)
{
if (lvl == 1)
{
digitalWrite(pin, HIGH);
}
if (lvl == 0)
{
digitalWrite(pin, LOW);
}
}
void ADS::pint(int pin, int type)
{
if (type == 1)
{
pinMode(pin, INPUT);
}
if (type == 0)
{
pinMode(pin, OUTPUT);
}
}