How to use/read information from library data type inside a different file

Hello everybody,

I’m not a very good programmer and i’m trying to find my way, but today i stumbled upon a problem that i can’t solve if my life depended on it. I kinda know why it isn’t working, but I don’t seem to find how to fix it myself.

I have 2 files. One main file with my main code. I also have a HallSensor.h file where I do all my calculations.

If I ask the value for “accel_current_size” I can read it just fine in my serial.monitor, but i need to pass that value to the hallsensor so i can read it out for a number of times and see what was biggest/smallest value.

I did the same for my hallsensor and that works fine, but I can’t seem to get it working for the accelero sensor. I use a library found online, that i I included here in the attachement.

/* ========================
======== MAIN CODE ========
======================== */

#include <Arduino.h>
#include "HallSensor.h"
#include "TouchPad.h"
#include <ADXL375.h>

//Pins variables
int HallPinA = 2;               // HallSensor Analog Pin
int HallPinD = 2;               // HallSensor Digital Pin
int TouchSensorLedPin = 3;      // SidePad LED PIN
int TouchSensorPadPin_1 = 4;    // HallSensor Digital LEFT Pin
int TouchSensorPadPin_2 = 5;    // HallSensor Digital RIGHT Pin
int FeedbackLedsPin = 6;        // FEEDBACK LEDS PIN
int HitLed = 7;                 // HIT LED PIN

int LedFeedbackAmount = 5;      // Amount of feedback LEDS

//Global variables
ADXL375 accel;

int accel_current_size;
int HallValueA;
int HallValueD;
long Timer;
long TimeToCheckHall = 50;  //Time in millieseconds to run the while loop for Hallsensor
long ReactionTime;  //Time in millieseconds to run the while loop for Hallsensor
int GreatHall;                  //Gives back greatest measured HallSensor value
int SmallHall;                  //Gives back smallest measured HallSensor value
int GreatAccel;                  //Gives back greatest measured Accel value
int SmallAccel;                  //Gives back smallest measured Accel value
int randNumber;
int Chanse_To_acivate_Pad = 4; // wil zeggen 1 op x -1... 4 = dus 1 op 3 kansen (0,3)

// size of shock to look for in g
const uint16_t SHOCKDUINO_THRESHOLD = 0;

//CanWeHitState = status die aangeeft of de hallsensor moet gechecked worden of niet.
bool CanWeHitState = true;

void setup() {
  Serial.begin(9600);
  FeedbackLeds.begin();       // INITIALIZE NeoPixel strip object (REQUIRED)
  HitterLeds.begin();         // INITIALIZE NeoPixel strip object (REQUIRED)
  pinMode(HallPinA, INPUT);
  pinMode(HallPinD, INPUT);
  pinMode(TouchSensorPadPin_1, INPUT);
  pinMode(TouchSensorPadPin_2, INPUT);

  accel.init();
  accel.setShockThreshold(SHOCKDUINO_THRESHOLD);
  accel.startShockDetection();

  randomSeed(analogRead(0));
}

void loop() {

  AccelReading accData = accel.getXYZ();
  accel_current_size = accData.accelSize();
  Serial.print("accel_current_size= ");
  Serial.println(accel_current_size);
  delay(4000);
  //accData.printDebug();

    //ALs er een hit gedetecteerd is moet hij waardes terug geven.
    GetMinMaxHallSensor(HallValueA, HallPinA, 
                        &GreatHall, &SmallHall, 
                        TimeToCheckHall, millis(), 
                        accData, &GreatAccel, &SmallAccel);
}
/* ========================
====== HallSensor.h =======
======================== */

/*HallSensor Code */

#include <Arduino.h>
#include <ADXL375.h>


void GetMinMaxHallSensor(int HallValueD, int HallPinA, 
                          int* add_greatHall, int* add_smallHall,
                          long TimeToCheckHall, long Timer, 
                          AccelReading accData, int* add_greatAccel, int* add_smallAccel)
{
  //accel.init();
  //accel.setShockThreshold(SHOCKDUINO_THRESHOLD);
  //accel.startShockDetection();
  long TimerMax = Timer + TimeToCheckHall;
  *add_smallHall = HallValueD;
  Serial.println("Timer: ");
  Serial.println(Timer);
  while (TimerMax > Timer)
  {
    int currentHallValA = analogRead(HallPinA);
    int previousHallValA;
    //AccelReading accData = accel.getXYZ();
    //int currentAccelVal = accData.accelSize();
    //int previousAccelVal;
    if (currentHallValA > previousHallValA)
    {
      *add_greatHall = currentHallValA;
      previousHallValA = currentHallValA;
    }
    else
    {
      if (previousHallValA < *add_smallHall) {
          *add_smallHall = currentHallValA;
      }
    }

    // if (currentAccelVal > previousAccelVal)
    // {
    //   *add_greatAccel = currentAccelVal;
    //   previousAccelVal = currentAccelVal;
    // }
    // else
    // {
    //   if (previousAccelVal < *add_smallAccel) {
    //       *add_smallAccel = currentAccelVal;
    //   }
    // }
  Timer = millis();
  }

}

adxl375.zip (371 KB)

I did the same for my hallsensor and that works fine, but I can’t seem to get it working for the accelero sensor. I use a library found online, that i I included here in the attachement.

can you post the code exhibiting the problem?

i don’t see “accelero” in the files in the code tags (i’m not going to unzip your file)

I posted 2 code pieces. MAIN & HALL.
Its the second that calculates the halls, and i have also the code in comments that should read out my accelero, which it doesn’t.

i'll guess it's the following line?

    //int currentAccelVal = accData.accelSize();

Yes,

I commented most lines that gave me a problem, but I wanted to keep them so you guys could see what I mean and what I tried, hopefully you'll get the idea.