AnalogPin as Inputparameter for function?

Hello everyone,

I'd like to modularize my program.
Therefore I need a function called readAnalogValue();

Out of my void loop() function I want to open the readAnalogValue function with input parameter of the desired analog pin.

E.g.

void loop()
{

  
  int actualFeedback = readAnalogValue (A0);
  
}





int readAnalogValue (int SensorNumber)
{

  int sensorValue = analogRead(SensorNumber);

  return sensorValue;

I actually have no arduino here to test the function.
I really dont know if the input parameter of the function readAnalogValue works well with an integer.
But the compiler said it'll be ok.

julianpe:
Therefore I need would like to make :wink: a function called readAnalogValue();

But yeay, that will work just fine. But a byte would also just work fine :slight_smile:

int readAnalogValue (byte sensorNumber)
{
  return analogRead(sensorNumber);;
}

But I have no idea why you would only wrap the analogRead() function into a new function....

And please, use code tags next time! :wink: