Thread: variable not working

  1. #1
    Registered User
    Join Date
    Jan 2017

    variable not working

    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:
    class ADS
        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
        // 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:
    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);
    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);

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    CS, DRDY, RESET, START = cs, drdy, reset, start
    This isn't how you assign 4 variables with 4 values.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Integer variable not working
    By xpro in forum C++ Programming
    Replies: 2
    Last Post: 08-30-2016, 08:17 AM
  2. Float variable not working!
    By Furugoori_K1204 in forum C Programming
    Replies: 5
    Last Post: 12-12-2013, 01:19 PM
  3. how to save my current working directory into a variable
    By sharonch in forum Windows Programming
    Replies: 3
    Last Post: 11-17-2012, 04:20 PM
  4. Replies: 8
    Last Post: 06-01-2012, 01:57 AM
  5. Working with variable variables
    By Differentialpi in forum C Programming
    Replies: 1
    Last Post: 01-06-2008, 10:35 PM

Tags for this Thread