View Single Post
Old 10-03-2010, 08:12 AM   #3 (permalink)
EcoModding Lurker
FalconFour's Avatar
Join Date: Sep 2010
Location: Fresno, CA
Posts: 78

LEAF - '11 Nissan LEAF
Thanks: 4
Thanked 9 Times in 7 Posts
And a fun one, if at least to see how far the MPGuino's interrupt-generated clock differs from reality (if "1.024 milliseconds, we will call that a millisecond for our purposes" is any indicator )... a clock.

It's not complete. The "values editor" has to first be created here in order to set the time on the clock. But it does count time, and it seems to be working, so I'll provide that here as a starting point, and to get some feedback (particularly on if there's anything I can do to clean up all the mBuff parameters)...

First, a new function, char * clock():
char * clock() {
  unsigned int clockDelta = tank.loopCount / loopsPerSecond;
  // if over 24 hours, remove 1 day. will occur after running for more than 24 hours.
  while (clockDelta > 86400) clockDelta -= 86400;
  unsigned int clock = (clockBase + clockDelta);
  // if we then add the clock base and it's over 11:59pm, wrap around to midnight.
  // will occur once a day and will reset when the clockDelta check above catches it.
  if (clock > 86400) clock -= 86400;
  unsigned int clockSeconds = (clock % 60);
  // will still be seconds so divide later
  unsigned int clockMinutes = (clock - clockSeconds) % 3600;
  unsigned int clockHours = (clock - clockMinutes - clockSeconds) / 3600;
  // divide to get minutes from mod seconds
  clockMinutes /= 60;
  boolean clockAmPm = false;
  if (clockHours > 12) {
    clockHours -= 12;
    clockAmPm = true;
  if (clockHours == 0) clockHours = 12;
  return mBuff;
So, add that code above somewhere, I added it below instantgph() and above the Trip functions.

Then, a way to display it. Basically just call LCD:rint(clock()) anywhere. I added a new menu for it. Take the construct above and replace the blank line print with:
  LCD::print("Time: ");
Then bam, you get a clock starting at 12am. Happiness!

Attached is a photo of my work thus far
Attached Thumbnails
Click image for larger version

Name:	20101003034408.jpg
Views:	131
Size:	102.7 KB
ID:	6975  

Last edited by FalconFour; 10-04-2010 at 10:11 AM.. Reason: Corrected bugs that would result in after-13pm oddities after 24 hours
  Reply With Quote