variable is not declared in this scop - No synthaxe issue

Hi,

(Sorry for my language I am french :wink: )

It’s been some days since my project doesn’t compile well.
The code is made for a teensy 3.5. I have declared a bunch of variable at the beginning of the program, (a lot of pin address essentially), but when I use one of the variables to make a digitaWrite or something I get the error :

main:252:49: error: ‘delay_bip_alarm’ was not declared in this scope

I don’t think my issue is related to the code so I have deled some useless functions to make the debugging easier :wink:

I have tested to put my variable declaration with the “const” prefix and without “#define” but it changes nothing …

Thanks by advance ! :slight_smile:

#include <Arduino.h>;
#include <Adafruit_MMA8451.h>;
#include <Adafruit_Sensor.h>;
#include <L3G.h>;

L3G gyro;
Adafruit_MMA8451 mma = Adafruit_MMA8451();


#define int ADDRESS_EEPROM[8] = {0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57};

#define int ADDRESS_ACC = 0x50;
#define int pin_capteurs[5] = {A1, A2, A3, A4, A5};

#define int freq_echant = 1000; //Hz
#define int record_time = 6000; //6s

#define float tension_nominale_battery = 12.0; // V
#define float seuil_limit_bat = 10.0; // V
#define float rapport_pont_diviseur_batterie = 0.5;

int off_set_jauges[5] = {0, 0, 0, 0, 0};
#define int pin_battery = A21;

//Définition des tableaux de données
int data_strain[5][freq_echant * record_time] = 0; //5 cases pour les capteurs
int data_acc[3][freq_echant * record_time] = 0; // données accélération x, y, z repère fusée
int data_gyro[3][freq_echant * record_time] = 0; // données accélération x, y, z, repère fusée
float data_time[freq_echant * record_time] = 0.0; // prise précise du temps.

#define int pin_buzzer = 23;
#define int date_buzzer = 0;

#define int pin_wheatstone = 24;
#define int pin_led_erreur = 13;
#define int pin_button = A22;
#define int pin_WP = 39;
#define int pin_SDA_EEPROM = 38;
#define int pin_SCL_EEPRIM = 37;
#define int pin_TX_seq = 32;
#define int pin_RX_seq = 31;
#define int pin_led_save = 28;
#define int pin_led_on = 27;
#define int pin_SCL_ACC = 3;
#define int pin_SDA_ACC = 4;
#define int pin_dem_exp = A7;

byte highAddress;
byte lowAddress;
byte data;

bool etat_buzzer = false;
bool alarm_buzzer = false;
int delay_bip_alarm = 100;



bool on_record = false;
bool ready_ = false;
bool etat_led_ready = false;
int date_led_ready = 0;
int delay_ready_flash = 500;



void loop() {
  // put your main code here, to run repeatedly:
  ready_ = true;
  if (millis() % 10000 <= 50) { // toute les 10s

    alarm_buzzer = check_battery(); //on vérifie le niveau de batterie
  }

  if (alarm_buzzer and millis() - date_buzzer > delay_bip_alarm ) { // bip en alternance si l'alarme est déclanchée
    etat_buzzer = not etat_buzzer;
    if (etat_buzzer) {
      digitalWrite(pin_buzzer, HIGH);
    }
    else
    {
      digitalWrite(pin_buzzer, LOW);
    }
  }

  if (digitalRead(pin_dem_exp) == HIGH) { //demarage exp
    on_record = true;
    ready_ = false;
    record();
  }

  if (digitalRead(pin_button) == HIGH and not on_record) { // remise à zero offset jauges appui court // save EEPROM appui long, on interdit le offset pendant le vol
    delay(1000);
    if (analogRead(pin_button) > 500) { // appuis long -> save
      digitalWrite(pin_led_save, HIGH);
      save_eeprom();
      digitalWrite(pin_led_save, LOW);
    }
    else { //appui court -> offset zero
      digitalWrite(pin_led_on, LOW);
      set_offset();
      delay(100);
      digitalWrite(pin_led_on, HIGH);
    }
  }

  if (ready_ and millis() - date_led_ready > delay_ready_flash) { //clignotement ready
    etat_led_ready = not etat_led_ready;
    if (etat_led_ready) {
      digitalWrite(pin_led_save, HIGH);
    }
    else {
      digitalWrite(pin_led_save, LOW);
    }
  }
  else {
    digitalWrite(pin_led_save, LOW);
  }

}

You're using #define incorrectly e.g.:

#define int record_time = 6000; //6s

Get rid of the #define so it looks like this

int record_time = 6000; //6s

Which is what you have done further down with other variables. Add const if you like once you have it compiling.

No semicolons ; at the end of #include

#include <Arduino.h>

If you are using #define you must NOT use a type or an equals, NOR end with semicolon

#define ADDRESS_ACC  0x50

#define is a macro definition, not a variable definition.
It’s an instruction that says everywhere you write ADDRESS_ACC instead replace it with 0x50
There’s a bit more to it than that, but that will do for a beginner.
If you do not understand #define, do not use it. There is nothing you can’t do by writing out longhand.

Consequently this define, and others, are total nonsense…

#define int pin_capteurs[5] = {A1, A2, A3, A4, A5};

You cannot #define an array.

Most your #defines just need the #define removing as they are C variable declarations and assignments. I’ve no idea why you have decided to stick #define in front of all of them??

Also in C if statements and Boolean expressions...
AND must be written &&
OR must be written ||
NOT must be written !

Thanks for your response.
I correct each part of my where according to your response and it works perfectly.
For array, I used a const to replace #define. I kept #define for pin identification.

I just have a question about if statement :

pcbbc:
Also in C if statements and Boolean expressions...
AND must be written &&
OR must be written ||
NOT must be written !

I ve wrote a lot of code with OR, AND and NOT, but does it work the same ay as &&, ||, ! ?

The subject can be marked as solved.

According to my code I need to use the analog pin A21 of the teensy.
The pin A21 raise 'A21' is not declared in this scop too.

Is there a way to feed pin id into my code ?

pcbbc:
Also in C if statements and Boolean expressions...
AND must be written &&
OR must be written ||
NOT must be written !

But this is C++ so the C rules are not relevant

See alternative operators