First let me start off by saying this is code for a MAX32 Microcontroller. The code that i'm having issues with is written in c++. Its some files that i'm creating for this project
So i've been working on this for hours and I can't find whats wrong with my code. I'm a little rusty at C++ but the code seems right.
the error i get is
Senior_Design.cpp.o: In function setup':
/privateSenior_Design.cpp:13: undefined reference toAccelerometer::setup()'
Senior_Design.cpp.o: In function loop':
/privateSenior_Design.cpp:20: undefined reference toAccelerometer::read()'
Senior_Design.cpp.o: In function __static_initialization_and_destruction_0':
/privateSenior_Design.cpp:7: undefined reference toAccelerometer::Accelerometer(long)'
collect2: ld returned 1 exit status
The main code is called "senior_design" and it is
#include <Wire.h>
#include "accel.h"
Accelerometer bodyAccel = Accelerometer(321);
void setup(void){
  Serial.begin(9600);
  //Wire.begin(); // join i2c bus (address optional for master)
  if( !bodyAccel.setup() ){
    Serial.println("Error with accelerometer");
    while(1);
  }
}
void loop(void){
 bodyAccel.read(); 
 Serial.print("Accel. Reading: ");
 Serial.println(bodyAccel.x);
 Serial.println(bodyAccel.y);
 Serial.println(bodyAccel.z);
 delay(1000);
}
i have these two other files that will be used. This one is the accel.cpp file
#include "accel.h"
#include <Wire.h>
#include "WProgram.h"
#include <limits.h>
static float Accel_MG_LSB = 0.001f;
Accelerometer::Accelerometer(long sensorID){
    sensor_ID = sensorID;
}
void Accelerometer::read(){
    Wire.beginTransmission( (byte)accelAddr );
    delay(50);
    Wire.send(accelXRegAddr | 0x80);
    Wire.endTransmission();
    delay(50);
    Wire.requestFrom( (byte)accelAddr, (byte)6 );
    while(Wire.available() < 6);
    xlo = Wire.receive();
    xhi = Wire.receive();
    ylo = Wire.receive();
    yhi = Wire.receive();
    zlo = Wire.receive();
    zhi = Wire.receive();
    accelDatax = (int16_t)(xlo | (xhi << 8)) >> 4;
    accelDatay = (int16_t)(ylo | (yhi << 8)) >> 4;
    accelDataz = (int16_t)(zlo | (zhi << 8)) >> 4;
    x = accelDatax * Accel_MG_LSB * 9.8;
    y = accelDatay * Accel_MG_LSB * 9.8;
    z = accelDataz * Accel_MG_LSB * 9.8;
}
bool Accelerometer::setup(){
    Wire.begin();
    //Enable 100Hz on accelerometer
    Wire.beginTransmission(accelAddr);
    Wire.send(0x20);
    Wire.send(0x57);
    Wire.endTransmission();
    Wire.beginTransmission(accelAddr);
    Wire.send(0x20);
    Wire.endTransmission();
    Wire.requestFrom(accelAddr, (byte)1);
    uint8_t reg = Wire.receive();
    Wire.endTransmission();
    if(reg != 0x57)
        return false;
    return true;    
}
and the header file for it (accel.h)
#ifndef accel_h
#define accel_h
#include "WProgram.h"
#include <Wire.h>
#define accelAddr (0x32 >> 1)
#define accelXRegAddr 0x28
class Accelerometer{
public:
    Accelerometer(long sensorID = -1);
    void read(void);
    bool setup(void);
    float x;
    float y;
    float z;
private:
    long sensor_ID;
    uint8_t xlo;
    uint8_t xhi;
    uint8_t ylo;
    uint8_t yhi;
    uint8_t zlo;
    uint8_t zhi;
    float accelDatax;
    float accelDatay;
    float accelDataz;
};
#endif /* accel_h */
 
    