Pass changing analog value from void loop to library .h file How would I go about passing a void loop analog read value to a library .h file?
I've tried it but it only reads the pot position as soon as I plug the arduino in and does not change once booted up.

arduino main sketch file code;

#include "Arduino.h"
#include "common.h"
#include "synth.h"
#include "serial-in.h"
#include "audio-out.h"

void setup() {
  Synth&lt;0&gt;::initialize();
  SerialIn&lt;0&gt;::open();
  AudioOut&lt;0&gt;::open();
}

void loop() {
  int val = analogRead(A0);   
  int val1 = analogRead(A1);   
  int val2 = analogRead(A2);   
  int val3 = analogRead(A3);   
  int val4 = analogRead(A4);   
  while (true) {
    if (SerialIn&lt;0&gt;::available()) {
      uint8_t b = SerialIn&lt;0&gt;::read();
      Synth&lt;0&gt;::receive_midi_byte(b);
    }

    int8_t level = Synth&lt;0&gt;::clock();
    AudioOut&lt;0&gt;::write(level);
  }
}


.h file code

#pragma once

// #define private public  // for tests

#include "common.h"

// associations of units
#define IOsc        Osc
#define IFilter     Filter
#define IAmp        Amp
#define IEG         EG
#define IVoice      Voice
#define ISynthCore  SynthCore

#include "osc.h"
#include "filter.h"
#include "amp.h"
#include "eg.h"
#include "voice.h"
#include "synth-core.h"

template &lt;uint8_t T&gt;
class Synth {
public:
  INLINE static void initialize() {
    ISynthCore&lt;0&gt;::initialize();
    int val = analogRead(A0);   
    int val1 = analogRead(A1);   
    int val2 = analogRead(A2);   
    int val3 = analogRead(A3);   
    int val4 = analogRead(A4);   
    // Preset
    ISynthCore&lt;0&gt;::control_change(OSC_MODE      , 0  );
    ISynthCore&lt;0&gt;::control_change(OSC_COLOR     , val);
    ISynthCore&lt;0&gt;::control_change(MOD_RATE      , 8  );
    ISynthCore&lt;0&gt;::control_change(MOD_DEPTH     , val1);
    ISynthCore&lt;0&gt;::control_change(LPF_CUTOFF_ENV, val2);
    ISynthCore&lt;0&gt;::control_change(LPF_RESONANCE , val3);
    ISynthCore&lt;0&gt;::control_change(ENV_A         , val4 );
    ISynthCore&lt;0&gt;::control_change(ENV_D_R       , 1 );
  }

  INLINE static void receive_midi_byte(uint8_t b) {
    ISynthCore&lt;0&gt;::receive_midi_byte(b);
  }

  INLINE static int8_t clock() {
    return ISynthCore&lt;0&gt;::clock();
  }
};
How would I go about passing a void loop analog read value to a library .h file?


What you wanted to do makes little sense. But it is certainly doable. The simplest would be to use an "extern" variable as a bridge.