[array] was not declared in this scope compile error

electron
Tags: #<Tag:0x00007fe21c966ff8>

#1

I’m getting a compile error [array name] was not declared in this scope.
I’m not understanding the error since the arrays irLeds and irRecs were declared in the global scope. Perhaps it’s a c++ syntax issue I’m not aware of coming from a different background.

FIRMWARE

// indicator light - (when lit active IR receiver is detecting IR light from the active IR transmitter)
int boardLed = D7;

int led50 = 18;
int led75 = 17;
int led100 = 16;
int ledDoor = 15;

int rec50 = 12;
int rec75 = 11;
int rec100 = 10;
int recDoor = 9;

int irLeds[] = {ledDoor, led100, led75, led50};
int irRecs[] = {recDoor, rec100, rec75, rec50};

// power to ir receievers
int recPower = WKP;

// Declare the cloud function calibrateSensor,
// which we will use with the variable activeSensor to select which sensor to calibrate 
int calibrateSensor(String command);
int activeSensor;

// set initial state of IR beam
// (0 == beam intact or IR light being detected by IR receiver)
// (1 == beam broken or IR light NOT being detected by IR receiver)
int beamState = 1;
int lastBeamState = 1;

void setup() {
    Particle.function("calibrateSensor", calibrateSensor);
    
    // declare pins
    pinMode(boardLed,OUTPUT);
    digitalWrite(boardLed,LOW);
    
    pinMode(recPower,OUTPUT);
    digitalWrite(recPower,HIGH);
    
    for (int a = 0; a < arraySize(irLeds); a++) {
        pinMode(irleds[a], OUTPUT);
    }
    
    for (int b = 0; b < arraySize(irRecs); b++) {
        pinMode(irRecs[b], INPUT);
        digitalWrite(irRecs[b], HIGH);
    }
    
    // open serial port for debugging
    Serial.begin(9600);
    Serial.println(F("ready to receive IR signals"));
}

void loop() {
    
    switch(activeSensor) {
        case 0:
            Serial.println("50% full sensor");
            analogWrite(led50, 128, 38000);
            beamState = digitalRead(rec50);
            break;
        case 1:
            Serial.println("75% full sensor");
            analogWrite(led75, 128, 38000);
            beamState = digitalRead(rec75);
            break;
        case 2:
            Serial.println("100% full sensor");
            analogWrite(led100, 128, 38000);
            beamState = digitalRead(rec100);
            break;
        case 3:
            Serial.println("Door ajar sensor");
            analogWrite(ledDoor, 128, 38000);
            beamState = digitalRead(recDoor);
            break;
        default:
            Serial.println("RUH ROH...... not working");
    }    
    
    Serial.println("beamState:");
    Serial.println(beamState);
    
    if (beamState == 0) {
        digitalWrite(boardLed, HIGH);
    } else if (beamState == 1) {
        digitalWrite(boardLed, LOW);
    } else {
        Serial.println("beam state error");
    }
    
    delay(1000);
}

int calibrateSensor(String command) {
    allOff();
    
    command.toLowerCase();
    
    if (command == "50") {
        activeSensor = 0;
        return 50;  
    }
    
    if (command == "75") {
        activeSensor = 1;
        return 75;  
    }
    
    if (command == "100") {
        activeSensor = 2;
        return 100;  
    }
    
    if (command == "door") {
        activeSensor = 3;
        return 3002;
    }
    
    return -1;

}

void allOff() {
    
    for (int x = 0; x < arraySize(irLeds); x++) {
        pinMode(irleds[x], OUTPUT);
        digitalWrite(irleds[x], LOW);
    }
    
    // Turn off indicator led
    digitalWrite(boardLed,LOW);
}

ERROR

mkdir -p ../build/target/user/platform-10-m
arm-none-eabi-gcc -DSTM32_DEVICE -DSTM32F2XX -DPLATFORM_THREADING=1 -DPLATFORM_ID=10 -DPLATFORM_NAME=electron -DUSBD_VID_SPARK=0x2B04 -DUSBD_PID_DFU=0xD00A -DUSBD_PID_CDC=0xC00A -DSPARK_PLATFORM -g3 -gdwarf-2 -Os -mcpu=cortex-m3 -mthumb -DINCLUDE_PLATFORM=1 -DPRODUCT_ID=10 -DPRODUCT_FIRMWARE_VERSION=65535 -DUSE_STDPERIPH_DRIVER -DDFU_BUILD_ENABLE -DSYSTEM_VERSION_STRING=1.1.0 -DRELEASE_BUILD -I./inc -I../wiring/inc -I../system/inc -I../third_party/miniz/miniz -I../services/inc -I../third_party/nanopb/nanopb -I../communication/src -I../hal/inc -I../hal/shared -I../hal/src/electron -I../hal/src/stm32f2xx -I../hal/src/stm32 -I../third_party/freertos/freertos/FreeRTOS/Source/include -I../third_party/freertos/freertos/FreeRTOS/Source/portable/GCC/ARM_CM3 -I../platform/shared/inc -I../platform/MCU/STM32F2xx/STM32_USB_Host_Driver/inc -I../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc -I../platform/MCU/STM32F2xx/STM32_USB_OTG_Driver/inc -I../platform/MCU/STM32F2xx/STM32_USB_Device_Driver/inc -I../platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc -I../platform/MCU/shared/STM32/inc -I../platform/MCU/STM32F2xx/CMSIS/Include -I../platform/MCU/STM32F2xx/CMSIS/Device/ST/Include -I../dynalib/inc -I -I./libraries -I. -MD -MP -MF ../build/target/user/platform-10-mdebug-pin-number.o.d -ffunction-sections -fdata-sections -Wall -Wno-switch -Wno-error=deprecated-declarations -fmessage-length=0 -fno-strict-aliasing -DSPARK=1 -DPARTICLE=1 -Wundef -DSTART_DFU_FLASHER_SERIAL_SPEED=14400 -DSTART_YMODEM_FLASHER_SERIAL_SPEED=28800 -DSPARK_PLATFORM_NET=UBLOXSARA -fno-builtin-malloc -fno-builtin-free -fno-builtin-realloc  -DLOG_INCLUDE_SOURCE_INFO=1 -DPARTICLE_USER_MODULE -DUSER_FIRMWARE_IMAGE_SIZE=0x20000 -DUSER_FIRMWARE_IMAGE_LOCATION=0x8080000 -DMODULAR_FIRMWARE=1 -DMODULE_VERSION=6 -DMODULE_FUNCTION=5 -DMODULE_INDEX=1 -DMODULE_DEPENDENCY=4,2,1102 -DMODULE_DEPENDENCY2=0,0,0 -D_WINSOCK_H -D_GNU_SOURCE -DLOG_MODULE_CATEGORY="\"app\""  -fno-exceptions -fno-rtti -fcheck-new -std=gnu++11 -c -o ../build/target/user/platform-10-mdebug-pin-number.o debug-pin-number.cpp
debug-pin-number.ino: In function 'void setup()':
debug-pin-number.ino:41:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int a = 0; a < arraySize(irLeds); a++) {
                       ^
debug-pin-number.ino:42:17: error: 'irleds' was not declared in this scope
         pinMode(irleds[a], OUTPUT);
                 ^
debug-pin-number.ino:45:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int b = 0; b < arraySize(irRecs); b++) {
                       ^
debug-pin-number.ino: In function 'void allOff()':
debug-pin-number.ino:127:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int x = 0; x < arraySize(irLeds); x++) {
                       ^
debug-pin-number.ino:128:17: error: 'irleds' was not declared in this scope
         pinMode(irleds[x], OUTPUT);
                 ^
../build/module.mk:277: recipe for target '../build/target/user/platform-10-mdebug-pin-number.o' failed
make[2]: Leaving directory '/firmware/user'
make[2]: *** [../build/target/user/platform-10-mdebug-pin-number.o] Error 1
../../../build/recurse.mk:11: recipe for target 'user' failed
make[1]: Leaving directory '/firmware/modules/electron/user-part'
make[1]: *** [user] Error 2
../build/recurse.mk:11: recipe for target 'modules/electron/user-part' failed
make: *** [modules/electron/user-part] Error 2

#2

No, the arrays the error messages complain about are not declared.
C/C++ is case sensitive.