reworked Pedal Input
This commit is contained in:
@@ -13,6 +13,12 @@ platform = atmelavr
|
|||||||
board = nanoatmega328new
|
board = nanoatmega328new
|
||||||
framework = arduino
|
framework = arduino
|
||||||
|
|
||||||
|
[env:megaatmega2560]
|
||||||
|
platform = atmelavr
|
||||||
|
board = megaatmega2560
|
||||||
|
framework = arduino
|
||||||
|
|
||||||
|
|
||||||
;upload_protocol = custom
|
;upload_protocol = custom
|
||||||
;upload_flags =
|
;upload_flags =
|
||||||
; -C
|
; -C
|
||||||
|
|||||||
@@ -1,151 +1,266 @@
|
|||||||
// PedalController.cpp
|
// PedalController.cpp
|
||||||
#include "PedalController.h"
|
#include "PedalController.h"
|
||||||
|
|
||||||
const int minMin = 50; // Minimum allowed raw value for calibration
|
// Basiskonfiguration
|
||||||
const int maxMin = 200; // Maximum allowed raw value for calibration
|
static const PedalConfig defaultConfig = {
|
||||||
const int minMax = 800; // Minimum allowed maximum value for calibration
|
|
||||||
const int maxMax = 1000; // Maximum allowed raw value for calibration
|
|
||||||
|
|
||||||
const PedalConfig defaultConfig = {
|
|
||||||
.minRaw = 0,
|
.minRaw = 0,
|
||||||
.maxRaw = 1023,
|
.maxRaw = 1023,
|
||||||
.calibrated = false
|
.calibrated = false,
|
||||||
};
|
.filterStrength = 8 // 8er Moving Average als Standard
|
||||||
|
};
|
||||||
|
|
||||||
PedalController::PedalController(int pin)
|
// Tuning-Konstanten für die Auto-Cal
|
||||||
: pedalPin(pin)
|
static const int STABLE_THRESHOLD = 3; // zulässige ADC-Differenz für "stabil"
|
||||||
|
static const unsigned long STABLE_TIME = 1000; // ms, die der Wert stabil sein muss
|
||||||
|
static const unsigned long SWEEP_TIME = 3000; // ms für die Sweep-Phase
|
||||||
|
static const int MIN_RANGE = 50; // minimale Spannweite min/max
|
||||||
|
static const int SAFETY_MARGIN_LOW = 5; // Puffer unten
|
||||||
|
static const int SAFETY_MARGIN_HIGH = 5; // Puffer oben
|
||||||
|
static const uint8_t MIN_FS = 2;
|
||||||
|
static const uint8_t MAX_FS = 32;
|
||||||
|
static const uint8_t DEFAULT_FS = 8;
|
||||||
|
|
||||||
|
PedalController::PedalController(int analogPin,
|
||||||
|
int digitalPin,
|
||||||
|
uint8_t digitalNotPressedLevel)
|
||||||
|
: analogPin(analogPin),
|
||||||
|
digitalPin(digitalPin),
|
||||||
|
useDigital(digitalPin >= 0),
|
||||||
|
digitalNotPressedLevel(digitalNotPressedLevel ? 1 : 0),
|
||||||
|
filteredValue(-1),
|
||||||
|
calState(IDLE),
|
||||||
|
calStep(0),
|
||||||
|
stepStartTime(0),
|
||||||
|
lastChangeTime(0),
|
||||||
|
lastSample(0),
|
||||||
|
minSeen(1023),
|
||||||
|
maxSeen(0)
|
||||||
{
|
{
|
||||||
|
if (useDigital)
|
||||||
|
{
|
||||||
|
pinMode(digitalPin, INPUT); // Hall-Module haben normalerweise eigenen Pullup
|
||||||
|
}
|
||||||
|
|
||||||
loadDefaults();
|
loadDefaults();
|
||||||
pinMode(pedalPin, INPUT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PedalController::loadDefaults()
|
// Rohwert lesen und glätten
|
||||||
|
int PedalController::readRaw()
|
||||||
{
|
{
|
||||||
config = defaultConfig;
|
int raw = analogRead(analogPin);
|
||||||
|
return applySmoothing(raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
int PedalController::applySmoothing(int rawValue)
|
int PedalController::applySmoothing(int raw)
|
||||||
{
|
{
|
||||||
filteredValue = (filteredValue * (config.filterStrength - 1) + rawValue) / config.filterStrength;
|
uint8_t fs = config.filterStrength;
|
||||||
return filteredValue;
|
|
||||||
|
// Filter deaktiviert? Direkt durchreichen.
|
||||||
|
if (fs <= 1)
|
||||||
|
{
|
||||||
|
filteredValue = raw;
|
||||||
|
return raw;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Erster Wert: direkt übernehmen
|
||||||
|
if (filteredValue < 0)
|
||||||
|
{
|
||||||
|
filteredValue = raw;
|
||||||
|
return raw;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 32-Bit Akkumulator, um Überlauf zu vermeiden
|
||||||
|
int32_t acc = filteredValue * (int32_t)(fs - 1) + raw;
|
||||||
|
filteredValue = acc / fs;
|
||||||
|
|
||||||
|
return (int)filteredValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
CalibrationState PedalController::autoCalibrate(bool reset)
|
CalibrationState PedalController::autoCalibrate(bool reset)
|
||||||
{
|
{
|
||||||
static int step = 0;
|
unsigned long now = millis();
|
||||||
static unsigned long lastChangeTime = 0;
|
|
||||||
static int previousValue = 0;
|
|
||||||
static CalibrationState errorState = IDLE;
|
|
||||||
|
|
||||||
if (reset)
|
if (reset)
|
||||||
{
|
{
|
||||||
step = 0;
|
// Konfiguration auf Defaults zurücksetzen
|
||||||
config.minRaw = 1023;
|
config = defaultConfig;
|
||||||
config.maxRaw = 0;
|
|
||||||
lastChangeTime = millis();
|
|
||||||
config.calibrated = false;
|
config.calibrated = false;
|
||||||
errorState = IDLE;
|
|
||||||
Serial.println("Calibration reset.");
|
// interne Zustände für die Kalibrierung
|
||||||
return IDLE;
|
calState = RUNNING;
|
||||||
|
calStep = 1; // Schritt 1: Pedal losgelassen
|
||||||
|
stepStartTime = now;
|
||||||
|
lastChangeTime = now;
|
||||||
|
|
||||||
|
filteredValue = -1;
|
||||||
|
int raw = readRaw();
|
||||||
|
lastSample = raw;
|
||||||
|
minSeen = 1023;
|
||||||
|
maxSeen = 0;
|
||||||
|
|
||||||
|
return calState;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long currentTime = millis();
|
// Kein Reset angefordert, aber auch keine aktive Kalibrierung
|
||||||
int rawValue = applySmoothing(analogRead(pedalPin));
|
if (calStep == 0)
|
||||||
|
{
|
||||||
|
calState = IDLE;
|
||||||
|
return calState;
|
||||||
|
}
|
||||||
|
|
||||||
switch (step)
|
int raw = readRaw();
|
||||||
|
int diff = abs(raw - lastSample);
|
||||||
|
|
||||||
|
printStatus(raw);
|
||||||
|
|
||||||
|
switch (calStep)
|
||||||
{
|
{
|
||||||
case 0: // Initial state: wait for pedal release
|
case 1: // Schritt 1: Pedal losgelassen halten
|
||||||
if (rawValue == previousValue && currentTime - lastChangeTime > 2000)
|
if (diff > STABLE_THRESHOLD)
|
||||||
{
|
{
|
||||||
if (rawValue >= minMin && rawValue <= maxMin)
|
lastSample = raw;
|
||||||
{
|
lastChangeTime = now;
|
||||||
config.minRaw = rawValue;
|
|
||||||
step++;
|
|
||||||
lastChangeTime = currentTime;
|
|
||||||
errorState = RUNNING;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
// Wert war lange genug stabil -> als unteres Ende merken
|
||||||
|
if (now - lastChangeTime > STABLE_TIME)
|
||||||
{
|
{
|
||||||
errorState = ERROR;
|
minSeen = raw;
|
||||||
}
|
config.minRaw = raw;
|
||||||
}
|
calStep = 2;
|
||||||
else if (rawValue != previousValue)
|
lastSample = raw;
|
||||||
{
|
lastChangeTime = now;
|
||||||
lastChangeTime = currentTime;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
calState = RUNNING;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1: // Wait for pedal full press
|
case 2: // Schritt 2: Pedal voll durchtreten
|
||||||
if (rawValue == previousValue && currentTime - lastChangeTime > 2000)
|
if (diff > STABLE_THRESHOLD)
|
||||||
{
|
{
|
||||||
if (rawValue >= minMax && rawValue <= maxMax)
|
lastSample = raw;
|
||||||
|
lastChangeTime = now;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wert war lange genug stabil -> als erstes oberes Ende merken
|
||||||
|
if (now - lastChangeTime > STABLE_TIME)
|
||||||
{
|
{
|
||||||
config.maxRaw = rawValue;
|
maxSeen = raw;
|
||||||
step++;
|
config.maxRaw = raw;
|
||||||
lastChangeTime = currentTime;
|
calStep = 3;
|
||||||
errorState = RUNNING;
|
stepStartTime = now;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
errorState = ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (rawValue != previousValue)
|
|
||||||
{
|
|
||||||
lastChangeTime = currentTime;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
calState = RUNNING;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2: // Validate calibration
|
case 3: // Schritt 3: Sweep, um echten min/max Bereich zu erfassen
|
||||||
if (config.maxRaw > config.minRaw + 100)
|
if (raw < minSeen)
|
||||||
{ // Ensure valid range
|
minSeen = raw;
|
||||||
step++;
|
if (raw > maxSeen)
|
||||||
|
maxSeen = raw;
|
||||||
|
|
||||||
|
if (now - stepStartTime > SWEEP_TIME)
|
||||||
|
{
|
||||||
|
int low = minSeen + SAFETY_MARGIN_LOW;
|
||||||
|
int high = maxSeen - SAFETY_MARGIN_HIGH;
|
||||||
|
|
||||||
|
// Falls Richtung "invertiert" ist, drehen
|
||||||
|
if (high < low)
|
||||||
|
{
|
||||||
|
int tmp = low;
|
||||||
|
low = high;
|
||||||
|
high = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bereich zu klein, Kalibrierung fehlgeschlagen
|
||||||
|
if (high - low < MIN_RANGE)
|
||||||
|
{
|
||||||
|
config.calibrated = false;
|
||||||
|
calState = ERROR;
|
||||||
|
calStep = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
config.minRaw = low;
|
||||||
|
config.maxRaw = high;
|
||||||
config.calibrated = true;
|
config.calibrated = true;
|
||||||
errorState = SUCCESS;
|
|
||||||
|
calState = SUCCESS;
|
||||||
|
calStep = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
errorState = ERROR;
|
calState = RUNNING;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
errorState = IDLE;
|
// Fallback, falls irgendetwas entgleist
|
||||||
step = 0;
|
calState = ERROR;
|
||||||
|
calStep = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
previousValue = rawValue;
|
return calState;
|
||||||
return errorState;
|
}
|
||||||
|
|
||||||
|
CalibrationState PedalController::getStatus() const
|
||||||
|
{
|
||||||
|
return calState;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PedalController::getPedal()
|
int PedalController::getPedal()
|
||||||
{
|
{
|
||||||
if (!config.calibrated || autoCalibrate(false) != IDLE)
|
// 1) Digital-Sanity: Wenn DO "nicht gedrückt" meldet → 0
|
||||||
|
if (useDigital)
|
||||||
|
{
|
||||||
|
int d = digitalRead(digitalPin);
|
||||||
|
|
||||||
|
if ((uint8_t)d == digitalNotPressedLevel)
|
||||||
|
{
|
||||||
|
// Optional: Filter sanft Richtung "unten" ziehen
|
||||||
|
// aber sicherheitshalber nichts fahren
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2) Ohne gültige Kalibrierung: kein Pedal
|
||||||
|
if (!config.calibrated)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rawValue = applySmoothing(analogRead(pedalPin));
|
int raw = readRaw();
|
||||||
if (rawValue < config.minRaw || rawValue > config.maxRaw)
|
|
||||||
|
int minR = config.minRaw;
|
||||||
|
int maxR = config.maxRaw;
|
||||||
|
|
||||||
|
// Defekter Config-Bereich, zur Sicherheit 0
|
||||||
|
if (maxR <= minR + 1)
|
||||||
{
|
{
|
||||||
return 0; // Out of bounds
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return map(rawValue, config.minRaw, config.maxRaw, 0, 100);
|
// Clamping
|
||||||
|
if (raw < minR)
|
||||||
|
raw = minR;
|
||||||
|
if (raw > maxR)
|
||||||
|
raw = maxR;
|
||||||
|
|
||||||
|
long span = (long)maxR - (long)minR;
|
||||||
|
long scaled = (long)(raw - minR) * 100L / span;
|
||||||
|
|
||||||
|
// kleine Deadzone unten
|
||||||
|
if (scaled < 5)
|
||||||
|
scaled = 0;
|
||||||
|
if (scaled > 100)
|
||||||
|
scaled = 100;
|
||||||
|
|
||||||
|
return (int)scaled;
|
||||||
}
|
}
|
||||||
|
|
||||||
CalibrationState PedalController::getStatus()
|
PedalConfig PedalController::getConfig() const
|
||||||
{
|
|
||||||
return autoCalibrate(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
int PedalController::getRawValue()
|
|
||||||
{
|
|
||||||
return analogRead(pedalPin);
|
|
||||||
}
|
|
||||||
|
|
||||||
PedalConfig PedalController::getConfig()
|
|
||||||
{
|
{
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
@@ -153,4 +268,84 @@ PedalConfig PedalController::getConfig()
|
|||||||
void PedalController::setConfig(const PedalConfig &newConfig)
|
void PedalController::setConfig(const PedalConfig &newConfig)
|
||||||
{
|
{
|
||||||
config = newConfig;
|
config = newConfig;
|
||||||
|
|
||||||
|
// FilterStrength sanitizen
|
||||||
|
if (config.filterStrength < MIN_FS || config.filterStrength > MAX_FS)
|
||||||
|
{
|
||||||
|
config.filterStrength = DEFAULT_FS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.maxRaw < config.minRaw)
|
||||||
|
{
|
||||||
|
int16_t tmp = config.minRaw;
|
||||||
|
config.minRaw = config.maxRaw;
|
||||||
|
config.maxRaw = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
filteredValue = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PedalController::loadDefaults()
|
||||||
|
{
|
||||||
|
config = defaultConfig;
|
||||||
|
|
||||||
|
if (config.filterStrength < MIN_FS || config.filterStrength > MAX_FS)
|
||||||
|
{
|
||||||
|
config.filterStrength = DEFAULT_FS;
|
||||||
|
}
|
||||||
|
|
||||||
|
calState = IDLE;
|
||||||
|
calStep = 0;
|
||||||
|
filteredValue = -1;
|
||||||
|
stepStartTime = 0;
|
||||||
|
lastChangeTime = 0;
|
||||||
|
lastSample = 0;
|
||||||
|
minSeen = 1023;
|
||||||
|
maxSeen = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PedalController::printStatus(int raw)
|
||||||
|
{
|
||||||
|
unsigned long now = millis();
|
||||||
|
if (now - lastStatusPrint < 1000)
|
||||||
|
return; // nur jede Sekunde
|
||||||
|
lastStatusPrint = now;
|
||||||
|
|
||||||
|
int digitalState = -1;
|
||||||
|
if (useDigital)
|
||||||
|
{
|
||||||
|
digitalState = digitalRead(digitalPin);
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.print("[CAL] Step=");
|
||||||
|
Serial.print(calStep);
|
||||||
|
Serial.print(" RAW=");
|
||||||
|
Serial.print(raw);
|
||||||
|
Serial.print(" Filtered=");
|
||||||
|
Serial.print(filteredValue);
|
||||||
|
|
||||||
|
Serial.print(" DO-State=");
|
||||||
|
if (useDigital)
|
||||||
|
Serial.print(digitalState);
|
||||||
|
else
|
||||||
|
Serial.print("N/A");
|
||||||
|
|
||||||
|
Serial.print(" minSeen=");
|
||||||
|
Serial.print(minSeen);
|
||||||
|
Serial.print(" maxSeen=");
|
||||||
|
Serial.print(maxSeen);
|
||||||
|
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
int PedalController::debugGetRaw()
|
||||||
|
{
|
||||||
|
return readRaw();
|
||||||
|
}
|
||||||
|
|
||||||
|
int PedalController::debugGetDO()
|
||||||
|
{
|
||||||
|
if (!useDigital)
|
||||||
|
return -1;
|
||||||
|
return digitalRead(digitalPin);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,33 +14,56 @@ enum CalibrationState {
|
|||||||
|
|
||||||
// Pedal configuration structure
|
// Pedal configuration structure
|
||||||
struct PedalConfig {
|
struct PedalConfig {
|
||||||
int minRaw;
|
int16_t minRaw;
|
||||||
int maxRaw;
|
int16_t maxRaw;
|
||||||
bool calibrated;
|
bool calibrated;
|
||||||
int filterStrength;
|
uint8_t filterStrength; // 1 = kein Filter, >1 = gleitender Mittelwert
|
||||||
};
|
};
|
||||||
|
|
||||||
class PedalController {
|
class PedalController {
|
||||||
private:
|
|
||||||
int pedalPin;
|
|
||||||
int filteredValue;
|
|
||||||
PedalConfig config;
|
|
||||||
|
|
||||||
int applySmoothing(int rawValue);
|
|
||||||
int getRawValue();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PedalController(int pin);
|
// analogPin = ADC-Eingang
|
||||||
|
// digitalPin = optionaler Digital-Eingang des Hall-Boards (DO), -1 wenn keiner
|
||||||
|
// digitalNotPressedLevel = 0 (LOW) oder 1 (HIGH), welches Level "nicht gedrückt" bedeutet
|
||||||
|
explicit PedalController(int analogPin,
|
||||||
|
int digitalPin = -1,
|
||||||
|
uint8_t digitalNotPressedLevel = LOW);
|
||||||
|
|
||||||
|
// Startet / läuft Auto-Kalibrierung
|
||||||
CalibrationState autoCalibrate(bool reset);
|
CalibrationState autoCalibrate(bool reset);
|
||||||
CalibrationState getStatus();
|
CalibrationState getStatus() const;
|
||||||
|
|
||||||
|
// 0–100 %, bei nicht kalibriert → 0
|
||||||
int getPedal();
|
int getPedal();
|
||||||
|
|
||||||
PedalConfig getConfig();
|
PedalConfig getConfig() const;
|
||||||
void setConfig(const PedalConfig &newConfig);
|
void setConfig(const PedalConfig &newConfig);
|
||||||
void loadDefaults();
|
void loadDefaults();
|
||||||
|
int debugGetRaw();
|
||||||
|
int debugGetDO();
|
||||||
|
|
||||||
|
private:
|
||||||
|
int analogPin;
|
||||||
|
int digitalPin;
|
||||||
|
bool useDigital;
|
||||||
|
uint8_t digitalNotPressedLevel; // 0 oder 1
|
||||||
|
|
||||||
|
PedalConfig config;
|
||||||
|
int32_t filteredValue;
|
||||||
|
|
||||||
|
// Auto-Cal intern
|
||||||
|
CalibrationState calState;
|
||||||
|
uint8_t calStep;
|
||||||
|
unsigned long stepStartTime;
|
||||||
|
unsigned long lastChangeTime;
|
||||||
|
int lastSample;
|
||||||
|
int minSeen;
|
||||||
|
int maxSeen;
|
||||||
|
unsigned long lastStatusPrint;
|
||||||
|
|
||||||
|
int readRaw(); // roher ADC-Wert (mit Glättung)
|
||||||
|
int applySmoothing(int raw);
|
||||||
|
void printStatus(int raw);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PEDALCONTROLLER_H
|
#endif // PEDALCONTROLLER_H
|
||||||
|
|||||||
43
src/main.cpp
43
src/main.cpp
@@ -17,11 +17,12 @@ const int encoderPinA = 3; // Encoder pin A
|
|||||||
const int encoderPinB = 4; // Encoder pin B
|
const int encoderPinB = 4; // Encoder pin B
|
||||||
const int encoderButton = 5; // Encoder button
|
const int encoderButton = 5; // Encoder button
|
||||||
const int motorPin = 9; // Motor PWM pin
|
const int motorPin = 9; // Motor PWM pin
|
||||||
const int pedalPin = A0; // Pedal input pin
|
const int pedalPinAnalog = A1; // Pedal analog Input pin
|
||||||
|
const int pedalPinDigital = 8; // Pedal digital Input pin
|
||||||
|
|
||||||
// Global objects
|
// Global objects
|
||||||
MotorController motor(motorPin); // Motor control object
|
MotorController motor(motorPin); // Motor control object
|
||||||
PedalController pedal(pedalPin); // Pedal input object
|
PedalController pedal(pedalPinAnalog, pedalPinDigital, HIGH); // Pedal input object
|
||||||
|
|
||||||
// Combined settings structure
|
// Combined settings structure
|
||||||
struct Settings
|
struct Settings
|
||||||
@@ -36,6 +37,9 @@ bool autoCalibrating = false;
|
|||||||
bool serialControlEnabled = false;
|
bool serialControlEnabled = false;
|
||||||
CalibrationState lastCalibrationState = IDLE;
|
CalibrationState lastCalibrationState = IDLE;
|
||||||
|
|
||||||
|
bool liveSensorOutput = false;
|
||||||
|
unsigned long lastSensorPrint = 0;
|
||||||
|
|
||||||
// Function prototypes
|
// Function prototypes
|
||||||
void loadSettings();
|
void loadSettings();
|
||||||
void saveSettings();
|
void saveSettings();
|
||||||
@@ -133,6 +137,26 @@ void loop()
|
|||||||
motor.setTargetSpeed(pedalValue);
|
motor.setTargetSpeed(pedalValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (liveSensorOutput)
|
||||||
|
{
|
||||||
|
unsigned long now = millis();
|
||||||
|
if (now - lastSensorPrint > 200)
|
||||||
|
{
|
||||||
|
lastSensorPrint = now;
|
||||||
|
|
||||||
|
int raw = pedal.debugGetRaw();
|
||||||
|
int pedalValue = pedal.getPedal();
|
||||||
|
int doState = pedal.debugGetDO();
|
||||||
|
|
||||||
|
Serial.print("[SENSOR] RAW=");
|
||||||
|
Serial.print(raw);
|
||||||
|
Serial.print(" Pedal%=");
|
||||||
|
Serial.print(pedalValue);
|
||||||
|
Serial.print(" DO=");
|
||||||
|
Serial.println(doState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Update display
|
// Update display
|
||||||
// updateDisplay();
|
// updateDisplay();
|
||||||
|
|
||||||
@@ -290,6 +314,18 @@ void handleSerialInput()
|
|||||||
Serial.println(motor.getSpeed());
|
Serial.println(motor.getSpeed());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'S':
|
||||||
|
liveSensorOutput = !liveSensorOutput; // toggeln
|
||||||
|
if (liveSensorOutput)
|
||||||
|
{
|
||||||
|
Serial.println("Sensor-Live-Ausgabe: ON");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Serial.println("Sensor-Live-Ausgabe: OFF");
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
Serial.println(input);
|
Serial.println(input);
|
||||||
}
|
}
|
||||||
@@ -306,10 +342,11 @@ void printHelp()
|
|||||||
Serial.println("h - Show this help");
|
Serial.println("h - Show this help");
|
||||||
Serial.println("+ - Increment PWM");
|
Serial.println("+ - Increment PWM");
|
||||||
Serial.println("- - Decrement PWM");
|
Serial.println("- - Decrement PWM");
|
||||||
|
Serial.println("S - Toggle debug Pedal-Input");
|
||||||
}
|
}
|
||||||
|
|
||||||
void configurePWMFrequency()
|
void configurePWMFrequency()
|
||||||
{
|
{
|
||||||
// Configure Timer1 for higher PWM frequency (~4 kHz)
|
// Configure Timer1 for higher PWM frequency (~4 kHz)
|
||||||
TCCR1B = (1<<CS11); // Set prescaler to 8
|
TCCR1B = (1 << CS11); // Set prescaler to 8
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user