Arduino Sim Racing Library v1.1.5
Loading...
Searching...
No Matches
ShiftPrint.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_ShifterX = A0;
31const int Pin_ShifterY = A2;
32const int Pin_ShifterRev = 2;
33
34SimRacing::LogitechShifter shifter(Pin_ShifterX, Pin_ShifterY, Pin_ShifterRev);
35//SimRacing::LogitechShifter shifter(SHIFTER_SHIELD_V1_PINS);
36
37const unsigned long PrintSpeed = 1500; // ms
38unsigned long lastPrint = 0;
39
40
41void setup() {
42 shifter.begin();
43
44 // if you have one, your calibration line should go here
45
46 Serial.begin(115200);
47 while (!Serial); // wait for connection to open
48
49 Serial.println("Starting...");
50}
51
52void loop() {
53 // send some serial data to run conversational calibration
54 if (Serial.read() != -1) {
55 shifter.serialCalibration();
56 delay(2000);
57 }
58
59 shifter.update();
60
61 if (shifter.gearChanged()) {
62 Serial.print("Shifted into ");
63 Serial.print(shifter.getGearString());
64 Serial.print(" [");
65 Serial.print(shifter.getGear());
66 Serial.print("]");
67
68 Serial.print(" - XY: (");
69 Serial.print(shifter.getPositionRaw(SimRacing::X));
70 Serial.print(", ");
71 Serial.print(shifter.getPositionRaw(SimRacing::Y));
72 Serial.print(")");
73 Serial.println();
74
75 lastPrint = millis();
76 }
77 else {
78 if(millis() - lastPrint >= PrintSpeed) {
79 Serial.print("Currently in ");
80 Serial.print(shifter.getGearString());
81 Serial.println();
82
83 lastPrint = millis();
84 }
85 }
86}
Header file for the Sim Racing Library.
void serialCalibration(Stream &iface=Serial)
Runs an interactive calibration tool using the serial interface.
int getPositionRaw(Axis ax) const
Retrieves the buffered position for the analog axis.
virtual bool update()
Polls the hardware to update the current gear state.
virtual void begin()
Initializes the hardware pins for reading the gear states.
Interface with the Logitech Driving Force shifter.
Definition SimRacing.h:787
int8_t getGear() const
Returns the currently selected gear.
Definition SimRacing.h:475
static String getGearString(int gear)
Returns a String that represents the given gear.
bool gearChanged() const
Checks whether the current gear has changed since the last update.
Definition SimRacing.h:519