What does thus section of code mean

This is an outsourced bit of code that will program a lilypad Arduino jacket. I am unsure of what this section of code means. Does anyone out there understand this? I am a beginner wanting to learn!
First section of code is the area I am stuck with. Rest of the code below for context if that helps anyone

void RightTurn()
{
digitalWrite(rightSignal, HIGH);
{
delay(1000); // wait for 1 second
if (digitalRead(rightSwitch) == LOW)
{
while (digitalRead(rightSwitch) == LOW);
digitalWrite(rightSignal, LOW); // turn the right signal off
return;
}
}
digitalWrite(rightSignal, LOW);
{
delay(1000); // wait for one second
if (digitalRead(rightSwitch) == LOW)
{
while (digitalRead(rightSwitch) == LOW);
digitalWrite(rightSignal, LOW);
return;
}
}

}

int leftSwitch = 6; // my left button is attached to petal 6
int rightSwitch = 12; // my right button is attached to petal 12
int rightLow = 4; // the - side of my right button is attached to petal 4
int leftSignal = 8; // my left turn signal is attached to petal 8
int rightSignal = 11; // my right turn signal is attached to petal 11
int signalLow = 10; // the - sides of my signals are attached to petal 10
int boardLED = 13; // the LED on the Lilypad

void setup() // run once, when the sketch starts
{
pinMode(boardLED, OUTPUT); // sets the boardLED to be an output

pinMode(leftSignal, OUTPUT); // sets the leftSignal petal to be an output
pinMode(rightSignal, OUTPUT); // sets the rightSignal petal to be an output

pinMode(signalLow, OUTPUT); // sets the signalLow - petal to be an output
pinMode(rightLow, OUTPUT); // sets the signal rightlLow petal to be an output

pinMode(leftSwitch, INPUT); // sets leftSwitch to input pin
digitalWrite(leftSwitch, HIGH); // sets leftSwitch on
pinMode(rightSwitch, INPUT); // sets rightSwitch to input pin
digitalWrite(rightSwitch, HIGH); // sets rightSwitch on

digitalWrite(boardLED, HIGH); // sets boardLED on
digitalWrite(signalLow, LOW); // sets the signalLow petal to Low (-)
digitalWrite(rightLow, LOW); // sets the right button off
}

void loop() // run over and over again
{
checkLeft(); // checkleft state
checkRight(); // checkRight state
}

void checkLeft() // code to establish boardLED saftey light
{
if (digitalRead(leftSwitch) == LOW) // left switch not pressed
{
digitalWrite(boardLED, LOW);
while (digitalRead(leftSwitch) == LOW) // boardLED off
{
if (digitalRead(rightSwitch) == LOW) // right switch not pressed
{
while (digitalRead(rightSwitch) == LOW | digitalRead(leftSwitch) == LOW);
digitalWrite(boardLED, HIGH); // no buttons pressed boardLED on
return;
}
}
leftTurn();
}
}

void checkRight() //code to establish boardLED saftey light
{
if (digitalRead(rightSwitch) == LOW) // right switch not pressed
{
digitalWrite(boardLED, LOW);
while (digitalRead(rightSwitch) == LOW) // boardLED off
{
if (digitalRead(leftSwitch) == LOW)
{
while (digitalRead(leftSwitch) == LOW | digitalRead(rightSwitch) == LOW);
digitalWrite(boardLED, HIGH); // no buttons pressed boardLED on
return;
}
}

}
}

void leftTurn()
{
digitalWrite(leftSignal, HIGH); // LED pannel on
{
delay(1000); // wait for one second
if (digitalRead(leftSwitch) == LOW) // if button not pressed LED off
{
while (digitalRead(leftSwitch) == LOW);
digitalWrite(leftSignal, LOW); // LED off no button press
return;
}
}
digitalWrite(leftSignal, LOW); // turns off LED pannel
{
delay(1000); // wait for one second
if (digitalRead(leftSwitch) == LOW) // checks to see if pushbutton is pressed
{
while (digitalRead(leftSwitch) == LOW); // lights stay
digitalWrite(leftSignal, LOW);
return;
}
}
}

Hi
Well the answer is, to my eyes that this is badly written code

It also seems that the actual thing that it is trying to do is not all that complicated
I would suggest that you draw out a logic table of what you want the controls to do under all conditions. ie

Take an input pin (Right Switch). It has two states, ON, OFF and two transitions On to OFF and OFF to ON

Usually transitions are not important considerations so ON and OFF is all you need
Then look at the condition of the switch, does it go on as a pulse or is it held

The first few lines of the code seem to give an idea that for a right turn the right signal is instantly turned on, but after a second delay the low state of the switch is considered and a low signal output is given for as long as the Right Switch is low.. A bit dumb really. You can continuously look at the state in void() and at each state issue a command to an output.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html .
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom... :slight_smile:

These warning indicate that you should be using "||" (logical OR) here and not "|" (bitwise OR) in these two statements.

/Users/john/Documents/Arduino/sketch_oct12a/sketch_oct12a.ino: In function 'void checkLeft()':
/Users/john/Documents/Arduino/sketch_oct12a/sketch_oct12a.ino:48:41: warning: suggest parentheses around comparison in operand of '|' [-Wparentheses]
         while (digitalRead(rightSwitch) == LOW | digitalRead(leftSwitch) == LOW);
/Users/john/Documents/Arduino/sketch_oct12a/sketch_oct12a.ino: In function 'void checkRight()':
/Users/john/Documents/Arduino/sketch_oct12a/sketch_oct12a.ino:66:40: warning: suggest parentheses around comparison in operand of '|' [-Wparentheses]
         while (digitalRead(leftSwitch) == LOW | digitalRead(rightSwitch) == LOW);