Fonctionnalité de repérage auto. lors du démarrage

This commit is contained in:
=
2021-01-27 14:34:44 +01:00
parent b668a01416
commit 562a43a6dd

View File

@@ -25,6 +25,11 @@ const int ROAD_LIGHTS_PIN = 16;
const int HEAD_LIGHTS_PIN = 14; const int HEAD_LIGHTS_PIN = 14;
const int FOG_LIGHTS_PIN = 15; const int FOG_LIGHTS_PIN = 15;
// Enabling modules
const bool USE_GEARSHIFT = true;
const bool USE_PEDALS = true;
const bool USE_WHEEL = true;
const int INTERVAL = 15; const int INTERVAL = 15;
void setup() { void setup() {
@@ -53,6 +58,7 @@ void setup() {
// Send current states // Send current states
/* Gearshift */ /* Gearshift */
if(USE_GEARSHIFT){
int value = analogRead(SPEEDS_PIN); int value = analogRead(SPEEDS_PIN);
if(value < 200) ZenDrive.switchSpeed1(); if(value < 200) ZenDrive.switchSpeed1();
else if(value < 326) ZenDrive.switchSpeed2(); else if(value < 326) ZenDrive.switchSpeed2();
@@ -65,8 +71,9 @@ void setup() {
//Read handbrake //Read handbrake
ZenDrive.setHandbrake(map(analogRead(HANDBRAKE_PIN), 0, 1023, 0, 255)); ZenDrive.setHandbrake(map(analogRead(HANDBRAKE_PIN), 0, 1023, 0, 255));
ZenDrive.sendGearshiftStates(); ZenDrive.sendGearshiftStates();
}
/* Pedals module */ /* Pedals module */
if(USE_PEDALS){
// Read clutch // Read clutch
ZenDrive.setClutch(map(analogRead(CLUTCH_PIN), 0, 1023, 0, 255)); ZenDrive.setClutch(map(analogRead(CLUTCH_PIN), 0, 1023, 0, 255));
// Read brake // Read brake
@@ -74,9 +81,10 @@ void setup() {
// Read accelerator // Read accelerator
ZenDrive.setAccelerator(map(analogRead(ACCELERATOR_PIN), 0, 1023, 0, 255)); ZenDrive.setAccelerator(map(analogRead(ACCELERATOR_PIN), 0, 1023, 0, 255));
ZenDrive.sendPedalsStates(); ZenDrive.sendPedalsStates();
}
/* Steering wheel module */ /* Steering wheel module */
// Left blinker if(USE_WHEEL){
// Blinkers
if(digitalRead(LEFT_BLINKER_PIN)){ if(digitalRead(LEFT_BLINKER_PIN)){
ZenDrive.setBlinkerLeft(true); ZenDrive.setBlinkerLeft(true);
ZenDrive.setBlinkerRight(false); ZenDrive.setBlinkerRight(false);
@@ -107,6 +115,7 @@ void setup() {
ZenDrive.setDirection(map(analogRead(DIRECTION_PIN), 0, 1023, -127, 127)); ZenDrive.setDirection(map(analogRead(DIRECTION_PIN), 0, 1023, -127, 127));
ZenDrive.sendWheelStates(); ZenDrive.sendWheelStates();
} }
}
void loop() { void loop() {
// Set refresh to false // Set refresh to false
@@ -115,6 +124,7 @@ void loop() {
ZenDrive.wheelNeedRefresh = false; ZenDrive.wheelNeedRefresh = false;
/* Gearshift module */ /* Gearshift module */
if(USE_GEARSHIFT){
//Read speed states on the analog shared pin //Read speed states on the analog shared pin
int value = analogRead(SPEEDS_PIN); int value = analogRead(SPEEDS_PIN);
if(value < 200) ZenDrive.switchSpeed1(); if(value < 200) ZenDrive.switchSpeed1();
@@ -129,8 +139,9 @@ void loop() {
ZenDrive.setHandbrake(map(analogRead(HANDBRAKE_PIN), 0, 1023, 0, 255)); ZenDrive.setHandbrake(map(analogRead(HANDBRAKE_PIN), 0, 1023, 0, 255));
// Send gearshift states if there are changes // Send gearshift states if there are changes
if(ZenDrive.gearshiftNeedRefresh) ZenDrive.sendGearshiftStates(); if(ZenDrive.gearshiftNeedRefresh) ZenDrive.sendGearshiftStates();
}
/* Pedals module */ /* Pedals module */
if(USE_PEDALS){
// Read clutch // Read clutch
ZenDrive.setClutch(map(analogRead(CLUTCH_PIN), 0, 1023, 0, 255)); ZenDrive.setClutch(map(analogRead(CLUTCH_PIN), 0, 1023, 0, 255));
// Read brake // Read brake
@@ -139,12 +150,22 @@ void loop() {
ZenDrive.setAccelerator(map(analogRead(ACCELERATOR_PIN), 0, 1023, 0, 255)); ZenDrive.setAccelerator(map(analogRead(ACCELERATOR_PIN), 0, 1023, 0, 255));
// Send pedals states if they are changes // Send pedals states if they are changes
if(ZenDrive.pedalsNeedRefresh) ZenDrive.sendPedalsStates(); if(ZenDrive.pedalsNeedRefresh) ZenDrive.sendPedalsStates();
}
/* Steering wheel module */ /* Steering wheel module */
// Left blinker if(USE_WHEEL){
ZenDrive.setBlinkerLeft(digitalRead(LEFT_BLINKER_PIN)); // Blinkers
// Right blinker if(digitalRead(LEFT_BLINKER_PIN)){
ZenDrive.setBlinkerRight(digitalRead(RIGHT_BLINKER_PIN)); ZenDrive.setBlinkerLeft(true);
ZenDrive.setBlinkerRight(false);
}
else if(digitalRead(RIGHT_BLINKER_PIN)){
ZenDrive.setBlinkerLeft(false);
ZenDrive.setBlinkerRight(true);
}
else{
ZenDrive.setBlinkerLeft(false);
ZenDrive.setBlinkerRight(false);
}
// Warning // Warning
ZenDrive.setWarning(digitalRead(WARNING_PIN)); ZenDrive.setWarning(digitalRead(WARNING_PIN));
// Lights // Lights
@@ -169,5 +190,6 @@ void loop() {
ZenDrive.setDirection(map(analogRead(DIRECTION_PIN), 0, 1023, -127, 127)); ZenDrive.setDirection(map(analogRead(DIRECTION_PIN), 0, 1023, -127, 127));
// Send steering wheel states if they are changes // Send steering wheel states if they are changes
if(ZenDrive.wheelNeedRefresh) ZenDrive.sendWheelStates(); if(ZenDrive.wheelNeedRefresh) ZenDrive.sendWheelStates();
}
delay(50); delay(50);
} }