Max Cunninghamachang24Chuk Uzowihe
Published

Button + 7 Segment Display

Count button clicks with a 7 segment display

IntermediateFull instructions provided10 hours720
Button + 7 Segment Display

Things used in this project

Hardware components

EK-TM4C123GXL TM4C Tiva LaunchPad
Texas Instruments EK-TM4C123GXL TM4C Tiva LaunchPad
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×14
7 Segment LED Display, InfoVue
7 Segment LED Display, InfoVue
×1
Texas Instruments Breadboard BoosterPack
×1
Texas Instruments Push Button
×1

Software apps and online services

Energia
Texas Instruments Energia

Story

Read more

Schematics

Circuit Schematic

Code

button counter + tilt switch

C/C++
implements button and tilt switch
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'
                                   };
// button states                                  
int current_button_state;
int previous_button_state = 0;
// counter that increments when the button is pressed
int counter = 0;
// tilt switch state
int tilt_switch;

void setup() {
  pinMode(17, INPUT); // set tilt switch as input
  pinMode(15, INPUT_PULLUP); // set button as input
  pinMode(2, OUTPUT); // set dot as output
  pinMode(3, OUTPUT); // set segment B as output
  pinMode(5, OUTPUT); // set segment C as output
  pinMode(6, OUTPUT); // set segment D as output
  pinMode(7, OUTPUT); // set segment E as output
  pinMode(8, OUTPUT); // set segment F as output
  pinMode(9, OUTPUT); // set segment G as output
  pinMode(10, OUTPUT); // set segment A as output
  for(int i = 2; i < 11; i++) { // start with segments and dot off
    digitalWrite(i, HIGH);
  }
}

/* In the loop section we will begin displaying the different numbers.
 * Add delay() or sleep() to give some time between the numbers changing.
 */
void loop() {
  // get the current state of the button
  current_button_state = digitalRead(15);
  // if button is pressed (state is on and last state is off)
  // then increment counter to display the next number
  if (current_button_state == LOW && previous_button_state == HIGH)
  {
    counter++;
  }
  // previous button state becomes the most recent state
  previous_button_state = current_button_state;
  // get the current state of the tilt switch
  tilt_switch = digitalRead(17);
  // if tilt switch is on then turn dot on
  if (tilt_switch == HIGH)
  {
    digitalWrite(2, LOW);
  }
  // if tilt switch is off then turn dot off
  else
  {
    digitalWrite(2, HIGH);
  }
  // pins corresponding to segments A,B,C,D,E,F,G in order
  int pins[7] = {10, 3, 5, 6, 7, 8, 9};
  // go through pins and turn corresponding segments on to display number
  for (int segCount = 0; segCount < 7; segCount++)
  {
    digitalWrite(pins[segCount], seven_segment_digits[counter%10][segCount]);
  }
}

Credits

Max Cunningham
1 project • 0 followers
Contact
achang24
1 project • 2 followers
Contact
Chuk Uzowihe
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.