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

Status
Not open for further replies.

mcivan

Active member
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() {

}
 
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
 

Attachments

  • Screen Shot 2014-10-15 at 12.20.58 AM.jpg
    Screen Shot 2014-10-15 at 12.20.58 AM.jpg
    114.3 KB · Views: 179
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.
 
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!
 
Status
Not open for further replies.
Back
Top