And here is the second half of the above code. This gets pasted directly under the last part.
//Right Blinker Code/////////////////////////////////////////////////////////////////////////////////////////////////////////
RightSwitchVal = digitalRead(RightSwitch); //read and store Right Blinker switch status
if ((RightSwitchVal == HIGH) && (previousRightSwitchVal == LOW)) //compares current switch status to previous status
{
previousRightSwitchVal = RightSwitchVal; //sets the current status as the old status in preparation for the next check
RightSwitchMillis = currentMillis; //sets a time stamp at the current time
}
if ((RightSwitchVal == HIGH) && (currentMillis - RightSwitchMillis > interval/2) && (RightPulse == LOW) && (currentMillis - RightPulseMillis > interval/10000)) //checks if the Right Blinker switch is pressed and how long it has been pressed for,
{ // if the Pulse was last set LOW, and if it is time for another step in brightness.
RightPulseMillis = currentMillis; //Time stamp used to check how long since the brightness, i, was last changed
R++; //Adds 1 to R value. The value of R dictates light brightness
RightBlinkState = R; //Sets the light brightness to the value of i.
analogWrite(RightBlink, RightBlinkState); //Sets the blinker brightness to the dictates level. Why I cannot go directly use (RightBlink, R), I do not know...
}
if (R == 255) //checks value of R
{
RightPulse = HIGH; //if R is maxed out at 255, the RightPulse goes HIGH. This lets R decrease.
}
if ((RightSwitchVal == HIGH) && (currentMillis - RightSwitchMillis > interval/2) && (RightPulse == HIGH) && (currentMillis - RightPulseMillis > interval/10000)) //checks if the Right Blinker switch is pressed and how long it has been pressed for,
{ // if the Pulse was last set HIGH, and if it is time for another step in brightness.
RightPulseMillis = currentMillis; //if the Right Blinker switch is pressed on and has been on for more than half a second, set a time stamp for the fade in.
R--; //Subtracts 1 from R value
RightBlinkState = R; //Sets the value of light brightness to the value of R
analogWrite(RightBlink, RightBlinkState); //set the blinker brightness to the value of RightBlinkState
}
if ((R == 0) && (currentMillis - RightSwitchMillis > interval/2)) // Checks if R is at 0 so that the brightening cycle can repeate. Also checks if the initial rapid flash sequence is over.
{
RightPulse = LOW; //if the above conditions are met, reset RightPulse to LOW.
}
if((RightSwitchVal == HIGH) && (currentMillis - RightFlashMillis > interval/50) && (currentMillis - RightSwitchMillis < interval/2)) //if the Right Blink switch is HIGH but less than half a second has elapsed,
{ // this checks if the Right Blink switch is HIGH and more than one-fifteith
RightFlashMillis = currentMillis; // saves current time //of a second has elapsed since the last time previousMillis10 was reset.
if (RightBlinkState == LOW)
RightBlinkState = HIGH;
else
RightBlinkState = LOW; //if more than one-fiftieth of a second has elapsed since the time stamp was reset, reverse the state of the Right Blinker.
digitalWrite(RightBlink, RightBlinkState); // set the Right Blinker with the state of the variable:
}
if (RightSwitchVal == LOW) //checks if the Blinker switch is still on or not. If it is off, the following occurs...
{
previousRightSwitchVal = RightSwitchVal; //makes sure the previousBrakeSwitch value is reset to off when the switch is in fact off.
RightBlinkState = LOW; //resets the blinker
digitalWrite(RightBlink, RightBlinkState); //Overall, if the Right Blinker switch is off, keep the Right Blinker off.
R = 0; //resets R in preparation for the next usage.
}
//Left Blinker Code. Identical to Right Blinker Code.//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
LeftSwitchVal = digitalRead(LeftSwitch);
if ((LeftSwitchVal == HIGH) && (previousLeftSwitchVal == LOW))
{
previousLeftSwitchVal = LeftSwitchVal;
LeftSwitchMillis = currentMillis;
}
if ((LeftSwitchVal == HIGH) && (currentMillis - LeftSwitchMillis > interval/2) && (LeftPulse == LOW) && (currentMillis - LeftPulseMillis > interval/10000))
{
LeftPulseMillis = currentMillis;
L++;
LeftBlinkState = L;
analogWrite(LeftBlink, LeftBlinkState);
}
if (L == 255)
{
LeftPulse = HIGH;
}
if ((LeftSwitchVal == HIGH) && (currentMillis - LeftSwitchMillis > interval/2) && (LeftPulse == HIGH) && (currentMillis - LeftPulseMillis > interval/10000))
{
LeftPulseMillis = currentMillis;
L--;
LeftBlinkState = L;
analogWrite(LeftBlink, LeftBlinkState);
}
if ((L == 0) && (currentMillis - LeftSwitchMillis > interval/2))
{
LeftPulse = LOW;
}
if((LeftSwitchVal == HIGH) && (currentMillis - LeftFlashMillis > interval/50) && (currentMillis - LeftSwitchMillis < interval/2))
{
LeftFlashMillis = currentMillis;
if (LeftBlinkState == LOW)
LeftBlinkState = HIGH;
else
LeftBlinkState = LOW;
digitalWrite(LeftBlink, LeftBlinkState);
}
if (LeftSwitchVal == LOW)
{
previousLeftSwitchVal = LeftSwitchVal;
LeftBlinkState = LOW;
digitalWrite(LeftBlink, LeftBlinkState);
L = 0;
}
}