GAMERIFTRobotics & Coding Shop kits
HomeKitsFor schoolsAboutGAMERIFT Store ↗
Beginner Kit · Lesson 07 of 12

Count On Me

Seven tiny lamps pretending to be a number. Wire them all and build a counting machine.

Unlock your lessons

Enter the access code from the card inside your Beginner Kit (or from your GAMERIFT order email). Your name appears on every page and printout as the licensee.

Don't have a kit yet? Get the Beginner Kit, the code ships inside. Lost your code? Contact us with your order number.

LICENSED TO , PERSONAL USE · © GAMERIFT

BRIEF The oldest digital number in the world

Microwave clocks, petrol pumps, scoreboards, lift buttons: the seven-segment display has been showing humanity its numbers since before your parents were born. It is nothing but seven little LED bars arranged as an 8. Light the right bars and any digit appears. Today you wire all seven, teach your board the shapes of the digits, and build a counter that ticks up every time you press a button. This is the most wires you have ever used. Go slow. It is worth it.

Time: 60–75 minutes · Difficulty: 4/5, mostly patience · You need: Lesson 03 done (buttons).

KIT What you need

Concept · Seven bars, one alphabet

Engineers name the bars a to g: a is the top bar, then clockwise around the edge, b (top right), c (bottom right), d (bottom), e (bottom left), f (top left), and g is the middle. A "7" is just a+b+c. A "8" is everything. Once you can light bars on command, digits are simply spelling.

Concept · Arrays, or teaching the board a list

Ten digits, seven bars each. You could write seventy digitalWrite lines... or you could hand the board a table and say "digit 4 is row 4 of the table". A list a program can look things up in is called an array, and it is one of the most useful ideas in all of coding. Today it saves you sixty lines of typing.

Concept · Finding the shared legs

Hold the display with the decimal point at the bottom right. It has 5 legs on top, 5 on the bottom. The middle leg of each row is the shared ground (they are connected to each other inside, so you only need to wire one of them). Every other leg controls one bar. Our display shares ground, "common cathode", so a bar lights when its leg goes HIGH.

BUILD Wire it

Unplug the USB. Straddle the display across the breadboard's middle channel like you did with the button. Wire the shared ground first, then work through the bars one by one, ticking them off on paper.

FromToWhy
Bottom middle leg220Ω resistor → R3 GNDShared ground, one bodyguard for all
R3 pin 3Leg for bar a (top row, right of middle)Top bar
R3 pin 4Leg for bar b (top row, far right)Top right
R3 pin 5Leg for bar c (bottom row, right of middle)Bottom right
R3 pin 6Leg for bar d (bottom row, second from left)Bottom bar
R3 pin 7Leg for bar e (bottom row, far left)Bottom left
R3 pin 8Leg for bar f (top row, second from left)Top left
R3 pin 9Leg for bar g (top row, far left)The middle bar
R3 pin 10Button leg · other leg to GNDThe counting trigger, like Lesson 03

Leg layouts can differ between displays. If a digit comes out scrambled later, don't rewire in a panic, use the Break It section's "bar test" to map YOUR display, then swap the wires calmly.

CODE Program it

// GAMERIFT Beginner Kit, Lesson 07: Count On Me
// An array holds the shape of every digit. The button counts.

const int barPins[7] = {3, 4, 5, 6, 7, 8, 9};  // bars a,b,c,d,e,f,g
const int buttonPin = 10;

// The digit table: one row per digit, one 1/0 per bar (a to g).
const int digits[10][7] = {
  {1,1,1,1,1,1,0},  // 0
  {0,1,1,0,0,0,0},  // 1
  {1,1,0,1,1,0,1},  // 2
  {1,1,1,1,0,0,1},  // 3
  {0,1,1,0,0,1,1},  // 4
  {1,0,1,1,0,1,1},  // 5
  {1,0,1,1,1,1,1},  // 6
  {1,1,1,0,0,0,0},  // 7
  {1,1,1,1,1,1,1},  // 8
  {1,1,1,1,0,1,1}   // 9
};

int count = 0;

void showDigit(int n) {
  for (int i = 0; i < 7; i++) {
    digitalWrite(barPins[i], digits[n][i]);   // look it up, light it up
  }
}

void setup() {
  for (int i = 0; i < 7; i++) {
    pinMode(barPins[i], OUTPUT);
  }
  pinMode(buttonPin, INPUT_PULLUP);
  showDigit(0);
}

void loop() {
  if (digitalRead(buttonPin) == LOW) {   // pressed (upside-down, remember)
    count = count + 1;
    if (count > 9) count = 0;            // only one digit, wrap around
    showDigit(count);
    delay(250);                           // so one press counts once
  }
}
  1. Upload. A zero appears. Press the button: 1, 2, 3... past 9 it rolls back to 0.
  2. Look how short loop() is. The array did the heavy lifting, that is the power of a good table.

BREAK IT Now break it on purpose

  1. The bar test. In setup(), light just barPins[0] and see which bar glows. Is it really the top one? Test all seven one at a time and draw your display's true map. If any wires are swapped, this is how you find them, no guessing.
  2. Pull out one bar's wire (say, bar g) and count to 9. Watch 8 become 0 and 4 become... something sad. One missing segment scrambles half the alphabet, which is why a half-dead petrol pump display is so confusing.
  3. Delete the delay(250) and press once. The counter sprints, one press registered fifty times. Now you have seen why debouncing matters, put it back.

REMIX Make it yours

LOG IT Show and tell

Film your counter counting for your lesson log, this build earns bragging rights, it has more wires than everything before it combined. Stuck? Photo of your wiring to contact us.

Next · Lesson 08: Make Some Noise

Your machines can shine and show. Next lesson they get a voice: two kinds of buzzer, a siren, and a melody you program note by note.

All lessons