#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include "HX711_ADC.h"
#define DEBUG 0
#if DEBUG
#define PRINT(s, x) \
{ \
Serial.print(F(s)); \
Serial.print(x); \
}
#define PRINTS(x) Serial.print(F(x))
#define PRINTX(x) Serial.println(x, HEX)
#else
#define PRINT(s, x)
#define PRINTS(x)
#define PRINTX(x)
#endif
#define HARDWARE_TYPE MD_MAX72XX:: PAROLA_HW//FC16_HW
#define MAX_DEVICES 4
#define CLK_PIN 13
#define DATA_PIN 11
#define CS_PIN 10
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
const uint8_t DIRECTION_SET = 8;
const uint8_t INVERT_SET = 9;
const uint8_t SPEED_DEADBAND = 5;
uint8_t scrollSpeed = 40; // higher for slower scroll
textEffect_t scrollEffect = PA_SCROLL_LEFT;
textPosition_t scrollAlign = PA_LEFT;
uint16_t scrollPause = 0; // in milliseconds
#define BUF_SIZE 75
char curMessage[BUF_SIZE] = { "" };
char newMessage[BUF_SIZE] = { "Three Mile Creek Primary Popsicle Stick Bridge Tester" };
bool newMessageAvailable = true;
unsigned long t = 0;
// Pin configurations
const int HX711_dout = 4; // Connect this to the DOUT pin of HX711
const int HX711_sck = 5; // Connect this to the SCK pin of HX711
// HX711 Constructor:
HX711_ADC LoadCell(HX711_dout, HX711_sck);
const float LOAD_THRESHOLD_POUNDS = 2.39;
float maxLoadPounds = 0.0;
bool showMaxLoad = false;
void setup() {
Serial.begin(57600);
P.begin();
P.displayText(curMessage, scrollAlign, scrollSpeed, scrollPause, scrollEffect, scrollEffect);
Serial.println();
Serial.println("Starting...");
LoadCell.begin();
// LoadCell.setReverseOutput(); // uncomment to turn a negative output value to positive
float calibrationValue = 9440; // calibration value
unsigned long stabilizingtime = 2000; // precision right after power-up can be improved by adding a few seconds of stabilizing time
boolean _tare = false; // set this to false if you don't want tare to be performed in the next step
LoadCell.start(stabilizingtime, _tare);
if (LoadCell.getTareTimeoutFlag()) {
Serial.println("Timeout, check MCU>HX711 wiring and pin designations");
while (1)
;
} else {
LoadCell.setCalFactor(calibrationValue); // set calibration value (float)
Serial.println("Startup is complete");
}
}
void loop()
{
if (P.displayAnimate())
{
if (newMessageAvailable)
{
strcpy(curMessage, newMessage);
newMessageAvailable = false;
}
P.displayReset();
}
static boolean newDataReady = false;
//increase value to slow down serial print activity
const int serialPrintInterval = 100;
// check for new data/start next conversion:
if (LoadCell.update()) {
newDataReady = true;
}
// print smoothed value from the dataset:
if (newDataReady) {
if (millis() > t + serialPrintInterval) {
float i =
LoadCell.getData();
Serial.print("");
Serial.println(i);
newDataReady = false;
t = millis();
}
}
long reading = LoadCell.getData();
float loadPounds = reading;
float showLoad = loadPounds;
if (loadPounds >= maxLoadPounds){
maxLoadPounds = loadPounds;
} else
if (loadPounds <= (0.7 * maxLoadPounds)) {
showLoad = maxLoadPounds;
}
displayLoad(showLoad);
}
void displayLoad(float loadPounds){
char buffer[10];
P.displayText(dtostrf(loadPounds, 4, 1, buffer), PA_RIGHT, 0, 0, PA_PRINT, PA_NO_EFFECT);
}
/*
void loop() {
if (P.displayAnimate()) {
if (newMessageAvailable) {
strcpy(curMessage, newMessage);
newMessageAvailable = false;
}
P.displayReset();
}
static boolean newDataReady = false;
const int serialPrintInterval = 50; // increase value to slow down serial print activity
// check for new data/start next conversion:
if (LoadCell.update()) newDataReady = true;
// get smoothed value from the dataset:
if (newDataReady) {
if (millis() > t + serialPrintInterval) {
double reading = LoadCell.getData();
float loadPounds = reading;
Serial.print("Load: ");
Serial.println(loadPounds,1);
if (loadPounds >= LOAD_THRESHOLD_POUNDS) {
// Show load as an integer
char buffer[10];
P.displayText(dtostrf(loadPounds, 4, 1, buffer), PA_RIGHT, 0, 0, PA_PRINT, PA_NO_EFFECT);
showMaxLoad = true;
}
if (loadPounds >= maxLoadPounds) {
maxLoadPounds = loadPounds;
}
if (showMaxLoad && (loadPounds <= (0.7 * maxLoadPounds))) {
// Check if load decreased by 30%
char buff[10];
P.displayText(dtostrf(loadPounds, 4, 1, buff), PA_RIGHT, 0, 0, PA_PRINT, PA_NO_EFFECT);
showMaxLoad = false;
}
newDataReady = false;
t = millis();
}
}
}
*/