I want to use analog inputs for my potentiometers to control audio speed and volume, but I don't want to use the ADC on the Bela Mini as its expensive if I want to make multiple of these boards.

Currently I am using the following script as an AuxiliaryTask:

#define LDR_PATH "/sys/bus/iio/devices/iio:device0/in_voltage5_raw"
int number;
void readAdc(void *){
        stringstream ss;
   	ss << LDR_PATH;
   	fstream fs;
   	fs.open(ss.str().c_str(), fstream::in);
   	fs >> number;
   	fs.close();
}

This worked well, except sometimes it drops readings and defaults to 0. I also tried putting this code in the loop when the audio is being played back, but that cause my CPU to spike.

Are there any examples on how to access the Pocket Beagle ADC pins so I can utilize them?

Thanks!

    Please always enclose your code in triple backticks ```\ (I edited your message above to make it readable).

    I haven't used those ADCs in years.

    Derek Molloy tends to cover Beaglebone very well, I am sure most of the details there would be transferrable to the PocketBeagle.

    What you are doing seems in principle right, assuming the LDR_PATH is right.
    However, it seems a bit of a waste to:
    - allocate memory for the string
    - copy he path to the string
    - open the file
    - close the file
    every time you want a read. This is definitely not very CPU friendly. You should only perform the read (fs >> number;) in the aux task, everything else should be done at setup() or cleanup().

    ifenta I also tried putting this code in the loop when the audio is being played back, but that cause my CPU to spike.

    What does this mean? How are you running in it when audio is not being played backk?
    How often are you scheduling that AuxiliaryTask?

    ifenta I want to make multiple of these boards.

    You may be interested in reading the MAKING PRODUCTS WITH BELA section here

      have you tried the above?

      Another thing:

      giuliomoro How often are you scheduling that AuxiliaryTask?

      That should probably be not more often than every 1ms or so. You can also decide to to schedule it only once, and add a while() loop in the auxiliary task. This loop will have to check for the gShouldStop variable and usleep() in between iterations.
      This, combined with the suggestions above, will result in:

      int number;
      void readAdc(void *){
          while(!gShouldStop) {
         	fs >> number;
              usleep(1000);
          }
      }

      and the rest of your code should go in setup(), except for fs.close();, which should go in cleanup()