My EE Capstone is coming up, and I'd like a few opinions on the readability of this code. It works, I'd just like to know if the flow and commenting is good enough for someone with a small amount of coding experience.
This program is designed for use with a ping pong ball scoreboard. A launcher shoots ping pong balls to a target, and if a player manages to hit the target, the sensors send a pulse to the appropriate input pin in the micro-controller, which then sends a predetermined amount of pulses to two decade counters. These decade counters connect to two 7-segment displays which display a player's score.
NOTE: This isn't straight C.
//Scoreboard_Program
/*****************************************************************
Input Pins are:
Reset Input = Analog 5
2 Points Input = 3 & 12
5 Points Input = 5 & 10
10 Points Input = 8
Output Pins are:
Score Output = 13
Reset Output = 11
******************************************************************/
//----------------------------------------------------------------
// Setup Variables
//----------------------------------------------------------------
int reset_in = A5; //Input pins
int points2 = 3;
int points2_2 = 12;
int points5 = 5;
int points5_2 = 10;
int points10 = 8;
int score_out = 13; //Output pins
int reset_out = 11;
int loop_val = 0;
int reset_in_val = 0; //Variables to store input pin H/L value
int points2_val = 0; //Preset to LOW
int points2_2_val = 0;
int points5_val = 0;
int points5_2_val = 0;
int points10_val = 0;
//----------------------------------------------------------------
//----------------------------------------------------------------
// Setup Pin I/O
//----------------------------------------------------------------
void setup()
{
pinMode(reset_in, INPUT); //Setup Inputs
pinMode(points2, INPUT);
pinMode(points2_2, INPUT);
pinMode(points5, INPUT);
pinMode(points5_2, INPUT);
pinMode(points10, INPUT);
pinMode(score_out, OUTPUT); //Setup Outputs
pinMode(reset_out, OUTPUT);
// Reset the score as soon as power is applied.
digitalWrite(reset_out, HIGH);
delay(50);
digitalWrite(reset_out, LOW);
}
//---------------------------------------------------------------
void loop()
{
//---------------------------------------------------------------
// Read Digital Pin Input
//---------------------------------------------------------------
reset_in_val = digitalRead(reset_in);
points2_val = digitalRead(points2);
points2_2_val = digitalRead(points2_2);
points5_val = digitalRead(points5);
points5_2_val = digitalRead(points5_2);
points10_val = digitalRead(points10);
//---------------------------------------------------------------
//---------------------------------------------------------------
// Reset Pin Function
//---------------------------------------------------------------
/*If the reset input pin is high, then the reset output pin
goes high for 30 milliseconds, then goes back low.*/
if(reset_in_val == HIGH)
{
digitalWrite(reset_out, HIGH);
delay(50);
digitalWrite(reset_out, LOW);
}
//---------------------------------------------------------------
//---------------------------------------------------------------
// Set Score Value
//---------------------------------------------------------------
/*If either 2pt pins goes high, go through the "Score Output
Loop" twice.*/
if(points2_val || points2_2_val == HIGH)
{
loop_val = 2;
}
/*If either 5pt pins goes high, go through the "Score Output
Loop" five times.*/
else if(points5_val || points5_2_val == HIGH)
{
loop_val = 5;
}
/*If the 10pt pin goes high, go through the "Score Output Loop"
ten times.*/
else if(points10_val == HIGH)
{
loop_val = 10;
}
/*If no pins are high, don't go through the "Score Output Loop"
at all.*/
else
{
loop_val = 0;
}
//----------------------------------------------------------------
//----------------------------------------------------------------
// Input Read Delay
//----------------------------------------------------------------
/* Delays the program so that when an input is read, it isn't
read twice. */
if(loop_val != 0)
{
delay(500);
}
//----------------------------------------------------------------
//----------------------------------------------------------------
// Score Output Loop
//----------------------------------------------------------------
while(loop_val > 0)
/*Sends a number of pulses out through the score pin. The number
of pulses depends on the input from the points pins.*/
{
digitalWrite(score_out, HIGH);
delay(50);
digitalWrite(score_out, LOW);
delay(50);
loop_val--;
}
//----------------------------------------------------------------
}