Hi
This is my first ever "Own" creation project (Given up on spirit level calibration)
I am wanting to make a test box to check that trailer lights are working correctly. We have 2 different ways the plugs are wired.
I want to be able to Plug in the trailer plug, select whether it is Old or New style wiring, and then run a sequence. (Eg. If button old is pressed, then turn on the side lights, wait to get to the back of the trailer, then put on the brake light... Flash the left hand indicator and so on).
I have written my Sketch and there is already a fault, something to do with the brackets at the end?
Please can you have a look, see if it can be improved, and Also see if it will actually flash the indicators for 5 seconds.
//Define the trailer socket pins to the Arduino pins
int trlpin_A = 13; //old is nothing // New is Side lights
int trlpin_B = 12; //old is LHS Brake Light // New is LH Indicate
int trlpin_C = 11; //old is Convoy // New is Convoy
int trlpin_E = 10; //old is Side Lights // New is Side lights
int trlpin_F = 9; //old is Fog Light // New is Brake Light (Blackout)??
int trlpin_H = 8; //old is nothing // New is Fog Light
int trlpin_J = 7; //old is RHS Brake light // New is RH Indicator
int trlpin_M = 6; //old is LH Indicator // New is Brake Lights
int trlpin_N = 5; //old is RH Indicator // New is Reverse Light
//Define the two pushbuttons to the Arduino
int switchPin_old = 4; //select device is plugged into Old style trailer plug
int switchPin_new = 3; //select device is plugged into New style trailer plug
int val1;
int val2;
int indFlashTime = 250; //Indicator flashing time on and off delay
int walkToBackDelay = 10000;
int delayForNextLight = 5000;
void setup() {
pinMode(trlpin_A, OUTPUT);
pinMode(trlpin_B, OUTPUT);
pinMode(trlpin_C, OUTPUT);
pinMode(trlpin_E, OUTPUT);
pinMode(trlpin_F, OUTPUT);
pinMode(trlpin_H, OUTPUT);
pinMode(trlpin_J, OUTPUT);
pinMode(trlpin_M, OUTPUT);
pinMode(trlpin_N, OUTPUT);
pinMode(switchPin_old, INPUT);
pinMode(switchPin_new, INPUT);
}
void loop() {
val1 = digitalRead(switchPin_old);
val2 = digitalRead(switchPin_new);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//run the sequence of testing lights IF the "Old" push button is pressed///
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (val1 == HIGH) { //IF the old style switch is pressed
digitalWrite(trlpin_E, HIGH); //Turn on the trailer side lights
delay(walkToBackDelay); //Wait 10 seconds to get to walk to back of trailer
digitalWrite(trlpin_B, HIGH); //Turn on the Left brake light
digitalWrite(trlpin_J, HIGH); //Turn on the Right brake light (Hopefully at the same time as left)
delay(delayForNextLight); //Delay for next light test (5 seconds)
digitalWrite(trlpin_B, LOW); //Turn off the Left brake light
digitalWrite(trlpin_J, LOW); //Turn off the Right brake light (Hopefully at the same time as left)
//Hopefully the side lights are still on, but the brake lights have BOTH come on for 5 seconds and gone off again
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Next I want to test the indicators LHS first with falshing on and off for under 1 second for about 5 seconds (not sure how to change The 5 seconds)
for (int x = 0; x < 10; x++) {
digitalWrite(trlpin_M, HIGH); //Turn on the LH Indicator and flash (Hopefully!)
delay(250);
digitalWrite(trlpin_M, LOW);
delay(250);
delay(delayForNextLight);
for (int x = 0; x < 10; x++) {
digitalWrite(trlpin_N, HIGH); //Turn on the RH Indicator and flash (Hopefully!)
delay(250);
digitalWrite(trlpin_N, LOW);
delay(250);
}
//Next still Keeping the side lights on, I want to test the Fog light
digitalWrite(trlpin_F, HIGH); //Turn on the rear Fog Light
delay(delayForNextLight); //Delay
digitalWrite(trlpin_F, LOW); //Turn off the rear Fog Light
delay(delayForNextLight); //Delay
digitalWrite(trlpin_E, LOW); //Turn off the side lights
delay(delayForNextLight);
digitalWrite(trlpin_C, HIGH); //Turn On convoy light (Hopefully the side lights are now Off)
delay(delayForNextLight);
digitalWrite(trlpin_C, LOW); //Turn Off the Convoy Light
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//run the sequence of testing lights IF the "NEW" push button is pressed///
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (val2 == HIGH) { //IF the NEW style switch is pressed
digitalWrite(trlpin_A, HIGH);//Turn on the trailer side lights
digitalWrite(trlpin_E, HIGH);
delay(walkToBackDelay); //Wait 10 seconds to get to walk to back of trailer
digitalWrite(trlpin_F, HIGH); //Turn on the brake light (This could be Brake light Blackout???)
digitalWrite(trlpin_M, HIGH); //Turn on the brake lights (Hopefully at the same time as left)
delay(delayForNextLight); //Delay for next light test (5 seconds)
digitalWrite(trlpin_F, LOW); //Turn off the Left brake light
digitalWrite(trlpin_M, LOW); //Turn off the Right brake light (Hopefully at the same time as left)
//Hopefully the side lights are still on, but the brake lights have BOTH come on for 5 seconds and gone off again
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Next I want to test the indicators LHS first with falshing on and off for under 1 second for about 5 seconds (not sure how to change The 5 seconds)
for (int x = 0; x < 10; x++) {
digitalWrite(trlpin_B, HIGH); //Turn on the LH Indicator and flash (Hopefully!)
delay(250);
digitalWrite(trlpin_B, LOW);
delay(250);
delay(delayForNextLight);
for (int x = 0; x < 10; x++) {
digitalWrite(trlpin_J, HIGH); //Turn on the RH Indicator and flash (Hopefully!)
delay(250);
digitalWrite(trlpin_J, LOW);
delay(250);
}
//Next still Keeping the side lights on, I want to test the Fog light
digitalWrite(trlpin_H, HIGH); //Turn on the rear Fog Light
delay(delayForNextLight); //Delay
digitalWrite(trlpin_H, LOW); //Turn off the rear Fog Light
delay(delayForNextLight); //Delay
digitalWrite(trlpin_A, LOW); //Turn off the side lights
digitalWrite(trlpin_E, LOW);
digitalWrite(trlpin_C, HIGH); //Turn On convoy light (Hopefully the side lights are now Off)
delay(delayForNextLight);
digitalWrite(trlpin_C, LOW); //Turn Off the Convoy Light
}
}