-
Notifications
You must be signed in to change notification settings - Fork 0
/
LogitechPedalsToRudder.ino
65 lines (52 loc) · 1.62 KB
/
LogitechPedalsToRudder.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//
// By Zach Fox
// https://github.com/zfox23/LogitechPedalsToRudder
//
#include "Joystick.h"
Joystick_ Joystick(
JOYSTICK_DEFAULT_REPORT_ID, // uint8_t hidReportId
JOYSTICK_TYPE_JOYSTICK, // uint8_t joystickType
0, // uint8_t buttonCount
0, // uint8_t hatSwitchCount
false, // bool includeXAxis
false, // bool includeYAxis
false, // bool includeZAxis
false, // bool includeRxAxis
false, // bool includeRyAxis
false, // bool includeRzAxis
true, // bool includeRudder
false, // bool includeThrottle
false, // bool includeAccelerator
false, // bool includeBrake
false // bool includeSteering
);
const int numSamples = 3;
int currentIndex;
int smoothedClutchPedalValue = 0;
int clutchPedalValues[numSamples];
int smoothedAcceleratorPedalValue = 0;
int acceleratorPedalValues[numSamples];
const bool initAutoSendState = true;
void setup() {
Joystick.begin();
Joystick.setRudderRange(-1000, 1000);
}
float average(int* array, int len) {
long sum = 0L;
for (int i = 0; i < len; i++) {
sum += array[i];
}
return ((float) sum) / len;
}
void loop() {
clutchPedalValues[currentIndex] = analogRead(A0); // From (0, 1023);
acceleratorPedalValues[currentIndex] = analogRead(A2); // From (0, 1023);
currentIndex = currentIndex + 1;
if (currentIndex >= numSamples) {
currentIndex = 0;
}
smoothedClutchPedalValue = average(clutchPedalValues, numSamples);
smoothedAcceleratorPedalValue = average(acceleratorPedalValues, numSamples);
Joystick.setRudder(smoothedClutchPedalValue - smoothedAcceleratorPedalValue);
delay(50);
}