NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Project Help and Ideas » Work time tracking clock

February 28, 2015
by scootergarrett
scootergarrett's Avatar

I've always thought it would be need to track the time I spend at work on different tasks, and I figured I could make a simple timer with some selection buttons and a screen that shows how many minutes I have spent on each task. Its basically a glorified chess clock. So I have 6 things I could be working on an it adds time based on the last button I hit, so if I was change task I would just hit the button corresponding to the new task and it would start adding time to that. The part I like is the screen which only uses three lines scrolls through all six tasks with the total time shown. I made it on a 324p just because I had a lot of buttons already plugged in.

Code:

#define TimeCategories 6
#define SecondsPerMinute 60

#define TestOut A,0
#define TestOutButtonPress A,1

volatile uint16_t TimeCategorysMinutes[TimeCategories] = {0};
volatile uint8_t SecondCount;
volatile uint8_t TimeCategorySelected;

int main()
{
    FILE lcd_stream;
    char TimeCategorysNames[TimeCategories][32] = {"EMAIL" , "MEETINGS", "OTHER", "DESIGN", "PROJECT 1", "PROJECT 2"};
    uint8_t k, j, StartPosition;

    // Initialize variables //
    SecondCount = 0;
    TimeCategorySelected = 0;
    // Set up outputs //
    OUTPUT(TestOut);            CLEAR(TestOut);
    OUTPUT(TestOutButtonPress);      CLEAR(TestOutButtonPress);
    // set up inputs all port C is inputs //
    DDRC = 0;
    PORTC = 0xFF;

    // Start the LCD screen //
    lcd_init();
    fdev_setup_stream(&lcd_stream, lcd_putchar, 0, _FDEV_SETUP_WRITE);
    lcd_clear_and_home();

    // Set up PORTC for pin change interrupts //
    PCICR |= (1<<PCIE2);
    PCMSK2 |= (1<<PCINT16) | (1<<PCINT17) | (1<<PCINT18) | (1<<PCINT19) | (1<<PCINT20) | (1<<PCINT21) | (1<<PCINT22) | (1<<PCINT23);

    // Interrupt Timing setup //
    TCCR1B |= (1<<CS12) | (1<<CS10) | (1<<WGM12);
    TIMSK1 |= (1<<OCIE1A);
    OCR1A = 14400;                 // Interrupt timing 1 Hz

    sei();          // Enable interrupts

    // Just prints info to screen in scrolling fashion //
    while(1)
    {
        for(StartPosition = 0; StartPosition<TimeCategories ; ++StartPosition)
        {
            lcd_line_one();
            fprintf_P(&lcd_stream, PSTR("                    "));
            lcd_line_one();
            fprintf_P(&lcd_stream, PSTR("Task:%s"), TimeCategorysNames[TimeCategorySelected]);

            for(k=1, j = StartPosition;k<4;++k, ++j)
            {
                lcd_goto_position(k, 0);
                fprintf_P(&lcd_stream, PSTR("                    "));
                lcd_goto_position(k, 0);

                if(j==TimeCategories)
                    j=0;

                fprintf_P(&lcd_stream, PSTR("%s"), TimeCategorysNames[j]);
                lcd_goto_position(k, 15);
                fprintf_P(&lcd_stream, PSTR("%i"), TimeCategorysMinutes[j]);
            }

            delay_ms(1000);
        }
    }

    return 0;
}

/// Interrupt code ///
ISR(TIMER1_COMPA_vect)
{
    // Interrupt code ...
    TOGGLE(TestOut);

    SecondCount ++;

    if(SecondCount == SecondsPerMinute)
    {
        ++TimeCategorysMinutes[TimeCategorySelected];
        SecondCount = 0;
    }

    return;
}

/// Interrupt code ///
ISR(PCINT2_vect)
{
    // Interrupt code ...
    TOGGLE(TestOutButtonPress);

    // Figure out what button is pressed and assign 'TimeCategorySelected' //
    switch(PINC^0xFF)
    {
    case 1:
        {
            TimeCategorySelected = 0;
            break;
        }
    case 2:
        {
            TimeCategorySelected = 1;
            break;
        }
    case 4:
        {
            TimeCategorySelected = 2;
            break;
        }
    case 8:
        {
            TimeCategorySelected = 3;
            break;
        }
    case 16:
        {
            TimeCategorySelected = 4;
            break;
        }
    case 32:
        {
            TimeCategorySelected = 5;
            break;
        }
    default:
        {
            break;
        }
    }

    return;
}

Circuit lab schematic Circuit diagram:

CD

Picture (there is some other stuff going on in the background just ignore that):

PIC

February 28, 2015
by Noter
Noter's Avatar

I wonder why your posted pictures don't scale? Can't get any of this to fit on my screen. Plus have to scroll horizontally to read the text. I probably won't follow this thread much just because it's a pain to view.

February 28, 2015
by Noter
Noter's Avatar

What? After I posted the comment above and the page refreshed with my post, suddenly every thing scaled and it's ok now. Never mind.

February 28, 2015
by JKITSON
JKITSON's Avatar

I had the same problem. Found if I right click on the page then select REFRESH every thing seems to be ok....

Nice project & write up.

Jim

February 28, 2015
by JKITSON
JKITSON's Avatar

I said REFRESH & menu choice is RELOAD. Sorry Jim

February 28, 2015
by Noter
Noter's Avatar

Thanks Jim, I'll try that next time.

Fun project but seems like a cell phone app would be better for tracking time.

March 01, 2015
by JKITSON
JKITSON's Avatar

Cell phone app probably would be better except... I don't have & cannot afford the smart phones. Besides taking an idea and making it work with things on your table top is fantastic. I watch the way most of you are able to program and make things work, where I seem to have to take years to do one project.

Thanks again guys for neat info...

Jim

March 02, 2015
by Ralphxyz
Ralphxyz's Avatar

I do not use a cell phone either.

I just do not need one.

March 02, 2015
by JKITSON
JKITSON's Avatar

I have made my living for 50+ years in computers. I swore I would never have a cell phone.

After being at a few Tractor Shows & need to call a friend & no pay phones anymore... I went with NET10 $15 per month for 200 min. I now have 1981 min in excess avail. It is nice to have when traveling. I do not give the # out, so others don't use my min.

March 02, 2015
by scootergarrett
scootergarrett's Avatar

I don't know why the picture didn't scale correctly at first. I known when I was previewing it looked wrong but I know that it scales pictures. I used to just have links to pictures to make the post more concise, but I think it looks better with pictures assuming is scales.

The cell phone app might be better but I don’t think my boss wants to see cell phones out all day. Not to mention I also don’t own a cell phone (which is risky with a car like mine). But I do want to get into the Android apps stuff in the other thread so I’m looking into getting a used Android phone with no service to test out apps and Bluetooth to nerdkits communication.

March 02, 2015
by Noter
Noter's Avatar

A smart phone is just a (very personal) computer with a cell phone built in. I've only had mine for a couple of years and I love it, not because of the cell phone but for the computer part of it. It's reminds me several times a day to take my pills which I used to forget on a regular basis but now I'm on track. The calendar is also quite useful to keep me from missing important appointments. Then I found the health apps like Samsung Health which I have been using for months now to track my caloric intake real time and have lost 45 lbs now. That alone is probably saving my life in terms of better health and greater longevity. Not to mention all the fun stuff I use in my avr projects. And the list goes on with built in GPS, maps, and all kinds of neat stuff at my fingertips all the time.

A couple of years ago I couldn't imagine wanting or needing such a thing but now I'm hooked. All because my niece came for a visit, showed me her smart phone, and then took me to the verizon store. Geesh, I must be and old geezer. - lol

Post a Reply

Please log in to post a reply.

Did you know that NerdKits has been featured on Slashdot, Hack A Day, Hacked Gadgets, the MAKE blog, and other DIY-oriented websites? Learn more...