Demo entry 2742041

LCDdemo

   

Submitted by anonymous on Sep 24, 2015 at 09:38
Language: C++. Code size: 1.4 kB.

// used libraries: 
#include <LiquidCrystal.h>
#include "Streaming.h"

long unsigned int time;
long unsigned int start = 0;
long unsigned int days, hours, minutes, seconds;

// initialize the library with the numbers of the interface pins
// Pins numbers as per Leo's Lab Shield Product ID 101
// TODO: add link to product page 
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

// get a nice output time output like 00:00:00
String convert(unsigned int n){
  String converted;
  if (n < 10) {
    converted = "0" + String(n);  
  } else {
    converted = String(n);
  }
  return(converted);
}

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd << "Awake since:";
}

void loop() {
  long unsigned int updatetime;
  String separator1 = ":";
  String separator2 = " ";
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the formatted time since reset:
  time = (millis()/1000) + start;
  seconds = time % 60;
  minutes = time  / 60;
  hours = minutes / 60;
  days = hours / 24;
  hours = hours - days * 24;
  minutes = minutes - (hours + days * 24) * 60;

  lcd << convert(days) << " - " << convert(hours) << ":" << convert(minutes) << ":" << convert(seconds);
  
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).