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