initial commit

master
Yorick GEOFFRE 2 years ago
commit c91f3567e7

@ -0,0 +1,41 @@
const int numPins = 3;
const int pwmPins[] = {A1, A2, A3};
const float minDutyCycle[numPins] = {5.98, 6.03, 6.03};
const float maxDutyCycle[numPins] = {12.08, 12.02, 11.94};
const float deadzone = 0.1;
void setup() {
Serial.begin(9600);
for (int i = 0; i < numPins; i++) {
pinMode(pwmPins[i], INPUT);
}
}
float mapFloat(float x, float in_min, float in_max, float out_min, float out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
void loop() {
for (int i = 0; i < numPins; i++) {
unsigned long highDuration = pulseIn(pwmPins[i], HIGH);
unsigned long lowDuration = pulseIn(pwmPins[i], LOW);
unsigned long period = highDuration + lowDuration;
float dutyCycle = (float)highDuration / (float)period * 100.0;
// Map the duty cycle value to the range of -1.0 to 1.0
float mappedDutyCycle = mapFloat(dutyCycle, minDutyCycle[i], maxDutyCycle[i], -1.0, 1.0);
// Apply deadzone
if (mappedDutyCycle > -deadzone && mappedDutyCycle < deadzone) {
mappedDutyCycle = 0.0;
}
// Print the mapped duty cycle in a format suitable for the Serial Plotter
Serial.print(mappedDutyCycle);
if (i < numPins - 1) {
Serial.print(",");
} else {
Serial.println();
}
}
}
Loading…
Cancel
Save