Samuel XuJacob FlynnKyle DerbabianMattie MeachamJanet LuAndrew Zhang
Published

It Counts

Offering all the wonders of two seven-segment displays in a package of one, keep track of game score in just a click™!

IntermediateFull instructions provided2 hours233
It Counts

Things used in this project

Hardware components

EK-TM4C123GXL TM4C Tiva LaunchPad
Texas Instruments EK-TM4C123GXL TM4C Tiva LaunchPad
×1
7 Segment LED Display, InfoVue
7 Segment LED Display, InfoVue
×2
Breadboard (generic)
Breadboard (generic)
×1
Male/Male Jumper Wires
Recommended to have a few dozen on hand
×44
Seeed Studio Sidekick Basic Kit for TI Launchpad
Only exclusive item would be the "Breadboard BoosterPack", not all Sidekick Basic Kits contain this component!
×1
Tilt Switch, SPST
Tilt Switch, SPST
A tilt switch used to reset the scoreboard
×1
TI Breadboard BoosterPack
Most likely can be found with the Sidekick Basic Kit
×1
PTS 645 Series Switch
C&K Switches PTS 645 Series Switch
Most likely also included with the Sidekick
×1

Software apps and online services

Energia
Texas Instruments Energia

Story

Read more

Code

Scoreboard

C/C++
Code for It Counts!
/*

  Team I: It Counts!

  Offering all the wonders of two seven-segment displays in a package of one, 
  keep track of game score in just a click™!
  
  Hardware Required:
  * TI LaunchPad
  * Breadboard
  * Breadboard BoosterPack
  * 44x Wire
  * 2x Seven-Segment Display
  * Tilt Switch
  * 2x Push Button

*/

// Define the LED digit patterns for 0 - 9 in a 2 dimensional array.
// The 2D array (an array of arrays or a matrix) has 10 arrays that each
// contain 7 values.
// Note that these patterns are for common cathode displays. For common
// anode displays, change the 1's to 0's and 0's to 1's
// 1 = LED on, 0 = LED off, in this order:
// Common Anode version
byte seven_segment_digits[10][7] = { { 0,0,0,0,0,0,1 }, // display '0'
                                     { 1,0,0,1,1,1,1 }, // display '1'
                                     { 0,0,1,0,0,1,0 }, // display '2'
                                     { 0,0,0,0,1,1,0 }, // display '3'
                                     { 1,0,0,1,1,0,0 }, // display '4'
                                     { 0,1,0,0,1,0,0 }, // display '5'
                                     { 0,1,0,0,0,0,0 }, // display '6'
                                     { 0,0,0,1,1,1,1 }, // display '7'
                                     { 0,0,0,0,0,0,0 }, // display '8'
                                     { 0,0,0,1,1,0,0 }  // display '9'
                                   };

// Common Cathode version
/* byte seven_segment_digits[10][7] = { { 1,1,1,1,1,1,0 }, // display '0'
                                     { 0,1,1,0,0,0,0 }, // display '1'
                                     { 1,1,0,1,1,0,1 }, // display '2'
                                     { 1,1,1,1,0,0,1 }, // display '3'
                                     { 0,1,1,0,0,1,1 }, // display '4'
                                     { 1,0,1,1,0,1,1 }, // display '5'
                                     { 1,0,1,1,1,1,1 }, // display '6'
                                     { 1,1,1,0,0,0,0 }, // display '7'
                                     { 1,1,1,1,1,1,1 }, // display '8'
                                     { 1,1,1,0,0,1,1 }  // display '9'
                                   };
*/

/* Connect the pins of the display accordingly.
Only one of the VCC (Common Anode) / GND (Common Cathode) pins need to be
connected to work, but it's ok to connect both if you want.
///////////////TOP//////////////
   pin 1 : G (9)  pin 10: A (3)
   pin 2 : F (8)  pin 9 : B (4)
   pin 3 : VCC    pin 8 : VCC
   pin 4 : E (7)  pin 7 : C (5)
   pin 5 : D (6)  pin 6 : Dot (10)
/////////////BOTTOM/////////////
*/

// Constants won't change. They're used here to set pin numbers:
const int buttonPin = PUSH1;        // the number of the first pushbutton pin
const int buttonPin2 = 19;          // the number of the second pushbutton pin
const int tiltSwitchPin = 2;        // the number of the tilt switch pin

// Variables will change:
int buttonState = 0;                // variable for reading the first push button status
int buttonState2 = 0;               // variable for reading the second push button status
int tiltSwitchState = 0;            // variable for reading the tilt switch status

// In the setup function, we set set up our pins.
void setup() {   
  
  // Initializes the push button pins as inputs
  pinMode(buttonPin, INPUT_PULLUP);     
  pinMode(buttonPin2, INPUT_PULLUP);

  // Initializes the tilt switch pins as input
  pinMode(tiltSwitchPin, INPUT_PULLUP); 

  // Initializes the first seven-segment display pins as outputs
  pinMode(3, OUTPUT); // set segment A1 as output
  pinMode(4, OUTPUT); // set segment B1 as output
  pinMode(5, OUTPUT); // set segment C1 as output
  pinMode(6, OUTPUT); // set segment D1 as output
  pinMode(7, OUTPUT); // set segment E1 as output
  pinMode(8, OUTPUT); // set segment F1 as output
  pinMode(9, OUTPUT); // set segment G1 as output
  pinMode(10, OUTPUT); // set dot1 as output

  // Initializes the second seven-segment display pins as outputs
  pinMode(18, OUTPUT); // set segment A2 as output
  pinMode(17, OUTPUT); // set segment B2 as output
  pinMode(16, OUTPUT); // set segment C2 as output
  pinMode(15, OUTPUT); // set segment D2 as output
  pinMode(14, OUTPUT); // set segment E2 as output
  pinMode(13, OUTPUT); // set segment F2 as output
  pinMode(12, OUTPUT); // set segment G2 as output
  pinMode(11, OUTPUT); // set dot2 as output

  // Starts with the first seven-segment display off
  for (int i = 3; i < 10; i++) { 
    digitalWrite(i, HIGH);
  }
  digitalWrite(10, HIGH);

  // Starts with the second seven-segment display off
  for (int i = 18; i > 11; i--) {
    if (i != 17){
      digitalWrite(i, HIGH);
    }
  }
  digitalWrite(11, HIGH);
  
}

/* In the loop section we will begin displaying the different numbers.
 * Add delay() or sleep() to give some time between the numbers changing.
 */

// Initializes the numbers that should be displayed on each of the segments
int count = 0;
int count2 = 0;
 
void loop() {
  
  // Reads the state of the push buttons
  buttonState = digitalRead(buttonPin);
  buttonState2 = digitalRead(buttonPin2);

  // Reads the state of the tilt switch
  tiltSwitchState = digitalRead(tiltSwitchPin);

  // Checks if the push buttons are pressed and adds to their respective counts if they are
  if (buttonState == LOW) {     
    count++;
  }
  if (buttonState2 == LOW) {     
    count2++;
  }

  // Checks if the tilt switch is activated and resets the counts if it is
  if (tiltSwitchState == 1) {
    count = 0;
    count2 = 0;
  }

  // Initializes the pins to be turned on
  int pin1 = 3;
  int pin2 = 18;

  // Loops through all the individual segments in the first seven-segment display
  for (int segCount = 0; segCount < 7; ++segCount) {

    // Reads the state of the tilt switch
    tiltSwitchState = digitalRead(tiltSwitchPin);

    // Checks if the tilt switch is activated and resets the counts if it is
    if (tiltSwitchState == 1) {
      count = 0;
      count2 = 0;
    }
    
    // Some pins were reserved, so we had to change them manually in code.
    if (pin2 == 16) {
      pin2 = 11;
    }
    if (pin2 == 17) {
      pin2 = 10;
    }

    // Turns on the segments according to the arrays above
    digitalWrite(pin1, seven_segment_digits[count % 10][segCount]);
    digitalWrite(pin2, seven_segment_digits[count2 % 10][segCount]);

    // Undoing reserved pin changes
    if (pin2 == 11) {
      pin2 = 16;
    }
    if (pin2 == 10) {
      pin2 = 17;
    }

    // Moves to the next pins
    ++pin1;
    --pin2;
    
  }
  
  delay(250);

}

Credits

Samuel Xu

Samuel Xu

2 projects • 5 followers
Jacob Flynn

Jacob Flynn

1 project • 4 followers
Kyle Derbabian

Kyle Derbabian

1 project • 4 followers
Mattie Meacham

Mattie Meacham

1 project • 4 followers
Janet Lu

Janet Lu

1 project • 4 followers
Andrew Zhang

Andrew Zhang

1 project • 0 followers
Thanks to Energia.

Comments