Update HX-Joystick.ino

Update 20260114-01
This commit is contained in:
2026-01-14 13:50:19 -05:00
parent 5e56b84a37
commit e57951a44c

View File

@@ -5,12 +5,17 @@
// URL: https://github.com/RobTillaart/HX711 // URL: https://github.com/RobTillaart/HX711
#define BrakeMode
#include "HX711.h" #include "HX711.h"
#include <Joystick.h> #include <Joystick.h>
HX711 scale; HX711 scale;
#ifdef BrakeMode
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_JOYSTICK, 0, 0, false, false, false, false, false, false, false, false, false, true, false); Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_JOYSTICK, 0, 0, false, false, false, false, false, false, false, false, false, true, false);
#else
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_JOYSTICK, 0, 0, true, false, false, false, false, false, false, false, false, false, false);
#endif
String readString, servo1, servo2; String readString, servo1, servo2;
@@ -18,6 +23,8 @@ String readString, servo1, servo2;
uint8_t dataPin = 6; uint8_t dataPin = 6;
uint8_t clockPin = 7; uint8_t clockPin = 7;
long brake_; long brake_;
long conf_minValue=0;
long conf_maxValue=13000;
void setup() void setup()
{ {
@@ -30,29 +37,39 @@ void setup()
bool showConfig; bool showConfig;
bool showValue; bool showValue;
bool showDebug;
long loadCell;
long MinVal=0; long MinVal=0;
long MaxVal=0; long MaxVal=0;
void loop() void loop()
{ {
brake_ = scale.read(); brake_ = scale.read();
loadCell = brake_ / 100;
//Min -140550 //Min -140550
if(brake_ < MinVal) if(loadCell < MinVal)
MinVal = brake_; MinVal = loadCell;
//Max 1253444 //Max 1253444
if(brake_ > MaxVal) if(loadCell > MaxVal)
MaxVal = brake_; MaxVal = loadCell;
if(loadCell > conf_maxValue)
conf_maxValue = loadCell;
if(loadCell <= conf_minValue)
brake_ = 0;
if(brake_ <= 0) if(loadCell > conf_minValue)
Joystick.setBrake(0); brake_ = map(loadCell, conf_minValue, (conf_maxValue+1), 0, 1024);
if(brake_ > 0) // long test;
{ // test = map(21320,0,21321,0,1023);
brake_ = map(brake_, 0, 1300000, 0, 1024); // Serial.println(test);
#ifdef BrakeMode
Joystick.setBrake(brake_); Joystick.setBrake(brake_);
} #else
Joystick.setXAxis(brake_);
#endif
while (Serial.available()) { while (Serial.available()) {
if (Serial.available() >0) { if (Serial.available() >0) {
@@ -61,13 +78,51 @@ void loop()
showValue=!showValue; showValue=!showValue;
else if(c == 'c') else if(c == 'c')
showConfig=true; showConfig=true;
else if(c == 'd')
showDebug=!showDebug;
else else
readString += c; //makes the string readString readString += c; //makes the string readString
} }
} }
if (showConfig) { if (showValue) {
Serial.println(brake_);
}
if (showDebug) {
Serial.print(brake_);
Serial.print(", ");
Serial.print(loadCell);
Serial.print(", ");
Serial.print(MinVal);
Serial.print(", ");
Serial.print(MaxVal);
Serial.println();
}
if (showConfig) {
showConfig = false;
Serial.println("DAProgs Handbrake Joystick. v1.0");
Serial.println("Configs:");
Serial.print(" minVal=");
Serial.println(MinVal);
Serial.print(" maxVal=");
Serial.println(MaxVal);
Serial.print(" zero=");
Serial.println(conf_minValue);
Serial.print(" maximum=");
Serial.println(conf_maxValue);
Serial.print(" Current=");
Serial.println(brake_);
#ifdef BrakeMode
Serial.println(" mode=brake");
#else
Serial.println(" mode=axis");
#endif
Serial.println("");
} }
if (readString.length() >0) { if (readString.length() >0) {
@@ -86,7 +141,7 @@ void loop()
readString=""; readString="";
} }
delay(10); delay(2);
} }