Hi all,
I can't find my first post about this topic, but I'm still stuck. I'm programming a shooting gallery and can't seem to figure out how to keep score. I have 2 BCD chips connected to 2 7-segment displays. The displays are reading 00 fine. I can't get the score to increment after each hit of a target. Can anyone please shed some light on this for me? Relevant code only included. Thanks! Not sure if I entered code correctly.
[/ /*
*/
const int A = 34; // BCD 1A (to BCD - 7 segment IC)
const int B = 35; // BCD 1B (to BCD - 7 segment IC)
const int C = 36; // BCD 1C (to BCD - 7 segment IC)
const int D = 37; // BCD 1D (to BCD - 7 segment IC)
const int AA = 38; // BCD 2A (to BCD - 7 segment IC)
const int BB = 39; // BCD 2B (to BCD - 7 segment IC)
const int CC = 40; // BCD 2C (to BCD - 7 segment IC)
const int DD = 41; // BCD 2D (to BCD - 7 segment IC)
int target2State = 0; // variable for reading the target1 status
int target3State = 0; // variable for reading the target2 status
int target4State = 0; // variable for reading the target3 status
int target5State = 0; // variable for reading the target4 status
int target6State = 0; // variable for reading the target5 status
int target7State = 0; // variable for reading the target6 status
int target8State = 0; // variable for reading the target7 status
int target9State = 0; // variable for reading the target8 status
int target10State = 0; // variable for reading the target9 status
int target11State = 0; // variable for reading the target10 status
int pos = 0; // variable to store the servo position
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
int counter = 0;
int num_array[10][9] = { { 0,0,0,0,0,0,0,0 }, // 0
{ 0,0,0,0,0,0,0,1 }, // 1
{ 0,0,0,0,0,0,1,0 }, // 2
{ 0,0,0,0,0,0,1,1 }, // 3
{ 0,0,0,0,0,1,0,0 }, // 4
{ 0,0,0,0,0,1,0,1 }, // 5
{ 0,0,0,0,0,1,1,0 }, // 6
{ 0,0,0,0,0,1,1,1 }, // 7
{ 0,0,0,0,1,0,0,0 }, // 8
{ 0,0,0,0,1,0,0,1 }}; // 9
void setup() {
Serial.begin(4800); //Set to 4800 bps for sound card
//Serial.print(0xEF); //reset mp3 player
delay(2000);
giraffeStepper.setSpeed(80);
cobraservo.attach(12); // attaches the servo on pin 12 to the servo object
mickeyservo.attach(13); // attaches the servo on pin 13 to the servo object
for(int i = 2; i <=11; i++){
pinMode(i, INPUT); // initialize the target pins 2-11 as inputs:
}
for(int i = 22; i <=53; i++){
pinMode(i, OUTPUT); // initialize the attraction pins 22-53 as outputs:
cobraservo.write(90);
mickeyservo.write(179);
}
pinMode(wheel3Pin, OUTPUT);
pinMode(eyePin, OUTPUT);
pinMode(fantPin, OUTPUT);
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, LOW);
digitalWrite(D, LOW);
digitalWrite(AA, LOW);
digitalWrite(BB, LOW);
digitalWrite(CC, LOW);
digitalWrite(DD, LOW);
delay(10);
}
void loop(){
// read the state of the targets:
target11State = digitalRead(target11Pin); // START
if (target11State == HIGH) { //READ START BUTTON
Serial.print(001);
digitalWrite(fantPin, HIGH);
target3State = digitalRead(target3Pin); //
target4State = digitalRead(target4Pin); // Twinks
target5State = digitalRead(target5Pin); // Cobra
target6State = digitalRead(target6Pin); // Animals
target7State = digitalRead(target7Pin); // Cannon
target8State = digitalRead(target8Pin); // SR Cannoe
target9State = digitalRead(target9Pin); // SL Cannoe
target10State = digitalRead(target10Pin); // Mickey Mountain
if (target4State == HIGH) { //READ TWINKS
// turn LED on:
for (int counter = 0; counter < 20; ++counter)
{
Num_Write(counter+1);
}
digitalWrite(game24Pin, LOW);
}
else {
digitalWrite(game24Pin, LOW);
}
}
void Num_Write(int);
counter == 1{
digitalWrite(A,HIGH);
digitalWrite(B,LOW);
digitalWrite(C,LOW);
digitalWrite(D,LOW);
digitalWrite(AA,LOW);
digitalWrite(BB,LOW);
digitalWrite(CC,LOW);
digitalWrite(DD,LOW);
}
counter == 2{
digitalWrite(A,LOW);
digitalWrite(B,HIGH);
digitalWrite(C,LOW);
digitalWrite(D,LOW);
digitalWrite(AA,LOW);
digitalWrite(BB,LOW);
digitalWrite(CC,LOW);
digitalWrite(DD,LOW);
}
counter == 3{
digitalWrite(A,HIGH);
digitalWrite(B,HIGH);
digitalWrite(C,LOW);
digitalWrite(D,LOW);
digitalWrite(AA,LOW);
digitalWrite(BB,LOW);
digitalWrite(CC,LOW);
digitalWrite(DD,LOW);
}
counter == 4{
digitalWrite(A,LOW);
digitalWrite(B,LOW);
digitalWrite(C,HIGH);
digitalWrite(D,LOW);
digitalWrite(AA,LOW);
digitalWrite(BB,LOW);
digitalWrite(CC,LOW);
digitalWrite(DD,LOW);
}
counter == 5{
digitalWrite(A,HIGH);
digitalWrite(B,LOW);
digitalWrite(C,HIGH);
digitalWrite(D,LOW);
digitalWrite(AA,LOW);
digitalWrite(BB,LOW);
digitalWrite(CC,LOW);
digitalWrite(DD,LOW);
}
counter == 6{
digitalWrite(A,LOW);
digitalWrite(B,HIGH);
digitalWrite(C,HIGH);
digitalWrite(D,LOW);
digitalWrite(AA,LOW);
digitalWrite(BB,LOW);
digitalWrite(CC,LOW);
digitalWrite(DD,LOW);
}
counter == 7{
digitalWrite(A,HIGH);
digitalWrite(B,HIGH);
digitalWrite(C,HIGH);
digitalWrite(D,LOW);
digitalWrite(AA,LOW);
digitalWrite(BB,LOW);
digitalWrite(CC,LOW);
digitalWrite(DD,LOW);
}
counter == 8{
digitalWrite(A,LOW);
digitalWrite(B,LOW);
digitalWrite(C,LOW);
digitalWrite(D,HIGH);
digitalWrite(AA,LOW);
digitalWrite(BB,LOW);
digitalWrite(CC,LOW);
digitalWrite(DD,LOW);
}
counter == 9{
digitalWrite(A,HIGH);
digitalWrite(B,LOW);
digitalWrite(C,LOW);
digitalWrite(D,HIGH);
digitalWrite(AA,LOW);
digitalWrite(BB,LOW);
digitalWrite(CC,LOW);
digitalWrite(DD,LOW);
}
counter == 10{
digitalWrite(A,LOW);
digitalWrite(B,LOW);
digitalWrite(C,LOW);
digitalWrite(D,LOW);
digitalWrite(AA,HIGH);
digitalWrite(BB,LOW);
digitalWrite(CC,LOW);
digitalWrite(DD,LOW);
}
counter == 11{
digitalWrite(A,HIGH);
digitalWrite(B,LOW);
digitalWrite(C,LOW);
digitalWrite(D,LOW);
digitalWrite(AA,HIGH);
digitalWrite(BB,LOW);
digitalWrite(CC,LOW);
digitalWrite(DD,LOW);
}
}
}
code]