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
#define BrakeMode
#include "HX711.h"
#include <Joystick.h>
HX711 scale;
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_JOYSTICK, 0, 0, false, false, false, false, false, false, false, false, false, true, false);
#ifdef BrakeMode
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;
@@ -18,6 +23,8 @@ String readString, servo1, servo2;
uint8_t dataPin = 6;
uint8_t clockPin = 7;
long brake_;
long conf_minValue=0;
long conf_maxValue=13000;
void setup()
{
@@ -30,44 +37,92 @@ void setup()
bool showConfig;
bool showValue;
bool showDebug;
long loadCell;
long MinVal=0;
long MaxVal=0;
void loop()
{
brake_ = scale.read();
loadCell = brake_ / 100;
//Min -140550
if(brake_ < MinVal)
MinVal = brake_;
if(loadCell < MinVal)
MinVal = loadCell;
//Max 1253444
if(brake_ > MaxVal)
MaxVal = brake_;
if(brake_ <= 0)
Joystick.setBrake(0);
if(loadCell > MaxVal)
MaxVal = loadCell;
if(loadCell > conf_maxValue)
conf_maxValue = loadCell;
if(loadCell <= conf_minValue)
brake_ = 0;
if(brake_ > 0)
{
brake_ = map(brake_, 0, 1300000, 0, 1024);
Joystick.setBrake(brake_);
}
if(loadCell > conf_minValue)
brake_ = map(loadCell, conf_minValue, (conf_maxValue+1), 0, 1024);
// long test;
// test = map(21320,0,21321,0,1023);
// Serial.println(test);
#ifdef BrakeMode
Joystick.setBrake(brake_);
#else
Joystick.setXAxis(brake_);
#endif
while (Serial.available()) {
if (Serial.available() >0) {
char c = Serial.read(); //gets one byte from serial buffer
if(c == 'v')
showValue=!showValue;
elseif(c == 'c')
else if(c == 'c')
showConfig=true;
else if(c == 'd')
showDebug=!showDebug;
else
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) {
@@ -86,7 +141,7 @@ void loop()
readString="";
}
delay(10);
delay(2);
}