Tristan AlanizMatthew KobrickAmy BarnettDelaney SchultzJoanna WangYijie Huang
Published © GPL3+

Headcounter Machine

We designed a simple headcounter to provide a fast and easy way to keep track of a headcount to stay safe and organized!

IntermediateFull instructions provided1 hour248
Headcounter Machine

Things used in this project

Story

Read more

Schematics

Headcounter Circuit Diagram

Replicating this circuit diagram with the materials listed earlier and using the included software will allow you to build your own headcounter!

Code

HeadcounterEnergiaCode.ino

Arduino
Running this code on a finished circuit (built to the specifications of the circuit diagram) will result in a working headcounter.
/*
   Team Name: Frankenstein Squad Gang
   Project Name: Headcounter Machine
   Date: 11/04/2020

   Program for reading input from a button and incrementing the
   digit displayed on a seven segment display.
*/

// array containing the states for each segment of the display
// for each digit from 0 to 10
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 tiltPin = 18;       // the number of the tilt switch pin
const int buttonPin = 19;     // the number of the pushbutton pin
int currentInputState = 0;    // the current state of the input
int lastInputState;           // the last state of the input
int count = 0;                // the count that will be displayed

// modify the variable below to choose which mode (no tilt switch or
// tilt switch) the headcounter should operate in
// if it is set to 0, press the button repeatedly
// if it is set to 1, tilt the breadboard back and forth repeatedly
int mode = 1;                 // 0 = no tilt switch, 1 = tilt switch

// set up for pins and the initial state of the display
void setup() {
  pinMode(tiltPin, INPUT_PULLUP); // set the tilt switch as pull up input
  pinMode(buttonPin, INPUT_PULLUP); // set the button as pull up input
  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++) { // start with segments off
    digitalWrite(i, HIGH); // turn off each segment
  }
  digitalWrite(10, HIGH);  // start with the dot off
  Serial.begin(9600); // enable the serial monitor for debugging purposes
}

// check input, increment the count if necessary, and change the display
void loop() {
  // save the last button state in order to allow for the button to only
  // increment the count when it is pressed down, not while it is held
  lastInputState = currentInputState;
  
  // obtain the input value based on the input mode
  if (mode == 0) {
    currentInputState = digitalRead(buttonPin); // read the button state
  }
  else {
    delay(100); // delay for more clean input
    currentInputState = digitalRead(tiltPin); // read the tilt switch state
  }
  
  // if the last input state was HIGH (button not pressed) and the
  // current input state is LOW (button pressed), then the button
  // has been pressed down
  if (lastInputState == HIGH && currentInputState == LOW) {
    count++; // increment the count
  }
  
  // if the count exceeds 10 (which the display cannot show) reset it to 0
  if (count >= 10) {
    count = 0; // reset the count to 0
  }
  
  // print the count in the serial monitor for debugging purposes
  Serial.println(count);
  
  int pin = 3; // pin for the segment currently being changed
  // loop over each segment (from 0 to 7)
  for (int segCount = 0; segCount < 7; ++segCount) {
    // obtain the count and the current segment and use them
    // to obtain the value (0 or 1) from the array
    // that will be written to that segment for that count
    digitalWrite(pin, seven_segment_digits[count][segCount]);
    ++pin; // increment to the pin of the next segment
  }
}

Credits

Tristan Alaniz
1 project • 0 followers
Rice Computer Science Major
Contact
Matthew Kobrick
1 project • 0 followers
Contact
Amy Barnett
1 project • 0 followers
Contact
Delaney Schultz
1 project • 0 followers
Contact
Joanna Wang
1 project • 0 followers
Contact
Yijie Huang
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.