Update HX-Joystick.ino
Update 20260114-01
This commit is contained in:
@@ -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;
|
||||||
|
|
||||||
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;
|
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,44 +37,92 @@ 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) {
|
||||||
char c = Serial.read(); //gets one byte from serial buffer
|
char c = Serial.read(); //gets one byte from serial buffer
|
||||||
if(c == 'v')
|
if(c == 'v')
|
||||||
showValue=!showValue;
|
showValue=!showValue;
|
||||||
elseif(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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user