# Help with project

What I want to do is keep score with my coin soccer game. I will have 2 metal contacts in the goals that when a coin goes through it will break contact and send a signal to the Arduino having the contacts allways HIGH and then when its LOW, it changes an 7 segment LED. I am very new to programming and the C language. I think I can write the whole IF and ELSE statements but I don't know how to make the LED display change. I need the LED display to change after getting the signal from my Arduino by going up one number. It is a single 7 segment display. Can someone help me with the code for that? Thanks in advance.

You need to say (or better still show in a schematic) how the 7 segment display is wired up. Otherwise how do you know what pins to send high or low?

I don't, thats the problem. I could look into the LED display program and see what pins. I'll draw up a schematic when I get the chance.

Schematic: http://i.imgur.com/YOCKZ.jpg I can't figure out how to do the IF and ELSE parts, so some help/explaination would be greatly appreciated.

Here's one option for you. I am sure that there are more graceful and efficient ways to do it, but here is an example just using if else blocks. What you'll first need to do is make a list of what numbers use what LED segments. My code will assume that A is at the 12 o'clock position and the segments proceed clockwise around the center. G is the center bar.

``````void updateSevenSeg(unsinged int inNum)
{
//A - Segment
//Turn on A-segment for all numbers that use it
if ((inNum == 2) || (inNum == 3) || (inNum == 5) || (inNum == 6) || (inNum == 7) || (inNum == 8) || (inNum == 9) {
digitalWrite(A, HIGH);
} else {
//Turn off A-segement for all that don't
digitalWrite(A, LOW);
}

//B - Segment
//Turn on B-segment for all numbers that use it
if ((inNum == 1) || (inNum == 2) || (inNum == 3) || (inNum == 4) || (inNum == 7) || (inNum == 8) || (inNum == 9) {
digitalWrite(B, HIGH);
} else {
//Turn off B-segement for all that don't
digitalWrite(B, LOW);
}

//C - Segment
//Turn on C-segment for all numbers that use it
if ((inNum == 1) || (inNum == 3) || (inNum == 4) || (inNum == 5) || (inNum == 6) || (inNum == 7) || (inNum == 8) || (inNum == 9) {
digitalWrite(C, HIGH);
} else {
//Turn off C-segement for all that don't
digitalWrite(C, LOW);
}

//Repeat the same process for the remaining 4-segments
}
``````

Looking at what I just wrote, I would actually write my conditionals like so:

``````//A-Segment
if ((inNum ==1) || (inNum ==4) {
digitalWrite(A, LOW);
} else {
digitalWrite(A, HIGH);
}
``````

I would write them like that because the majority of the numbers use that segment. With fewer parts in the conditional, debugging is easier, execution of the program is faster, and the program size is reduced.

The Playground is a great way of avoiding wheel reinvention http://arduino.cc/playground/Main/InterfacingWithHardware#Output

In that diagram I see no current limiting resistors, you need them to avoid damaging the LEDs and the arduino outputs. Use 220R unless you know better.

Grumpy_Mike: In that diagram I see no current limiting resistors, you need them to avoid damaging the LEDs and the arduino outputs. Use 220R unless you know better.

I normally use 100ohm for 5v, 220 gets a little darker, but either will work. What does "inNum" mean? This is some code I found on the internet regarding control of LED display:

``````/*
Make Projects: How to Drive a 7 Segment LED
URL:
By: Riley Porter
This is an introduction on how to drive a 7 Segment LED using only a Arduino.  This is
not the best way to do this.  This is meant to be a learning excercise.  In later tutorials
I will show you how to use an dedicated IC using SPI or a Shift Register.  Enjoy.

Use this link for instructions: http://makeprojects.com/Project/Drive-a-7-Segment-LED-with-an-Arduino/645/1

digitalWrite(A, HIGH) = turn off the "A" segment in the LED display
digitalWrite(B, LOW)  = turn on the "B" segment in the LED display

*/
#define A 8
#define B 9
#define C 2
#define D 3
#define E 4
#define F 5
#define G 6

void clr()
{
//Clears the LED
digitalWrite(A, HIGH);
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
digitalWrite(D, HIGH);
digitalWrite(E, HIGH);
digitalWrite(F, HIGH);
digitalWrite(G, HIGH);

}

void char_A()
{
digitalWrite(D, HIGH);
digitalWrite(E, LOW);
digitalWrite(F, LOW);
digitalWrite(G, LOW);
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, LOg9tW);
}
z
void char_B()
{
//Displays B
digitalWrite(D, LOW);
digitalWrite(E, LOW);
digitalWrite(F, LOW);
digitalWrite(G, LOW);
digitalWrite(A, HIGH);
digitalWrite(B, HIGH);
digitalWrite(C, LOW);
}

void char_C()
{
//Displays C
digitalWrite(D, LOW);
digitalWrite(E, LOW);
digitalWrite(F, LOW);
digitalWrite(G, HIGH);
digitalWrite(A, LOW);
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
}

void char_D()
{
//Displays D
digitalWrite(D, LOW);
digitalWrite(E, LOW);
digitalWrite(F, HIGH);
digitalWrite(G, LOW);
digitalWrite(A, HIGH);
digitalWrite(B, LOW);
digitalWrite(C, LOW);
}

void char_E()
{
//Displays E
digitalWrite(D, LOW);
digitalWrite(E, LOW);
digitalWrite(F, LOW);
digitalWrite(G, LOW);
digitalWrite(A, LOW);
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
}

void char_F()
{
//Displays F
digitalWrite(D, HIGH);
digitalWrite(E, LOW);
digitalWrite(F, LOW);
digitalWrite(G, LOW);
digitalWrite(A, LOW);
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
}

void one()
{
//Displays 1
digitalWrite(D, HIGH);
digitalWrite(E, LOW);
digitalWrite(F, LOW);
digitalWrite(G, HIGH);
digitalWrite(A, HIGH);
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
}

void two()
{
//Displays 2
digitalWrite(D, LOW);
digitalWrite(E, LOW);
digitalWrite(F, HIGH);
digitalWrite(G, LOW);
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, HIGH);
}

void three()
{
//Displays 3
digitalWrite(D, LOW);
digitalWrite(E, HIGH);
digitalWrite(F, HIGH);
digitalWrite(G, LOW);
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, LOW);
}

void four()
{
//Displays 4
digitalWrite(D, HIGH);
digitalWrite(E, HIGH);
digitalWrite(F, LOW);
digitalWrite(G, LOW);
digitalWrite(A, HIGH);
digitalWrite(B, LOW);
digitalWrite(C, LOW);
}

void five()
{
//Displays 5
digitalWrite(D, LOW);
digitalWrite(E, HIGH);
digitalWrite(F, LOW);
digitalWrite(G, LOW);
digitalWrite(A, LOW);
digitalWrite(B, HIGH);
digitalWrite(C, LOW);
}

void six()
{
//Displays 6
digitalWrite(D, LOW);
digitalWrite(E, LOW);
digitalWrite(F, LOW);
digitalWrite(G, LOW);
digitalWrite(A, LOW);
digitalWrite(B, HIGH);
digitalWrite(C, LOW);
}

void seven()
{
//Displays 7
digitalWrite(D, HIGH);
digitalWrite(E, HIGH);
digitalWrite(F, HIGH);
digitalWrite(G, HIGH);
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, LOW);
}

void eight()
{
//Displays 8
digitalWrite(D, LOW);
digitalWrite(E, LOW);
digitalWrite(F, LOW);
digitalWrite(G, LOW);
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, LOW);
}

void nine()
{
//Displays 9
digitalWrite(D, LOW);
digitalWrite(E, HIGH);
digitalWrite(F, LOW);
digitalWrite(G, LOW);
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, LOW);
}

void zero()
{
//Displays 0
digitalWrite(D, LOW);
digitalWrite(E, LOW);
digitalWrite(F, LOW);
digitalWrite(G, HIGH);
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, LOW);
}

void LoopDisplay()
{
//Loop through all Chars and Numbers
char_A();
delay(1000);
char_B();
delay(1000);
char_C();
delay(1000);
char_D();
delay(1000);
char_E();
delay(1000);
char_F();
delay(1000);
one();
delay(1000);
two();
delay(1000);
three();
delay(1000);
four();
delay(1000);
five();
delay(1000);
six();
delay(1000);
seven();
delay(1000);
eight();
delay(1000);
nine();
delay(1000);
zero();
delay(1000);
}

void setup()
{
//Setup our pins
pinMode(A, OUTPUT);
pinMode(B, OUTPUT);
pinMode(C, OUTPUT);
pinMode(D, OUTPUT);
pinMode(E, OUTPUT);
pinMode(F, OUTPUT);
pinMode(G, OUTPUT);
Serial.begin(9600);  //Begin serial communcation

}

void loop()
{
Serial.println("Starting\n");
LoopDisplay();

}
``````

Moderator edit: Please put code in code boxes, using the # icon on the editor's toolbar. If you forget to do this, you can click on "modify", then highlight the code, click on #, then click "save".

What does “inNum” mean?

Where it is not in the code?

This is some code I found on the internet regarding control of LED display

… and ?

``````void updateSevenSeg(unsinged int inNum)
``````

It is the single decimal (or hex) digit you want to be displayed.

(and it should be "unsigned", unless you want it slightly carbonised)