How reduce size of program and variables

Hello everyone,
I’m completing a program which reads the weight values from two scale connecting to HX711 boards and send them via I2C to another Arduino controller. I am beginner in programming and I am interested to learn how can I read and send my data in optimum way without declaring twice or three times all of the values
Appreciate your help

#include “HX711.h”
#include <Wire.h>

#define calibration_factor -117250.0 //This value is obtained using the SparkFun_HX711_Calibration sketch
#define calibration_factor1 -117260.0 //This value is obtained using the SparkFun_HX711_Calibration sketch

#define DOUT 3
#define CLK 2
#define DOUT2 5
#define CLK2 4
HX711 scale(DOUT, CLK);
HX711 scale1(DOUT2, CLK2);

const int numReadings = 10;
int readings[numReadings]; // the readings from the Hx711
int readIndex = 0; // the index of the current reading
int total = 0; // the running total
int average = 0; // the average

void setup() {
Wire.begin(8); // join i2c bus with address #8
Wire.onRequest(requestEvent); // register event
Serial.begin(9600);
Serial.println(“HX711 scale demo”);
scale.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch
scale1.set_scale(calibration_factor1); //This value is obtained by using the SparkFun_HX711_Calibration sketch
scale.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0
scale1.tare(); //Assuming there is no weight on the scale1 at start up, reset the scale to 0

for (int thisReading = 0; thisReading < numReadings; thisReading++) { // initialize all the readings to 0
readings[thisReading] = 0;
}
Serial.println(“Readings:”);
}

void loop() {

Serial.print(“Reading: “);
Serial.print(scale.get_units()*453.529, 0); //scale.get_units() returns a float
Serial.print(” gr”);
Serial.print(" \t");

Serial.print(scale1.get_units()*453.529, 0);
Serial.print(" gr"); //You can change this to kg but you’ll need to refactor the calibration_factor
Serial.println();
delay (1);

}
void requestEvent()
{
int32_t Scale0= scale.get_units()*453.529 ;
int32_t Scale1= scale1.get_units()*453.529 ;
byte myArray[8];

myArray[0] = (Scale0 >> 24) &0xFF;
myArray[1] = (Scale0 >> 16) &0xFF;
myArray[2] = (Scale0 >> 8) &0xFF;
myArray[3] = Scale0 & 0xFF;
myArray[4] = (Scale1 >> 24) &0xFF;
myArray[5] = (Scale1 >> 16) &0xFF;
myArray[6] = (Scale1 >> 8) &0xFF;
myArray[7] = Scale1 & 0xFF;

Wire.write(myArray, 8);
}

Your program isn't very big in the first place, excluding your includes. There aren't any raging inefficiencies I can immediately see, and if this is the only code running on the Arduino it is more than capable of handling it even if it were inefficient.

Did you consider using a for loop for the following?

myArray[0] = (Scale0 >> 24) &0xFF;
myArray[1] = (Scale0 >> 16) &0xFF;
myArray[2] = (Scale0 >>  &0xFF;
myArray[3] = Scale0 & 0xFF;
myArray[4] = (Scale1 >> 24) &0xFF;
myArray[5] = (Scale1 >> 16) &0xFF;
myArray[6] = (Scale1 >>  &0xFF;
myArray[7] = Scale1 & 0xFF;

To be fair it wont make your code faster, or even save much program memory with only two scales connected.

Thanks for your answer,
the thing is I would like to reduce rewriting the codes but i don't know how can i do this! could you please,tell me how to use for loop & if functions to avoid rewriting and declaring extra variables?
Thanks a lot

You can save a loop by assigning 0 to readings when you declare it.

is getunits() a function in a library? Do you need 32 bits there? You end up getting
rid of a lot of the bits.

I don't know about the data your working on, so hard to say.

Maybe combining gr and \t in one serial print.