'phDriverInit' was not declared in this scope

Hello there, I am trying to make a library and get it to compile using the Arduino IDE however, I am getting an error in the script VegaBoard.cpp the following error says: 'phDriverInit' was not declared in this scope.

Here is the code that the error occurs inside of:

VegaBoard.cpp

/*
  Created by Tetra System Solutions (tetrasystemsolutions@gmail.com) - <https://www.tetrasystemsolutions.com>
  Copyright (C) 2021 Tetra System Solutions.
  All rights reserved.
*/
#include "VegaBoard.h"

void switchDriver(int option)
{
    phDriverBegin();
    switch(option)
    {
        case 0:
            break;
        case 1:
            break;
        case 2:
            break;
        case 3:
            break;
        default:
            phDriverInit();
            break;
    }
}

VegaBoard.h

#include "ToolDrivers.h"
#include <SoftwareSerial.h>

class VegaBoard
{
    public:
        void switchDriver(int option);
        void CommInit(int pin, int ledPin1); // Initializes communication with python and the ai.
        void CommBegin(int pin, int ledPin1); // Begins communication with the ai. 
        void readDriver(int pin); // Reads data from the drivers
};

Here is the code for the script that defines the phDriverInit function (ToolDrivers.cpp & ToolDrivers.h):

/*
  Created by Tetra System Solutions (tetrasystemsolutions@gmail.com) - <https://www.tetrasystemsolutions.com>
  Copyright (C) 2021 Tetra System Solutions.
  All rights reserved.
*/
#include "ToolDrivers.h"

void phDriverInit()
{
  Wire.begin();
  Serial.begin(9600);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
  display.setTextColor(WHITE);

  timer.setInterval(500L, display_driver.displayValue("pH:", ph_act));
}

void phDriverBegin()
{
  timer.run();
  for(int i = 0; i<10; i++)
  {
    buffer_array[i]=analogRead(A0);
    delay(30);
  }
  for(int i = 0; i<9; i++)
  {
    for(int j=i+1; j<10; j++)
    {
      if(buffer_array[i]>buffer_array[j])
      {
        temperature=buffer_array[i];
        buffer_array[i]=buffer_array[j];
        buffer_array[j]=temp;
      }
    }
  }
  average_val=0;
  for(int i=2; i<8; i++)
  average_val+=buffer_array[i];
  float voltage=(float)average_val*5.0/1024/6;
  ph_act = -5.70 * voltage + calibration_value;

  Serial.println("pH Val: ");
  Serial.print(ph_act);
  delay(1000);
  
}

ToolDrivers.h:

/*
  Created by Tetra System Solutions (tetrasystemsolutions@gmail.com) - <https://www.tetrasystemsolutions.com>
  Copyright (C) 2021 Tetra System Solutions.
  All rights reserved.
*/
#include <SimpleTimer.h>
#include "DisplayDriver.h"

SimpleTimer timer;
float calibration_value = 21.34 - 0.7;
int ph_value = 0;
unsigned long int average_val;
int buffer_array[10],temperature;

float ph_act;

class ToolDrivers
{
  public:
    void phDriverInit();
    void phDriverBegin();
};

What exactly would I be missing here? Thanks again for any help! :grinning:

You define phDriverInit() only inside the class ToolDrivers. The compiler doesn't know that you have a normal function coded somewhere else (outside the include chain).

Thank you very much pylon!

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