Can someone please help me understand this bit of partial code? So I think the code turns on an led, then lights a different led when certain conditions are met (case 0-3). I believe the cases have to do with analog pins 0-3. But I'm not sure what each case is actually looking for. Can someone please help explain what going on in each case definition? Thanks.
digitalWrite(led[currentPort],HIGH);
switch (currentPort)
{
case 0:
while (!(PINC & B00000001));
break;
case 1:
while (!(PINC & B00000010));
break;
case 2:
while (!(PINC & B00000100));
break;
case 3:
while (!(PINC & B00001000));
break;
}
hitCounter++;
Ew! that's a nasty piece of code. Where did you found that code ? Is it some very special optimized code for a specific purpose ?
The PINC is a register of the microcontroller. It is the 8 pins of PORTC.
The while(condition)[glow=red,2,300];[/glow]
should be read as : "while the condition is true, do nothing". Because the semicolon ";" is an empty statement.
The currentPort can be 0,1,2,3 (perhaps more). The switch-case statement executes the appropriate statement.
For example when currentPort is 0, the while-statement waits while the first pin of PORTC (bit 0 of PORTC) is kept low.
Perhaps buttons are connected to PORTC, and the code waits until the button is released.
Thanks for the reply. I've added a little more to the code above to clarify. It is code for a target system. Reactive Targets for 6mm Airsoft and NERF® As an Arduino amateur, I was trying to read and understand the code completely before attempting the build.
Each port is connected to a piezo (on analog pins) to register hits on a target. Each target also has an led (on digital pins) to signify which target is active.
So if I understand this correctly:
The led on the currentPort (active target) goes on,
then the switch-case statement checks pins A0-A3 to see that they are low (no signal from piezo).
If they are low, nothing happens.
If ANY of those pins goes high, then the code advances and a hit is registered?
It seems like if you hit any of the targets not just the active (lit) one, a hit will be registered. Or is it only looking for switch-case on the currentPort?
I'm sorry, but I have my doubts with the code and the schematic. I would do both in a different way.
You say "nothing happens". In my opinion, nothing happens when the Arduino is turned off 
The while-statement waits until the piezo is hit. After the hit, the code advances.