Hi! Im a grade 10 student, our project is to make an arcade game, what we have in mind is a pop-a-shot game (like the picture below), I know how to code the IR sensor and led but what our teacher will not teach us is the seven segment display. We have our drawn design below.
60 seconds=1 minute countdown
2.When someone shoots is starts the countdown
the IR detects the ball
-Add 1 point
-It shows a check
there is no ball
-It shows a X mark
60 seconds end
5 seconds it shows the score made
after 5 seconds
-The countdown is back to 60 seconds
-the score is back to zero
Note:
-You can be the judge of what pins to use just tell
-any added info is welcome
-IF A 4 digit 7 segment code is too hard a 2 digit scorer is accepted
I foresaw the code as a bit simple but what made it hard was the segment
You need a few things:
A font array to map the numbers you want to display to the segments being used.
Digits are like this:
a
f b
g
e c
d DP if used
declare the array before setup().
Then use blink without delay to multiplex the data out to the display. Every 2-3mS, set up the data and enable of the common cathode transistors.
void loop(){
currentMillis = millis(); // all time elements are type unsigned long, declare before setup()
elapsedMillis = currentMillis - previousMillis;
if (elapsedMillis >= onDuration){ // onDuration set for 2, 3 whatever you use, up to about 8 for 30Hz refresh
previousMillis = previousMillis + onDuration; // set up for next interval
// turn off current digit drive transistor, assume using pins 15-14-13-12, set up in an array:
digitalWrite (digitPin[digitDrive], LOW);
digitDrive = digitDrive +1; // point to next digit
if (digitDrive == 4){ digitDrive = 0;} // reset to initial digit
// assume you're using 4 bits of PORTD and 4 bits of PORTB: 7-6-5-4, and 11-10-9-8, for DP-g-f-e, d-c-b-a
// and data is stored in an array
// clear lower 4 bits of PORTB
PORTB = PORTB & 0b11110000;
// look up the font (segment mapping), mask off lower 4 bits of data, OR into output register
PORTB = PORTB | (fontArray[dataArray[digitDrive]] & 0b00001111);
// clear upper 4 bits of PORTD,
// look up the font (segment mapping), mask off upper 4 bits of data, OR into output register
PORTD = PORTD & 0b00001111;
PORTD = PORTD | (fontArray[dataArray[digitDrive]] & 0b11110000);
// turn on the transistor for the current data
digitalWrite (digitPin[digitDrive], HIGH);
}
// do whatever you do to update dataArray[0], dataArray[1], dataArray[2], dataArray[3] with data while the 2-8mS is passing by to turn on the next digit
}
Make sure you use current limit with all the output pins.
LEDs: (5V - (Vf of LED) - (Vce of transistor))/10mA
Say Vf is 2.5V and Vce is 0.5V, then (5V - 2.5V - 0.5)/.01 = 200 ohm
Transistor base resistor: (5V - Vbe)/20mA
assume Vbe = 0.7V (1 diode drop), then
(5V - 0.7V)/.02 = 215 ohm, can use 200 also]