////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//run the sequence of testing lights IF the "NEW" push button is pressed///
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
{
newSwVal1 = digitalRead(switchPin_new);
delay(10);
newSwVal2 = digitalRead(switchPin_new);
if (newSwVal1 == newSwVal2) { // make sure we got 2 consistant readings!
if (newSwVal1 != buttonStateNewSw) { // the button state has changed!
if (newSwVal1 == HIGH) { // check if the button is pressed
if (lightModeNew == 0) { // is the light off?
lightModeNew = 1; // turn light on!
Tft_New_Test ();
//IF the NEW style switch is pressed
Tft_Side ();
digitalWrite(trlpin_A, HIGH);
digitalWrite(trlpin_E, HIGH);
Serial.println("Turn On Side Lights 2 LED"); //Turn on the trailer side lights
delay(walkToBackDelay); //Wait 10 seconds to get to walk to back of trailer
for (int x = 0; x < 5; x++)
{
Tft_Brake ();
digitalWrite(trlpin_F, HIGH); //Turn on the brake and flash
digitalWrite(trlpin_M, HIGH);
delay(brakeFlashTime);
digitalWrite(trlpin_F, LOW);
digitalWrite(trlpin_M, LOW);
delay(brakeFlashTime);
}
}
Tft_LH_Ind (); //Turn on the LH Indicator and flash
for (int x = 0; x < 10; x++)
{
digitalWrite(trlpin_B, HIGH);
delay(indFlashTime);
digitalWrite(trlpin_B, LOW);
delay(indFlashTime);
}
delay(delayForNextLight);
Tft_RH_Ind (); //Turn on the RH Indicator and flash
for (int x = 0; x < 10; x++)
{
digitalWrite(trlpin_J, HIGH);
delay(indFlashTime);
digitalWrite(trlpin_J, LOW);
delay(indFlashTime);
}
delay(delayForNextLight);
digitalWrite(trlpin_H, HIGH); //Turn on the rear Fog Light
Tft_Fog ();
delay(delayForNextLight); //Delay
digitalWrite(trlpin_H, LOW); //Turn off the rear Fog Light
tft.fillScreen(ILI9340_BLACK);
delay(delayForNextLight); //Delay
digitalWrite(trlpin_A, LOW); //Turn off the side lights
digitalWrite(trlpin_E, LOW);
Tft_Convoy ();
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
tft.fillScreen(ILI9340_BLACK);
Tft_End ();
delay(5000);
software_Reset();
} else {
lightModeNew = 0;
}
}
}
}
}
void software_Reset() // Restarts program from beginning but does not reset the peripherals and registers
{
asm volatile (" jmp 0");
}
void Tft_Side ()
{
tft.fillScreen(ILI9340_RED);
tft.setCursor(50, 90);
tft.setTextColor(ILI9340_WHITE);
tft.setTextSize(10);
tft.println("SIDE");
}
void Tft_Brake ()
{
tft.fillScreen(ILI9340_BLACK);
delay(tftDelay);
tft.fillScreen(ILI9340_RED);
tft.setCursor(50, 100);
tft.setTextColor(ILI9340_WHITE);
tft.setTextSize(8);
tft.println("BRAKE");
}
void Tft_LH_Ind ()
{
tft.fillScreen(ILI9340_BLUE);
delay(tftDelay);
tft.setCursor(50, 165);
tft.setTextColor(ILI9340_YELLOW);
tft.fillCircle(60, 60, 60, ILI9340_YELLOW);
tft.setTextSize(10);
tft.println("LEFT");
}
void Tft_RH_Ind ()
{
tft.fillScreen(ILI9340_BLUE);
delay(tftDelay);
tft.setCursor(40, 165);
tft.setTextColor(ILI9340_YELLOW);
tft.fillCircle(255, 60, 60, ILI9340_YELLOW);
tft.setTextSize(9);
tft.println("RIGHT");
}
void Tft_Fog ()
{
tft.fillScreen(ILI9340_BLACK);
delay(tftDelay);
tft.setCursor(50, 20);
tft.setTextColor(ILI9340_RED);
tft.fillCircle(150, 170, 55, ILI9340_RED);
tft.setTextSize(11);
tft.println("FOG");
}
void Tft_Convoy ()
{
tft.fillScreen(ILI9340_BLACK);
delay(tftDelay);
tft.setCursor(40, 40);
tft.setTextColor(ILI9340_RED);
tft.fillCircle(150, 170, 55, ILI9340_WHITE);
tft.setTextSize(7);
tft.println("CONVOY");
}
void Tft_End ()
{
tft.fillScreen(ILI9340_BLACK);
delay(tftDelay);
tft.setCursor(40, 40);
tft.setTextColor(ILI9340_RED);
tft.setTextSize(8);
tft.println("END");
tft.setCursor(40, 150);
tft.println("TEST");
}
void Tft_Old_Test ()
{
testFillScreen();
tft.fillScreen(ILI9340_BLACK);
tft.setCursor(30, 90);
tft.setTextColor(ILI9340_GREEN);
tft.setTextSize(5);
tft.println("Old Style");
tft.setCursor(30, 150);
tft.println("Selected");
delay(4000);
}
void Tft_New_Test ()
{
testFillScreen();
tft.fillScreen(ILI9340_BLACK);
tft.setCursor(30, 90);
tft.setTextColor(ILI9340_GREEN);
tft.setTextSize(5);
tft.println("New Style");
tft.setCursor(30, 150);
tft.println("Selected");
delay(4000);
}
unsigned long testFillScreen() {
unsigned long start = micros();
tft.fillScreen(ILI9340_BLACK);
tft.fillScreen(ILI9340_RED);
tft.fillScreen(ILI9340_GREEN);
tft.fillScreen(ILI9340_BLUE);
tft.fillScreen(ILI9340_BLACK);
return micros() - start;
}
unsigned long testTriangles() {
unsigned long start;
int n, i, cx = tft.width() / 2 - 1,
cy = tft.height() / 2 - 1;
tft.fillScreen(ILI9340_BLACK);
n = min(cx, cy);
start = micros();
for(i=0; i<n; i+=5) {
tft.drawTriangle(
cx , cy - i, // peak
cx - i, cy + i, // bottom left
cx + i, cy + i, // bottom right
tft.Color565(0, 0, i));
}
return micros() - start;
}
unsigned long testRoundRects() {
unsigned long start;
int w, i, i2,
cx = tft.width() / 2 - 1,
cy = tft.height() / 2 - 1;
tft.fillScreen(ILI9340_BLACK);
w = min(tft.width(), tft.height());
start = micros();
for(i=0; i<w; i+=6) {
i2 = i / 2;
tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.Color565(i, 0, 0));
}
return micros() - start;
}
unsigned long testFilledRoundRects() {
unsigned long start;
int i, i2,
cx = tft.width() / 2 - 1,
cy = tft.height() / 2 - 1;
tft.fillScreen(ILI9340_BLACK);
start = micros();
for(i=min(tft.width(), tft.height()); i>20; i-=6) {
i2 = i / 2;
tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.Color565(0, i, 0));
}
return micros() - start;
}