...And some more:
void lightStopper() {
clearLCD();
// light each pin one by one using a function A
for (int j = 6; j > 0; j--) {
b = j;
lightShiftPinA(j);
delay(time);
check2();
if(j == 4) {
digitalWrite(latchPin, 0);
shiftOut(dataPin, clockPin, 0);
digitalWrite(latchPin, 1);
analogWrite(blPin, 255);
mdl = true;
for(i = 0; i < mdltime; i++) { // TIME ! ! ! !
check2();
delay(1);
}
analogWrite(blPin, 0);
mdl = false;
}
}
// light each pin one by one using a function B
for (int j = 1; j < 7; j++) {
b = j;
lightShiftPinB(j);
delay(time);
check();
if(j == 3) {
digitalWrite(latchPin, 0);
shiftOut(dataPin, clockPin, 0);
digitalWrite(latchPin, 1);
analogWrite(rdPin, 255);
mdl = true;
for(i = 0; i < mdltime; i++) { // TIME ! ! ! !
check();
delay(1);
}
analogWrite(rdPin, 0);
mdl = false;
}
}
lightStopper();
}
void check() {
irval = digitalRead(irPin);
if(irval == 0) {
switch (b) {
case 1:
Wrong();
for(i = 0; i < 5; i++) {
shiftOut(dataPin, clockPin, 1);
delay(100);
}
clearLCD();
break;
case 2:
Wrong();
for(i = 0; i < 5; i++) {
shiftOut(dataPin, clockPin, 2);
delay(100);
}
clearLCD();
break;
case 3:
if(mdl == true) {
mdl = false;
Loser();
lightStopper();
}
Wrong();
for(i = 0; i < 5; i++) {
shiftOut(dataPin, clockPin, 3);
delay(100);
}
clearLCD();
break;
case 4:
Wrong();
for(i = 0; i < 5; i++) {
shiftOut(dataPin, clockPin, 4);
delay(100);
}
clearLCD();
break;
case 5:
Wrong();
for(i = 0; i < 5; i++) {
shiftOut(dataPin, clockPin, 5);
delay(100);
}
clearLCD();
break;
case 6:
Wrong();
for(i = 0; i < 5; i++) {
shiftOut(dataPin, clockPin, 6);
delay(100);
}
clearLCD();
break;
}
}
}
void check2() {
irval = digitalRead(irPin);
if(irval == 0) {
switch (b) {
case 6:
Wrong();
for(i = 0; i < 5; i++) {
shiftOut(dataPin, clockPin, 1);
delay(100);
}
clearLCD();
break;
case 5:
Wrong();
for(i = 0; i < 5; i++) {
shiftOut(dataPin, clockPin, 2);
delay(100);
}
clearLCD();
break;
case 4:
if(mdl == true) {
mdl = false;
Winner();
lightStopper();
}
Wrong();
for(i = 0; i < 5; i++) {
shiftOut(dataPin, clockPin, 3);
delay(100);
}
clearLCD();
break;
case 3:
Wrong();
for(i = 0; i < 5; i++) {
shiftOut(dataPin, clockPin, 4);
delay(100);
}
clearLCD();
break;
case 2:
Wrong();
for(i = 0; i < 5; i++) {
shiftOut(dataPin, clockPin, 5);
delay(100);
}
clearLCD();
break;
case 1:
Wrong();
for(i = 0; i < 5; i++) {
shiftOut(dataPin, clockPin, 6);
delay(100);
}
clearLCD();
break;
}
}
}
void lightShiftPinA(int p) {
//defines a local variable
int pin;
//this is line uses a bitwise operator
//shifting a bit left using << is the same
//as multiplying the decimal number by two.
pin = 1<< p;
//ground latchPin and hold low for as long as you are transmitting
digitalWrite(latchPin, 0);
//move 'em out
shiftOut(dataPin, clockPin, pin);
//return the latch pin high to signal chip that it
//no longer needs to listen for information
digitalWrite(latchPin, 1);
}
//This function uses that fact that each bit in a byte
//is 2 times greater than the one before it to
//shift the bits higher
void lightShiftPinB(int p) {
//defines a local variable
int pin;
//start with the pin = 1 so that if 0 is passed to this
//function pin 0 will light.
pin = 1;
for (int x = 0; x < p; x++) {
pin = pin * 2;
}
//ground latchPin and hold low for as long as you are transmitting
digitalWrite(latchPin, 0);
//move 'em out
shiftOut(dataPin, clockPin, pin);
//return the latch pin high to signal chip that it
//no longer needs to listen for information
digitalWrite(latchPin, 1);
}