Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: INPUT, pinMode not declared Compiler Error with #ifdef and Classes

  1. #1
    Member
    Join Date
    Oct 2014
    Location
    World
    Posts
    31

    INPUT, pinMode not declared Compiler Error with #ifdef and Classes

    I am trying to learn/implement classes in my program, however I have hit a strange compiler error that I can't solve. Some how there references to the Teensyduino libraries are getting broken. However this only happens in one case.
    I am not confident in my implementation, and use of static, however I can't find any error between the two implementations. One compiles, and one gives weird errors. Any help or suggestions welcome!


    Arduino 1.0.6
    Teensyduino 1.20 (downloaded and installed today)
    The code should compile on copy/paste, but swap the commented //#define and the second should fail stating OUTPUT undefined, and highlighting the wrong line.

    Code:
    #define ZARL_01  //Set my hardware version to 01
    //#define ZARL_00    //Set my hardware version to 01
    
    #include "math.h"
    
    #ifdef ZARL_01
    class PINS{
    public:
      static const int Qo_Leds = 12;
      static const int PwmRes = 16;
      static const int PwmMaxValue = pow( 2, PwmRes) -1;
      int Led[2][Qo_Leds] = {
        { 
          25, 32, 3, 4, 5, 9, 21, 22, 6, 10, 20, 23                         }
        , // RGBW, 1-8 spots addressed clockwise starting at 4 o'clock
        {
        }                                                 // Second row to hold set values
      };
      const int Red   = Led[0][0];
      const int Green = Led[0][1];
      const int Blue  = Led[0][2];
      const int White = Led[0][3];
      const int Touch[3][5] = { 
        {   
          0, 1, 16, 17, 33
        }
        ,                        // 5 touch pins; touch pin calibration; last reading
        {
        }
        ,
        {
        }
      };
      const int TeensyLed = 13;
      const int vibe = A14;
      const int audio = 15;
      const int light = 14;
      const int SysVoltage = A13;
      const int BattPowerGood = 11;
      const int BattStatOne = 7;
      const int BattStatTwo = 8;
      const int MpuInterrupt = 2;
    
      void Config() {
        for ( int i = 0; i < Qo_Leds; ++i ) pinMode( Led[0][i], OUTPUT );
        for ( int i = 0; i < 5; ++i ) pinMode( Touch[0][i], INPUT );
        pinMode( TeensyLed, OUTPUT );
        pinMode( vibe, OUTPUT );
        pinMode( audio, INPUT );
        pinMode( light, INPUT );
        pinMode( SysVoltage, INPUT );
        pinMode( BattPowerGood, INPUT );
        pinMode( BattStatOne, INPUT );
        pinMode( BattStatTwo, INPUT );
        pinMode( MpuInterrupt, INPUT );
      }
    };
    #endif
    
    #ifdef ZARL_00
    class PINS {
    public:
      static const int Qo_Leds = 4;
      static const int PwmRes = 16;
      static const int PwmMaxValue = (pow( 2, PwmRes) -1);
      int Led[2][Qo_Leds] = {
        { 
          3, 4, 5, 6
        }
        , // RGBW, 1-8 spots addressed clockwise starting at 4 o'clock
        {
        }                                           // Second row to hold values
      };
      static const int audio = 23;
      static const int light = 22;
      static const int MpuInterrupt = 14;
      static const int TeensyLed = 13;
    
      void Config() {   //Comment out the next 5 lines, and the code will compile
        for ( int i = 0; i < Qo_Leds; ++i ) pinMode( Led[0][i], OUTPUT );
        pinMode( TeensyLed, OUTPUT );
        pinMode( audio, INPUT );
        pinMode( light, INPUT );
        pinMode( MpuInterrupt, INPUT );
      }
    };
    #endif
    
    
    
    PINS pin;
    
    
    void setup() {
      pin.Config();
    }
    
    void loop() {
    
    }

  2. #2
    Member
    Join Date
    Oct 2014
    Location
    World
    Posts
    31
    Alright, restarted with a simplified approach. Was compiling frequently, then hit the same problem, but I was able to take a few steps back and saw I had accidentally nested #ifdef statements. I saw this trick online, but I didn't consider that I had an #ifdef in the code I was to mark as old!

    Apparently #ifdef cannot be nested! *shrugs* :roll eyes:
    [
    ATTACH=CONFIG]2791[/ATTACH]

    Code:
    //#ifdef OLD
    //
    //// TEST PIN OUTS
    //void pinTest() { 
    //  for ( int i = 0; i < Qo_LEDS; ++i) {
    //    digitalWrite( LED[i], HIGH );
    //    delay(200);
    //  }
    //  digitalWrite ( POWER_LED, HIGH );
    //#ifdef ZARL_01 analogWrite ( VIBE_MOTOR, 1023); 
    //  delay(500);
    //  analogWrite( VIBE_MOTOR, 0 );
    //#endif
    //  digitalWrite ( POWER_LED, LOW );
    //  for ( int i = 0; i < Qo_LEDS; ++i) digitalWrite( LED[i], LOW );
    //}
    //
    //#endif
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	Screen Shot 2014-10-15 at 12.20.58 AM.jpg 
Views:	104 
Size:	114.3 KB 
ID:	2791  

  3. #3
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,681
    Note, you have the wrong syntax for the second #ifdef.

    You wrote:
    Code:
    #ifdef ZARL_01 analogWrite ( VIBE_MOTOR, 1023);
    The #ifdef can only be followed by a single identifer, i.e.:
    Code:
    #ifdef ZARL_01
    Since the IDE, decides to hide some error messages (particularly include file not found), perhaps it is deleting the error message that the compiler gives that the #ifdef is mal-formed. So, the first #endif winds up closing the first #ifdef, instead of the second, and the second #endif is also an error.

  4. #4
    Member
    Join Date
    Oct 2014
    Location
    World
    Posts
    31
    Quote Originally Posted by MichaelMeissner View Post
    Note, you have the wrong syntax for the second #ifdef.

    Since the IDE, decides to hide some error messages (particularly include file not found), perhaps it is deleting the error message that the compiler gives that the #ifdef is mal-formed. So, the first #endif winds up closing the first #ifdef, instead of the second, and the second #endif is also an error.
    Thanks for the clarification!
    I went back and played with this... and strangely the error is completely gone, regardless of the syntax mentioned above.
    ... I'll be proceeding with caution.

    The #ifdef isn't very clean in my implementation, but it is convenient to have one piece of software work on two different hardware iterations of the same project!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •