Code V.01

Libraries

We use several libraries in the code to help you quickly and easily control different parts and do specific things with your code. You can find all the libraries used in the project folder under “Libraries”

//LOAD CELL LIB
#include "HX711.h"
HX711 scale;
//OLED DISP LIB
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// Real Time Clock LIB
#include "Arduino.h"
#include "uRTCLib.h"
uRTCLib rtc(0x68);  // uRTCLib rtc;
Defines

We define pins, loadcells factor. To calculate your calibration factor….


// LOAD CELL DEFINES
#define LOADCELL_DOUT_PIN 2
#define LOADCELL_SCK_PIN 0
float calibration_factor = 27; //need to check
int weigth = 0;

The same for OLED display, depends if you use the same…

// OLED DISP DEFINES
#define SCREEN_WIDTH 128  // OLED display width, in pixels
#define SCREEN_HEIGHT 64  // OLED display height, in pixels
// Declaration for SSD1306 display connected using I2C
#define OLED_RESET -1  // Reset pin
#define SCREEN_ADDRESS 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
const int bufferSize = 4;  // Size of the circular buffer
struct Measurement {
  char Calendar[20];
  float weight;
};
Measurement measurements[bufferSize];  // Array to store the measurements
int currentIndex = 0;                  // Index to keep track of the current position in the buffer
// Motor DEFINES
 // Motor A connections
#define enA 15
#define in1 13
#define in2 12
float cal = 0.0007;  // auxiliary declaration of an initial Calibration value
// calibration for 6V 10rpm float cal = 0.00075;
int16_t Hour_A;  // 32767.. +32767  optimize the data type
int16_t Hour_B;
int16_t Minute_A;
int16_t Minute_B;
int16_t Meal_size_A;
int16_t Meal_size_B;