Tally Counter
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Tally Counter

by BindMlown on Sat May 11, 2013 8:52 pm

To make this https://www.youtube.com/watch?v=wfHCKhXEM6Y I would need
this 7 Segment LED Display correct?

Everything else I would need comes with the Experimenter's Start Kit, right?

Here is the diagram

Obligatory shout out http://missionduke.com/wordpress/arduino-projects/

Here is the sketch code. Will I need to modify it for use with the Adafruit display?
Code: Select all | TOGGLE FULL SIZE
#include <SoftwareSerial.h>  //for software serial communication

#define txPin 14  //change to your serial port on Arduino board
#define rxPin 15  //not used but is required

SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);
int buttonPressCount;

const int  buttonPin = 2;    //the pin that the pushbutton is attached to

int buttonPushCounter = 0;   //counter for the number of button presses
int buttonState = 0;         //current state of the button
int lastButtonState = 0;     //previous state of the button

void setup()  {
  pinMode(buttonPin, INPUT);  //initialize the button pin as a input
  Serial.begin(9600);  //initialize serial communication

 pinMode(txPin, OUTPUT);
 //the following resets the board, changes the brightness to 100%, and sets the board to '0000':
 mySerial.print(0x7A,BYTE); //special character
 mySerial.print(0x00,BYTE); //set brightness to full
 mySerial.print(0x76,BYTE); //reset board
 mySerial.print(0); //send '0' character
 mySerial.print(0); //send '0' character
 mySerial.print(0); //send '0' character
 mySerial.print(0); //send '0' character

void loop(){
  buttonState = digitalRead(buttonPin);  //read the pushbutton input pin

  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == HIGH) {
      // if the current state is HIGH then the button
      // went from off to on:
      Serial.print("number of button pushes:  ");
      Serial.println(buttonPushCounter, DEC);
      updateDisplay(buttonPushCounter);  //function to update the display 'requires button press count'

  lastButtonState = buttonState;  // save the current state as the last state, for next time through the loop



void updateDisplay(int buttonPushCounter){
String intString = String(buttonPushCounter);  //changes integer to a string
char displayChars[4];  //create array to hold the four numbers
int stringLength = intString.length();  //get length of the string
//the following will determine if the button press count variable has 1, 2, 3, or 4 numbers in it
//and will fill the empty spaces with '0'. so if the button press count variable is '29' it will end up being '0029':
if(stringLength == 4){
  displayChars[0] = intString.charAt(0);
  displayChars[1] = intString.charAt(1);
  displayChars[2] = intString.charAt(2);
  displayChars[3] = intString.charAt(3);
}else if(stringLength == 3){
  displayChars[0] = 0;
  displayChars[1] = intString.charAt(0);
  displayChars[2] = intString.charAt(1);
  displayChars[3] = intString.charAt(2);
}else if(stringLength == 2){
  displayChars[0] = 0;
  displayChars[1] = 0;
  displayChars[2] = intString.charAt(0);
  displayChars[3] = intString.charAt(1);
}else if(stringLength == 1){
  displayChars[0] = 0;
  displayChars[1] = 0;
  displayChars[2] = 0;
  displayChars[3] = intString.charAt(0);
 mySerial.print(0x76,BYTE); //Reset board
 mySerial.print(0x76,BYTE); //Reset board
 mySerial.print(displayChars[0]); //Send '0' character
 mySerial.print(displayChars[1]); //Send '0' character
 mySerial.print(displayChars[2]); //Send '0' character
 mySerial.print(displayChars[3]); //Send '0' character

delay(100); //this will make it so you don't get double counts. you could also use this to avoid someone pressing the button repeatedly 'for fun!'

I have no idea what I'm doing.
Posts: 2
Joined: Fri Apr 26, 2013 9:19 pm

Re: Tally Counter

by adafruit_support_mike on Sat May 11, 2013 10:59 pm

Yeah, that display should make it easy to build an event counter. The code will be slightly different.. the backpack uses a library that we wrote to handle communication with the chip, but from the high-level code it will still be "print( number, DEC )".

The tutorial page for that display should get you going: http://learn.adafruit.com/adafruit-led- ... t-backpack

And yes, the Experimentation Kit does come with a couple of pushbutton switches and some 10k resistors.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.

Posts: 16894
Joined: Thu Feb 11, 2010 2:51 pm

Please be positive and constructive with your questions and comments.