Arduino Sim Racing Library v1.1.5
Loading...
Searching...
No Matches
PedalsPrint.ino
1/*
2 * Project Sim Racing Library for Arduino
3 * @author David Madison
4 * @link github.com/dmadison/Sim-Racing-Arduino
5 * @license LGPLv3 - Copyright (c) 2022 David Madison
6 *
7 * This file is part of the Sim Racing Library for Arduino.
8 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
28#include <SimRacing.h>
29
30const int Pin_Gas = A2;
31const int Pin_Brake = A1;
32const int Pin_Clutch = A0;
33
34SimRacing::LogitechPedals pedals(Pin_Gas, Pin_Brake, Pin_Clutch);
35//SimRacing::LogitechPedals pedals(PEDAL_SHIELD_V1_PINS);
36
37
38void setup() {
39 pedals.begin(); // initialize pedal pins
40
41 // if you have one, your calibration line should go here
42
43 Serial.begin(115200);
44 while (!Serial); // wait for connection to open
45
46 Serial.println("Starting...");
47}
48
49void loop() {
50 // send some serial data to run conversational calibration
51 if (Serial.read() != -1) {
52 pedals.serialCalibration();
53 delay(2000);
54 }
55
56 pedals.update();
57
58 Serial.print("Pedals:");
59
60 if (pedals.hasPedal(SimRacing::Gas)) {
61 int gasPedal = pedals.getPosition(SimRacing::Gas);
62 Serial.print("\tGas: [ ");
63 Serial.print(gasPedal);
64 Serial.print("% ]");
65 }
66
67 if (pedals.hasPedal(SimRacing::Brake)) {
68 int brakePedal = pedals.getPosition(SimRacing::Brake);
69 Serial.print("\tBrake: [ ");
70 Serial.print(brakePedal);
71 Serial.print("% ]");
72 }
73
74 if (pedals.hasPedal(SimRacing::Clutch)) {
75 int clutchPedal = pedals.getPosition(SimRacing::Clutch);
76 Serial.print("\tClutch: [ ");
77 Serial.print(clutchPedal);
78 Serial.print("% ]");
79 }
80
81 Serial.println();
82 delay(100);
83}
Header file for the Sim Racing Library.
Interface with the Logitech pedals (Gas, Brake, and Clutch)
Definition SimRacing.h:760
void serialCalibration(Stream &iface=Serial)
Runs an interactive calibration tool using the serial interface.
bool hasPedal(PedalID pedal) const
Checks if a given pedal is present in the class.
virtual bool update()
Perform a poll of the hardware to refresh the class state.
virtual void begin()
Initialize the hardware (if necessary)
long getPosition(PedalID pedal, long rMin=0, long rMax=100) const
Retrieves the buffered position for the pedal, rescaled to a nominal range using the calibration valu...