Mark Kessler
Published © LGPL

Button Mashing Counter

Have your friends ever gotten mad and accused you for button mashing at Super Smash Bros? Well now your name is cleared!

BeginnerWork in progress1 hour19
Button Mashing Counter

Things used in this project

Hardware components

Breadboard (generic)
Breadboard (generic)
×1
EK-TM4C123GXL TM4C Tiva LaunchPad
Texas Instruments EK-TM4C123GXL TM4C Tiva LaunchPad
×1
Jumper wires (generic)
Jumper wires (generic)
×1
7 Segment LED Display, InfoVue
7 Segment LED Display, InfoVue
×1
TI Breadboard BoosterPack
×1
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×1
Tilt Switch, SPST
Tilt Switch, SPST
×1

Software apps and online services

Texas Instruments TI Energia

Story

Read more

Schematics

sidekickexample10-bb_bb_cQ9RfaKxnA.png

tilt switch and button wiring

demo

Code

My Code :D

C/C++
// Initialize pins and data
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'
                                   };

const int buttonPin = 19;
const int tilt = 17;
int breadboardButtonState = 1;
int tiltstate = 1;
int start_num = 0;


// Setup pins for 7 segment display and set to display '0'
void setup() {

  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(tilt, INPUT_PULLUP);

  pinMode(3, OUTPUT); // set segment A as output
  pinMode(4, 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 dot as output
  for(int i = 3; i < 10; i++) { 
    if(i==9){
      digitalWrite(i,HIGH);
    }
    else{
    digitalWrite(i, LOW);
    }
  }
  digitalWrite(10, HIGH);  // start with the dot off
}


 
void loop() {

  
  tiltstate = digitalRead(tilt);

  //manage whether button can be pressed to add or not
  if(tiltstate==0){
    breadboardButtonState = 1;
  }
  else{
    breadboardButtonState = digitalRead(buttonPin);
   }
  
  //display next number
  if(breadboardButtonState == 0){
    start_num = start_num + 1;
    start_num = start_num % 10;
    int pin =3;
    for(int i = 0; i<7 ;i++){
      
      digitalWrite(pin, seven_segment_digits[start_num-1][i]);
      pin++;
      }
    }
  
 
delay(130); //Best delay for button mashing
}

Credits

Mark Kessler

Mark Kessler

0 projects • 0 followers

Comments

Add projectSign up / Login