Evan Alexander 

Calorie Counter

A photo of a calorie counting device. The shot is angled down at a 35 degree angle. The device is ontop of a whiteboard table and lit from all sides.

A photo of a calorie counting device. The shot is angled down at a 35 degree angle. The device is on top of a whiteboard table and lit from all sides.

Description:

This is a device that simply calculates macro-nutrients and converts them into a caloric value. A single rotary encoder with a button changes states of the device from editing the values to selecting them. A button on the right sets the goal for each value I would like to reach.

A angled shot of the device. The shot is in front of the device to it's right looking down.

A photo of a calorie counting device. The shot is angled down at a 75 degree angle to the left of the device. Once can read the labels on the top of the device: Calories, Proteins, Fats and Carbs in descending order. A on or off switch is in the bottom left corner of the lid in this view.

A front shot of the device. It shows the text on the center screen. The rotary dial and the text wrapping around it stating: "Click to Select. Turn to Change". A red button is on the right with an engraving underneath that states: "Goal-Set".

A picture from an angle with the lid detached from the shell. There are some wires showing from inside.

IMG_5493.MOV

In this video, I show operation of the device. I press the rotary button twice to enter calorie edit mode turn the dial to the right to add some calories. Then I hold the button down to confirm my selection which takes me back to the main menu.

Process

First steps into project. Bunch of text written out on a whiteboard table with the Arduino just being tested.

More wiring work being done. Hardware is being tested / coming together.

Finished laser cutting all pieces for the shell of the device. The shell is made of wood and in a pile. One lone Arduino stands victorious.

Hardware is being placed onto fabricated pieces. Wires strewn about to the left of the image. LCD Testing happening to the right of the image.

A close up with almost all pieces glued together. Hot glue was used to adhere pieces together. No electronics are on the inside of the box yet.

All wires and hardware is attached / inside the box. This was the final test before putting the lid on and a battery on the inside of the device.

3. Discussion

(instructions are embedded below)

Discussion

This was a difficult project. Not because it was a hard problem or device to make, it was difficult because I did not believe in my ability's. It was a mixture of self doubt, and disinterest. During Ideation, I experienced difficulties coming up with a project idea that was interesting to me. I would have rather used someone else's design and modified it to make it my own. I would build it from scratch, just with some guide lines. These thoughts and doubts led to me procrastination, till I had only 3 days to whip something up. I did and I'm shocked with how it turned out.

Compared to the first project, I had a clear difficulties keeping myself in check. Having a partner helps demystify and problem solve. Coming into the lab helped simulate that same experience as everyone during the final two days was bouncing ideas / solutions to problems. It was a nice sight to see.

In the end, I was happy others liked the design of my device. I had some complaints about the position of the screen / how one holds the box while interacting with it. I would have changed the screen to angle up at a 45 degree so the user would not have to crouch to see the screen if it were on a table. I would like to have the macro nutrient conversions working as well, as it is only a calorie tracker in it's current form. A SD card for keeping track of information logged in the past would also be useful.


Technical information

Code:

#include <EasyButton.h>

#include <EasyButtonBase.h>

#include <EasyButtonTouch.h>

#include <EasyButtonVirtual.h>

#include <Sequence.h>


#include <Encoder.h>


#include <LiquidCrystal_I2C.h>


//Title: Calorie Counter

//By: Evan Alexander


///Description///


//This block of code operates two devices. A 2x16 LCD and a Rotary encoder and a Arduino Uno.

//On a high level this runs a main function to display your 3 macros (proteins, fats, carbs)

//and a caloric value.


//Credits//


//The "EasyButton" library was used heavily in this project. Check them out at: https://easybtn.earias.me/

//The "Encoder" library was used for seamless use. Library found at: https://www.pjrc.com/teensy/td_libs_Encoder.html

//The "LiquidCrystal_I2C" library was used to access the liquid crystal display: https://github.com/johnrickman/LiquidCrystal_I2C


//Pin Mapping//

// SCL and SDA plug into the Pack of the LCD Display

// 2 ~3 and 4 all are used for the rotary encoder.


//Code released to the public domain by the author: 3/20/24


//Deffined Global Variables:


Encoder myEnc(2, 3);

LiquidCrystal_I2C screen(0x27, 16, 2);

unsigned long tickTimer = 0;

const int tickWait = 200;


long Calories;

long Protein;

long Fats;

long Carbs;


long additionNumber;


#define BUTTONPIN 4

EasyButton encoderButton(BUTTONPIN);


void setup() {

  Serial.begin(9600);

  Serial.println("Start");


  //Screen Initialization

  screen.init();

  screen.display();

  screen.backlight();

  screen.home();

}


//Number Declairations

long oldPosition = -999;


void loop() {

  Main();

  encoderButton.read();

  DubblePressToCalorieChange();

}


void Main() {

  //Positioning of encoder. If this was not here

  //It would take one noch on the encoder as 4 isntead of one.

  long newPosition = myEnc.read() / 4;

  if (newPosition != oldPosition) {

    oldPosition = newPosition;

    Serial.println(newPosition);

  }


  //Section: Display function:

  if ((millis() - tickTimer) >= tickWait) {

    screen.clear();

    //Display Calories

    screen.setCursor(4, 0);

    screen.print("Cal:");

    screen.setCursor(10, 0);

    screen.print(Calories);



    //Display Protein

    screen.setCursor(0, 1);

    screen.print("P:");

    screen.setCursor(2, 1);

    screen.print(Protein);

    //Display Fats

    screen.setCursor(5, 1);

    screen.print("F:");

    screen.setCursor(7, 1);

    screen.print(Protein);

    //Display Carbs

    screen.setCursor(10, 1);

    screen.print("C:");

    screen.setCursor(12, 1);

    screen.print(Protein);


    tickTimer = millis();

  }

}


void DubblePressToCalorieChange() {

  //Changes state from the main to ChangeCal()

  encoderButton.onSequence(2, 1000, ChangeCal);

}


void ChangeCal() {

  bool stayInState = false;

  Serial.println("!!!!I have changed states!!!!");

  do {

    encoderButton.read();

    Serial.println("I'm staying in this state!");

    stayInState = encoderButton.pressedFor(1000);


    //EncoderMovement

    long newPosition = myEnc.read() / 4;

    if (newPosition != oldPosition) {

      oldPosition = newPosition;

      additionNumber = newPosition;

      Serial.println(newPosition);

    }


    //Display calories

    if ((millis() - tickTimer) >= tickWait) {

      screen.clear();

      //Display Calories

      screen.setCursor(1, 0);

      screen.print("Change Cal:");

      screen.setCursor(13, 0);

      screen.print(Calories);


      screen.setCursor(7, 1);

      screen.print(newPosition);


      tickTimer = millis();

    }



  } while (stayInState == false);


  Calories = (Calories + additionNumber);

  screen.println("added Number");

}