Fonctionnalité de repérage auto. lors du démarrage
This commit is contained in:
@@ -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);
|
||||
@@ -107,6 +115,7 @@ void setup() {
|
||||
ZenDrive.setDirection(map(analogRead(DIRECTION_PIN), 0, 1023, -127, 127));
|
||||
ZenDrive.sendWheelStates();
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Set refresh to false
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user