Potentiometer cannot get picked up by analogRead function

I am having trouble connecting a potentiometer to my project. I have a guitarpedal that is inserted in the A0 port. Then when I connect the potentiometer the rest of the code stops working. I have read that you have to write 2 “analogRead(pin)” with a decent amount of delay between them to get it work but it doesn’t for me. Any help with understanding how bytes work and how to get the potentimeter to work is appreciated!

Code and schematics is attached.

//defining harware resources.
#define LED 13
#define FOOTSWITCH 12
#include "Volym.h"

//#define TOGGLE 2
//#define PUSHBUTTON_1 A5
//#define PUSHBUTTON_2 A4
#define KNOB A5

//defining the output PWM parameters
#define PWM_FREQ 0x00FF // pwm frequency - 31.3KHz
#define PWM_MODE 3 // Fast (1) or Phase Correct (0)
#define PWM_QTY 2 // 2 PWMs in parallel

//other variables
int counter = 0;
int counter2 = 0;
int counter3 = 0;
int input;
int dist_variable=20;
int distortion_threshold=6000;
byte ADC_low, ADC_high;
int sensorValue = analogRead(KNOB);
int sensorValue2 = analogRead(KNOB);

void setup() {
  pinMode(FOOTSWITCH, INPUT_PULLUP);
  pinMode(LED, OUTPUT);
  Serial.begin(9600);
  sensorValue = analogRead(KNOB);
  delay(10);
  sensorValue = analogRead(KNOB);
  delay(10);
  Serial.print(sensorValue);
  
  // setup ADC 
  ADMUX = 0x60; // left adjust, adc0, internal vcc
  ADCSRA = 0xe5; // turn on adc, ck/32, auto trigger
  ADCSRB = 0x07; // t1 capture for trigger
  DIDR0 = 0x01; // turn off digital inputs for adc0

  // setup PWM
  TCCR1A = (((PWM_QTY - 1) << 5) | 0x80 | (PWM_MODE << 1)); //
  TCCR1B = ((PWM_MODE << 3) | 0x11); // ck/1
  TIMSK1 = 0x20; // interrupt on capture interrupt
  ICR1H = (PWM_FREQ >> 8);
  ICR1L = (PWM_FREQ & 0xff);
  DDRB |= ((PWM_QTY << 1) | 0x02); // turn on outputs
  sei(); // turn on interrupts - not really necessary with arduino
}

void loop() {
  if (digitalRead(FOOTSWITCH)) digitalWrite(LED, HIGH); 
    else  digitalWrite(LED, LOW);
  //float gain_power = calculateGain();
  
}

ISR(TIMER1_CAPT_vect) {
counter3++;
if(counter3==5000){
    //delay(10);
    //sensorValue = analogRead(KNOB);
    //delay(10);
    //sensorValue = analogRead(KNOB);
    //delay(10);
    //float voltage = sensorValue * (5.0 / 1023.0);
    //Serial.println(voltage);
}
counter++; //to save resources, the pushbuttons are checked every 2000 times.
if(counter==2000)
{
  counter=0;
  sensorValue = analogRead(KNOB);
  delay(10);
  sensorValue = analogRead(KNOB);
  delay(10);
  float voltage = sensorValue * (5.0 / 1023.0);
  Serial.println(voltage);
  
  if (sensorValue > sensorValue2) {
    
    if (dist_variable<500)dist_variable++;
      
    digitalWrite(LED, LOW); //blinks the led
      
  }

  if (sensorValue < sensorValue2) {
    if (dist_variable>0)dist_variable--; 
    digitalWrite(LED, LOW); //blinks the led
   
  }
  sensorValue2 = sensorValue;
}
  counter2++;
  
  if(counter2>=dist_variable)
  { 
    counter2=0;

    
    // get ADC data
    ADC_low = ADCL; // you need to fetch the low byte first
    ADC_high = ADCH;
    //construct the input sumple summing the ADC low and high byte.
    input = ((ADC_high << 8) | ADC_low) + 0x8000; // make a signed 16b value
  
    OCR1AL = ((input + 0x4000) >> 8); // convert to unsigned, send out high byte
    OCR1BL = input; // send out low byte
    
    if(input>distortion_threshold) input=32768;
    else if(input<-distortion_threshold) input=-32768;
  }
}

Image from Original Post so we don’t have to download it. See this Simple Image Guide

a632e1ed154ca9f121e8a0a687c1ef8c814671eb.png

…R

I can't read the diagram because it is too small and you have a lot of references to registers in your code and I am too lazy to spend half an hour or more with the Atmega 328 datasheet trying to figure out what your program is supposed to do.

Perhaps you can provide a description of the different parts of the program.

...R

There is low level code, probably to increase the sampling rate. It may be interfering with the core analogRead() function.

You can not use delay() in an ISR because interrupts are disabled and millis() is frozen.

Also yes, the diagram is unreadable. Please provide a link to the original project.

Sorry for the lack of information! Here's the original post:

EDIT: Wrong page, this is the real one

https://www.electrosmash.com/pedalshield-uno

One thing I'm not clear on - have you made any changes to the code that you posted a link to? Also, does your hardware differ from what is there? If the answer to either of these is "yes", then you need to document the differences here, in order to get any useful assistance.

The only change I’ve made on the hardwear is that I connected a 100k potentiometer to port A5 to read out the analog signals. The code is mostly the original, the only thing I’ve changed is a few variable numbers that only changes the sound that the guitar produced. I’ve also removed the previous pushbuttons that controlled the sound and tried to write my own code to work with the potentiometer. So far I’ve not been able to read both the analog signals from the guitar and the potentiometer, it’s either the one or the other. The guitar seems to always pump in analog signals and when I try to read from the potentiometer the guitar signals can’t be read and just shuts down completely if I’ve understood it correctly. As I said I’m not familar with programming in bytes so I need help to figure out how to stop the analog signals from the guitar from being read while the potentiometer gets read so they don’t crash on one another.

Please ask more questions on what you need to know to be able to help me, I’ll try to answer them with the information I have.