Things used in this project

Hardware components:
SparkFun Force Sensitive Resistor 0.5"
×1
SparkFun Mini Pushbutton Switch
×1
A000066 iso both
Arduino Arduino UNO & Genuino UNO
×1
11441 01
SparkFun SparkFun 7-Segment Serial Display - Red
×1
SparkFun Mini Speaker - PC Mount 12mm 2.048kHz
×1
Software apps and online services:
8ztngd 9
circuito.io
Ide web
Arduino Arduino IDE

Code

Code for Chug MeterArduino
Replace the setup and loop functions from the code you got from circuito.io, with the code below
int start_flag = 0;
bool glassState = 0;
long finalTime, time0;
int timer;


/* This code sets up the essentials for your circuit to work. It runs first every time your circuit is powered with electricity. */
void setup() {
  // Setup Serial which is useful for debugging
  // Use the Serial Monitor to view printed messages
  Serial.begin(9600);
  Serial.println("start");

  pushButton.init();

  s7s.clearDisplay();  // Clears display, resets cursor
  s7s.setBrightness(255);  // High brightness
  s7s.setDecimals(0b00010000);  // Sets colon and apostrophe, see .cpp file for reference
  s7s.writeInt(0);
}

/* This code is the main logic of your circuit. It defines the interaction between the components you selected. After setup, it runs over and over again, in an eternal loop. */
void loop() {
  // Read FSR resistance value. try also fsr.getResistance()
  // For more information see Sparkfun website - www.sparkfun.com/products/9375
  // Note, the default Vcc and external resistor values for FSR calculations are 5V ang 3300Okm, if you are not
  //       using these default valuse in your circuit go to FSR.cpp and change default values in FSR constructor
  float fsrForce = fsr.getForce();
  //Serial.print(F("    Force: ")); Serial.print(fsrForce); Serial.println(F(" [g]"));


  //Read pushbutton state.
  //if button is not pushed function will return LOW (0). if it is pushed function will return HIGH (1).
  //if debounce is not working properly try changing 'debounceDelay' variable in Button.h
  //try also pushButton.onPress(), .onRelease() and .onChange() for debounce.
  bool pushButtonVal = pushButton.onPress();
  //Serial.print(F("Val: ")); Serial.println(pushButtonVal);


  //Reset the time using the push-button
  if (pushButtonVal == 1) {
    start_flag = 0;
    glassState = 0;
    //Start timer
    s7s.writeInt(0);
    time0 = millis();
  }

  //set time state
  if (start_flag == 0) {
    //If the galss is placed
    if (fsrForce > 50)
    {
      glassState = 1;
      //Start timer
      s7s.writeInt(0);
      time0 = millis();
    }

    //If the glass was picked up
    else if (fsrForce < 50 && glassState)
    {
      finalTime = millis() - time0;
      start_flag = 1;
    }
  }
  //the glass was picked, run the timer
  else if (start_flag == 1)
  {
    //while you are drinking, display the time on the 7-Seg display
    if (fsrForce < 100)
    {
      finalTime = (millis() - time0) / 10;
      s7s.writeInt(finalTime);
    }

    //Finish drinking, stop timer, print final time, and play hooray sound
    else
    {
      start_flag = 2;
      finalTime = (millis() - time0) / 10;
      s7s.writeInt(finalTime);
      piezoSpeaker.playMelody(piezoSpeakerHoorayLength, piezoSpeakerHoorayMelody, piezoSpeakerHoorayNoteDurations);
      delay(500);
    }
  }

  //always print final time until reset button is pushed
  else
  {
    s7s.writeInt(finalTime);
  }

}

Credits

Jzbvk4go5lw68vtvbfe4
circuito.io team

Circuito.io is an online platform that generates wiring and code for Arduino projects. Want to know more? Visit http://circuito.io

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Using CA and CC RGB LED by Current Sourcing and Sinking!
Easy
  • 352
  • 23

Protip

RGB LEDs are of two types, common cathode and common anode which behave differently with same Arduino code; how to resolve this.

Arduino Amiga Floppy Disk Reader
Easy
  • 2,242
  • 5

Work in progress

An Arduino powered floppy disk controller and reader for making disk images from old AmigaDOS floppy disks.

Quadrature Encoder Demo
Easy
  • 15
  • 1

Full instructions

Use a 3D printed encoder wheel, LED, and 2 photocells to demonstrate how a quadrature encoder works.

Micro:bit Moisture sensor
Easy
  • 158
  • 4

Protip

In this quick and easy project, you build a micro:bit moisture sensor

3D-Printed, Internet-Controlled, Self-Balancing FPV Robot
Easy
  • 1,612
  • 22

Full instructions

Open source telepresence robot that keeps its balance on two wheels. Controlled from UI in the web browser.

Arduino Controlled USB Trackpad
Easy
  • 2,598
  • 4

Full instructions

I really want to make a Raspberry Pi laptop but just can't find the right size trackpad so in this project we will be salvaging an old one.

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login