Read analog input with interruption

Hi !

I have a problem with the Analog input. I want to build a Arduino audio input (https://www.instructables.com/Arduino-Audio-Input/) but, i want the controller some parameters with using a potentiometer with the analog input.

I used the code in PedalShield Electrosmashb prototype .

// [www.Electrosmash.com/rights](http://www.electrosmash.com/rights) CC-by-NC

//defining hardware resources.
#define LED 13
#define FOOTSWITCH 12
#define TOGGLE 2
#define PUSHBUTTON_1 A5
#define PUSHBUTTON_2 A4

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

//other variables
int input;
unsigned int ADC_low, ADC_high;

void setup() {
//setup IO
pinMode(FOOTSWITCH, INPUT_PULLUP);
pinMode(TOGGLE, INPUT_PULLUP);
pinMode(PUSHBUTTON_1, INPUT_PULLUP);
pinMode(PUSHBUTTON_2, INPUT_PULLUP);
pinMode(LED, OUTPUT);
pinMode(6, OUTPUT); //PWM0 as output
pinMode(7, OUTPUT); //PWM1 as output

// setup ADC
ADMUX = 0x60; // left adjust, adc0, internal vcc
ADCSRA = 0xe5; // turn on adc, ck/32, auto trigger
ADCSRB = 0x00; //free running mode
DIDR0 = 0x01; // turn off digital inputs for adc0

// setup PWM
TCCR4A = (((PWM_QTY - 1) << 5) | 0x80 | (PWM_MODE << 1)); //
TCCR4B = ((PWM_MODE << 3) | 0x11); // ck/1
TIMSK4 = 0x20; // interrupt on capture interrupt
ICR4H = (PWM_FREQ >> ![8)|20x20])
ICR4L = (PWM_FREQ & 0xff);
DDRB |= ((PWM_QTY << 1) | 0x02); // turn on outputs
sei(); // turn on interrupts - not really necessary with arduino
}

void loop()
{
//Turn on the LED and write the OLED if the effect is ON.
if (digitalRead(FOOTSWITCH))
digitalWrite(LED, HIGH); //light the LED
else
digitalWrite(LED, LOW); // switch-off the LED
}

ISR(TIMER4_CAPT_vect)
{
// 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)|20x20]| ADC_low) + 0x8000; // make a signed 16b value

/**********************************************/
/** READ THE A1 , A2 AND A3 PIN */
/**********************************************/

//write the PWM signal
OCR4AL = ((input + 0x8000) >> ![8)|20x20](https://www.electrosmash.com/media/kunena/emoticons/cool.png "8)"); // convert to unsigned, send out high byte
OCR4BL = input; // send out low byte
}

I am conected the potentiometer in the A1, A2 and A3 input.

The question is... How can read the value in the potentiometer ?? Because i cannot used the analogRead function.... Can??

Thanks in advance

Jota

The problem is you have copied down someone’s code , but I suspect don’t understand it .
This is fraught with problems .

There are examples for analog signals in the IDE .
I don’t really understand what you really want to do , or what your project is about from your post .

Of course you can use the analogRead() function. People have been using it for more than a decade. Why didn't you even try?

Also, if you are guessing at how to connect the potentiometers and it doesn't work, please post a diagram of your connection. Whenever you get around to working on your project...

Hi

Thanks for the fast answer . I will explained my project.

I want to used the Arduino with a guitar pedal effects. I used this project ElectroSmash - pedalSHIELD UNO Arduino Guitar Pedal. . I built a PCB board, but i added 3 potentiometer in the pins A1, A2, and A3 for read this values and change the parameters in the guitar effects.

I used this schematic for built the pcb

My modification is added the 3 potentiometer in the pins A1, A2 and A3.

The pcb worked. If I up the code, i have the sound, and the project work. What is the problem? When I try to read the A1 with analogRead the project doesnot work, and i havent effect sound.

Then , i think that when i used the interruption for read the analog pins A0 (this pin received the audio signal ) i cannot used the analogRead for the A1 ...

This is my problem..

Then, i want to understand how can built it for get the sound in the A0 pin, and read the value in the A1 pin ..

Thanks for the help me :smiley:

You used words instead of diagrams to show how the potentiometers are connected. Please add diagrams.

HI

This is the pots schema

2021-08-02 09_12_45-Eeschema — ArduinoUnoR3_Shield.sch _ — C__Users_LordJota_Desktop_ProyectosKowk

Thanks !

The Arduino only has a single ADC, you cannot use it for reading potentiometer values while sampling audio simultaneously.

Why are you reading the ADC result in a timer interrupt? Why not in the ADC interrupt?

How do you parse this?