Storing and sequencing output value (arduino) I am new to Arduino programming, after days and nights trying to use array,for loop and googling a lot of article, I still unable to find the way how to store each weighing output value from int Sampling() to be executed by the respective servo in sequence order.
If you have any clue to share and help me, I'll be very happy. Thank You very much.
Below is my base code.
#include &lt;HX711.h&gt;
///////////////////////////////////////////////////////////////////////
#define calibration_factor -251 
#define LOADCELL_DOUT_PIN 7   // data 
#define LOADCELL_SCK_PIN 8    // sck 
////////////////////////////////////////////////////////////////////////
HX711 scale;
////////////////////////////////////////////////////////////////////////
int servo1 = 12;
int servo2 = 13;
int proxiPin1 = 2;
int proxiPin2 = 3;
////////////////////////////////////////////////////////////////////////
int toggleState = 0;
int proxiState1 = 1;
int proxiState2 = 1;
////////////////////////////////////////////////////////////////////////
int weight;
int weightFinal;
////////////////////////////////////////////////////////////////////////
void setup()
{
  Serial.begin(9600);
  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
  scale.set_scale(calibration_factor);
  scale.tare();

  pinMode(servo1, OUTPUT); // simulating servo1
  pinMode(servo2, OUTPUT); // simulating servo2
  pinMode(proxiPin1, INPUT_PULLUP); // proximity
  pinMode(proxiPin2, INPUT_PULLUP); // proximity

}
/////////////////////////////////////////////////////////////////////////
void loop()
{
  Serial.print(Sampling());
  Serial.print(&quot; gram&quot;);
  Serial.println();
  ///////////////////////////////////////////////////////////////////////
  if ( weightFinal == 10 )
  {
    toggleState = true;
    servo10gr();
  }

  if ( weightFinal == 20 )
  {
    toggleState = true;
    servo20gr();
  } 
}
////////////////////////////////////////////////////////////////////////
int Sampling()
{
  int weight = scale.get_units();

  if (weight &gt;= 10  &amp;&amp; weight&lt; 20)
  {
    weightFinal = 10;
  }

  else if (weight &gt;= 20  &amp;&amp; weight &lt; 30)
  {
    weightFinal = 20;
  }

  return weight;
}
/////////////////////////////////////////////////////////////////////////
int servo10gr()
{
  proxiState1 = digitalRead(proxiPin1);
  if ( proxiState1 == 0 &amp;&amp; toggleState == true )
  {
    digitalWrite(servo1, HIGH);  //Simulating servo signal Pin//
    delay(500);                  
    digitalWrite(servo1, LOW);  

    toggleState = false;
    weightFinal=0;
  }
}
/////////////////////////////////////////////////////////////////////////
int servo20gr()
{
  proxiState2 = digitalRead(proxiPin2);
  if ( proxiState2 == 0 &amp;&amp; toggleState == true )
  {
    digitalWrite(servo2, HIGH);    //Simulating servo signal Pin//
    delay(500);                    
    digitalWrite(servo2, LOW);    

    toggleState = false;
    weightFinal=0;
  }
}
I'm still not entirely sure what you want to achieve, but maybe this will help:
You have a global variable int weight, and in int Sampling() you create another int weight = scale.get_units() which you give a value.
That second variable is only accessible inside of Sampling(). If you want to use it elsewhere for storing or in other functions, change:
int weight = scale.get_units();
to
weight = scale.get_units();
and you can then use weight wherever you like in your code, also in servo10gr() and servo20gr().
You don't need to store a sequence of weights to drive the servos; you can just use the current weight immediately to drive a servo and then get a new weight.
If, however, you want or need to keep a list of weights for some reason, there's a bit more work to be done.
There are better ways of going about this, but let's see first if this solves your problem.