Skip to content

Commit b0bc51a

Browse files
committed
Send initial pedal state in joystick example
Fixes a bug where pedal state would not be detected until the pedals were moved for the first time. Also refactors the function name from "updatePedals" to "updateJoystick", as the pedal object is updated from within loop().
1 parent 4819578 commit b0bc51a

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

examples/Pedals/PedalsJoystick/PedalsJoystick.ino

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,19 @@ void setup() {
6161
Joystick.setZAxisRange(0, ADC_Max);
6262
Joystick.setRxAxisRange(0, ADC_Max);
6363
Joystick.setRyAxisRange(0, ADC_Max);
64+
65+
updateJoystick(); // send initial state
6466
}
6567

6668
void loop() {
6769
pedals.update();
6870

6971
if (pedals.positionChanged()) {
70-
updatePedals();
72+
updateJoystick();
7173
}
7274
}
7375

74-
void updatePedals() {
76+
void updateJoystick() {
7577
if (pedals.hasPedal(SimRacing::Gas)) {
7678
int gasPedal = pedals.getPosition(SimRacing::Gas, 0, ADC_Max);
7779
Joystick.setRyAxis(gasPedal);

0 commit comments

Comments
 (0)