Untitled
unknown
plain_text
2 years ago
5.3 kB
14
Indexable
#include <HX711.h>
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
const int PIN_NEOPIXEL = 32;
// Define HX711 connections entrance load cell
const int doutPin_entrance = 47;
const int sckPin_entrance = 46;
// Define HX711 connections exit load cell
const int doutPin_exit = 43;
const int sckPin_exit = 42;
//entrance led
const int greenled1_pin = 52;
const int redled1_pin = 50;
//exit led
const int greenled2_pin = 53;
const int redled2_pin = 54;
// Declare HX711 instances for entrance and exit load cells
HX711 loadcell_entrance;
HX711 loadcell_exit;
// Define calibration factor
const float calibration_factor_entrance = 21052.08;
const float calibration_factor_exit = 20719.11;
// Define variables
float weight_value_entrance = 0;
float previous_highest_weight_entrance = 0; // Pinaka-taas nga timbang sa nakaraang pagbasa
float highest_weight_entrance = 0; // Pinaka-taas nga timbang sa kasamtangan nga pagbasa
bool interval_active_entrance = false; // Flag alang sa active nga interval
// Define variables
float weight_value_exit = 0;
float previous_highest_weight_exit = 0; // Pinaka-taas nga timbang sa nakaraang pagbasa
float highest_weight_exit = 0; // Pinaka-taas nga timbang sa kasamtangan nga pagbasa
bool interval_active_exit = false; // Flag alang sa active nga interval
const float weight_limit = 500;
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(32, 8, PIN_NEOPIXEL,
NEO_MATRIX_TOP + NEO_MATRIX_LEFT +
NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG,
NEO_GRB + NEO_KHZ800);
const uint16_t color = matrix.Color(255, 0, 0); // Red color for the scale
void setup() {
Serial.begin(9600);
matrix.begin();
matrix.setTextWrap(false);
matrix.setBrightness(10);
matrix.setTextColor(color);
loadcell_entrance.begin(doutPin_entrance, sckPin_entrance);
loadcell_entrance.set_scale(calibration_factor_entrance);
loadcell_entrance.tare();
// Initialize exit load cell
loadcell_exit.begin(doutPin_exit, sckPin_exit);
loadcell_exit.set_scale(calibration_factor_exit); // You need to define calibration_factor_exit for the exit load cell
loadcell_exit.tare();
}
void loop() {
// Basaha ang timbang gikan sa load cell
weight_value_entrance = loadcell_entrance.get_units();
weight_value_exit = loadcell_exit.get_units();
// Clear the display and set cursor position (adjusted)
matrix.fillScreen(0);
int stringSize = matrix.width() - 31;
matrix.setCursor(stringSize, 0);
// Check if the weight exceeds 10 kg
if (weight_value_entrance > 10) {
// If the weight exceeds 10 kg and no interval is active, start the interval
if (!interval_active_entrance) {
interval_active_entrance = true;
previous_highest_weight_entrance = highest_weight_entrance; // I-save ang pinaka-taas nga timbang sa nakaraang interval
highest_weight_entrance = 0; // I-reset ang kasamtangan nga pinaka-taas nga timbang
// Update the highest weight if the current weight is higher
}
Serial.print(weight_value_entrance, 2); //Pinaka-taas nga timbang
Serial.println("Kg");
matrix.print(highest_weight_entrance);
matrix.println("Kg");
digitalWrite(redled1_pin, HIGH);
delay(4000);
digitalWrite(greenled1_pin, HIGH);
highest_weight_entrance = max(highest_weight_entrance, weight_value_entrance);
} else {
// If the weight is below 10 kg, end the interval and update the highest weight
if (interval_active_entrance) {
interval_active_entrance = false;
digitalWrite(greenled1_pin, HIGH);
highest_weight_entrance += previous_highest_weight_entrance; // I-add ang pinaka-taas nga timbang sa nakaraang interval sa kasamtangan nga pinaka-taas nga timbang
Serial.print(highest_weight_entrance, 2); //Pinaka-taas nga timbang
Serial.println("Kg");
matrix.print(highest_weight_entrance);
matrix.println("Kg");
}
}
// Check if the weight from the exit load cell exceeds 10 kg
if (weight_value_exit > 10) {
// If the weight exceeds 10 kg and no interval is active, start the interval
if (!interval_active_exit) {
interval_active_exit = true;
previous_highest_weight_exit = highest_weight_exit; // I-save ang pinaka-taas nga timbang sa nakaraang interval
highest_weight_exit = 0; // I-reset ang kasamtangan nga pinaka-taas nga timbang
}
matrix.print(highest_weight_exit);
matrix.println("Kg");
// Update the highest weight if the current weight is higher
highest_weight_exit = max(highest_weight_exit, weight_value_exit);
} else {
// If the weight is below 10 kg, end the interval and update the highest weight
if (interval_active_exit) {
interval_active_exit = false;
highest_weight_entrance -= highest_weight_exit; // I-add ang pinaka-taas nga timbang sa nakaraang interval sa kasamtangan nga pinaka-taas nga timbang
Serial.println(highest_weight_entrance); //total nga timbang
}
matrix.print(highest_weight_entrance);
}
matrix.show();
}
Editor is loading...
Leave a Comment