Filling an Array with #defines

Hello,

cuerrently i am trying to set up an array.
To make programming more easy i want to fill it with defines.

My problem ist, that filling an array with defines doesn´t work at all.
error: stray'303'
Does anyone know if theres a way to do so?

#define OUTPUT_WIRE1 24   //Stecker 18-polig Pin 1
#define OUTPUT_WIRE2 26   //Stecker 18-polig Pin 2
#define OUTPUT_WIRE3 28   //Stecker 18-polig Pin 3
#define OUTPUT_WIRE4 30   //Stecker 18-polig Pin 4
#define OUTPUT_WIRE5 32   //Stecker 18-polig Pin 5
#define OUTPUT_WIRE6 34   //Stecker 18-polig Pin 6
#define OUTPUT_WIRE7 36   //Stecker 18-polig Pin 7
#define OUTPUT_WIRE8 38   //Stecker 18-polig Pin 8
#define OUTPUT_WIRE9 40   //Stecker 18-polig Pin 9
#define OUTPUT_WIRE10 42  //Stecker 18-polig Pin 10
#define OUTPUT_WIRE11 9   //Stecker 18-polig Pin 11
#define OUTPUT_WIRE12 8   //Stecker 18-polig Pin 12
#define OUTPUT_WIRE13 7   //Stecker 18-polig Pin 13
#define OUTPUT_WIRE14 6   //Stecker 18-polig Pin 14
#define OUTPUT_WIRE15 5   //Stecker 18-polig Pin 15
#define OUTPUT_WIRE16 4   //Stecker 18-polig Pin 16
#define OUTPUT_WIRE17 3   //Stecker 18-polig Pin 17
#define OUTPUT_WIRE18 2   //Stecker 18-polig Pin 18

#define INPUT_WIRE1 23    //Becherelektronik Pin 1
#define INPUT_WIRE2 25    //Becherelektronik Pin 2
#define INPUT_WIRE3 27    //Becherelektronik Pin 3
#define INPUT_WIRE4 29    //Becherelektronik Pin 4
#define INPUT_WIRE5 31    //Becherelektronik Pin 5
#define INPUT_WIRE6 33    //Becherelektronik Pin 6
#define INPUT_WIRE7 35    //Becherelektronik Pin 7
#define INPUT_WIRE8 37    //Becherelektronik Pin 8
#define INPUT_WIRE9 39    //Becherelektronik Pin 9
#define INPUT_WIRE10 43   //Becherelektronik Vcc
#define INPUT_WIRE11 45   //Becherelektronik SDA
#define INPUT_WIRE12 47   //Becherelektronik SCL
#define INPUT_WIRE13 49   //Becherelektronik GND
#define INPUT_WIRE14 44   //I2C Anschluss VCC
#define INPUT_WIRE15 46   //I2C Anschluss SDA
#define INPUT_WIRE16 48   //I2C Anschluss SCL
#define INPUT_WIRE17 50   //I2C Anschluss GND
#define INPUT_WIRE18 52  

int ausgänge[16];
{OUTPUT_WIRE1, OUTPUT_WIRE2, OUTPUT_WIRE3, OUTPUT_WIRE4, OUTPUT_WIRE5, OUTPUT_WIRE6,
OUTPUT_WIRE7, OUTPUT_WIRE8, OUTPUT_WIRE9, OUTPUT_WIRE10, OUTPUT_WIRE11, OUTPUT_WIRE12, OUTPUT_WIRE13,
OUTPUT_WIRE14, OUTPUT_WIRE15, OUTPUT_WIRE16, OUTPUT_WIRE17};


#define eingänge[16] = {INPUT_WIRE1, INPUT_WIRE2, INPUT_WIRE3, INPUT_WIRE4, INPUT_WIRE5, INPUT_WIRE6,
INPUT_WIRE7, INPUT_WIRE8, INPUT_WIRE9, INPUT_WIRE10, INPUT_WIRE11, INPUT_WIRE12, INPUT_WIRE13, INPUT_WIRE14,
INPUT_WIRE15, INPUT_WIRE16, INPUT_WIRE17};

int x = 0;

byte anschluss[16];
byte kurzschluss[16];
byte verbindungsNummer = 0;

void setup() {
  pinMode(OUTPUT_WIRE1, OUTPUT);
  pinMode(OUTPUT_WIRE2, OUTPUT);
  pinMode(OUTPUT_WIRE3, OUTPUT);
  pinMode(OUTPUT_WIRE4, OUTPUT);
  pinMode(OUTPUT_WIRE5, OUTPUT);
  pinMode(OUTPUT_WIRE6, OUTPUT);
  pinMode(OUTPUT_WIRE7, OUTPUT);
  pinMode(OUTPUT_WIRE8, OUTPUT);
  pinMode(OUTPUT_WIRE9, OUTPUT);
  pinMode(OUTPUT_WIRE10, OUTPUT);
  pinMode(OUTPUT_WIRE12, OUTPUT);
  pinMode(OUTPUT_WIRE13, OUTPUT);
  pinMode(OUTPUT_WIRE14, OUTPUT);
  pinMode(OUTPUT_WIRE15, OUTPUT);
  pinMode(OUTPUT_WIRE16, OUTPUT);
  pinMode(OUTPUT_WIRE17, OUTPUT);
  pinMode(OUTPUT_WIRE18, OUTPUT);

  pinMode(INPUT_WIRE1, INPUT);
  pinMode(INPUT_WIRE2, INPUT);
  pinMode(INPUT_WIRE3, INPUT);
  pinMode(INPUT_WIRE4, INPUT);
  pinMode(INPUT_WIRE5, INPUT);
  pinMode(INPUT_WIRE6, INPUT);
  pinMode(INPUT_WIRE7, INPUT);
  pinMode(INPUT_WIRE8, INPUT);
  pinMode(INPUT_WIRE9, INPUT);
  pinMode(INPUT_WIRE10, INPUT);
  pinMode(INPUT_WIRE11, INPUT);
  pinMode(INPUT_WIRE12, INPUT);
  pinMode(INPUT_WIRE13, INPUT);
  pinMode(INPUT_WIRE14, INPUT);
  pinMode(INPUT_WIRE15, INPUT);
  pinMode(INPUT_WIRE16, INPUT);
  pinMode(INPUT_WIRE17, INPUT);
  pinMode(INPUT_WIRE18, INPUT);
}

void loop() {
 
}

Lose the semicolon

I have no idea what this is supposed to be.

I think it may be the name "ausgänge" which is causing the error, I tried changing it and this stopped the error 303.

1 Like

you can't have an umlaut in a C++ variable name ( identifier) .. stick to just plain old ASCII (well not even all ascii, the dash is for minus, the dot has special use, etc...)

the spec says:

An identifier is an arbitrarily long sequence of digits, underscores, lowercase and uppercase Latin letters, and most Unicode characters. A valid identifier must begin with a non-digit character (Latin letter, underscore, or Unicode character of class XID_Start) and may contain non-digit characters, digits, and Unicode characters of class XID_Continue in non-initial positions. Identifiers are case-sensitive (lowercase and uppercase letters are distinct), and every character is significant. Every identifier must conform Normalization Form C.

Note: Support of Unicode identifiers is limited in most implementations, e.g. gcc (until 10).

➜ avoid unicode

3 Likes

It would make more sense if you make an array with all the pins and #define the indexes of the pins so when you need access to the pin you go

input_pins[WIRE1]

Make the array byte instead of int, I do not know of any board that has over 255 I/O pins.

The whole point of putting the pin numbers in an array is so you can avoid the long list of repetitive function calls:

void setup() {
  for (size_t i = 0; i < sizeof(ausgange) / sizeof(ausgange[0]); i++) {
    pinMode(ausgange[i], OUTPUT);
  }

  for (size_t i = 0; i < sizeof(eingange) / sizeof(eingange[0]); i++) {
    pinMode(eingange[i], INPUT);
  }
}

Hello
Or using a little bit C++:

void setup() {
  for (auto ausgang:ausgange) pinMode(ausgang, OUTPUT);
  for (auto eingang:eingange)  pinMode(eingang, INPUT);
}

Have a nice day and enjoy coding in C++.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.