[SOLVED] Trying to combine large font and time with no RTC
as title states, i'm trying combine large numbers font made hifiduino (https://downloadcode.wordpress.com/page/1/) , crossroads clock gets time set buttons , not rely on rtc module. complete noob when comes this, have read as can figure out , have hit wall. figure out i'm doing wrong have gratitude.
code: [select]
[code]
/*
set of custom made large numbers 16x2 lcd using the
liquidcrystal librabry. works displays compatible the
hitachi hd44780 driver.
cuicuit:
lcd rs pin d12
lcd enable pin d10
lcd d4 pin d5
lcd d5 pin d4
lcd d6 pin d3
lcd d7 pin d2
lcd vee tied pot control brightness
lcd vss , r/w tied ground
lcd vcc +5v
made michael pilcher
2/9/2010
*/
// include library
#include <liquidcrystal.h>
#include <time.h>
#include <timelib.h>
// initialize interface pins
liquidcrystal lcd(12, 10, 5, 4, 3, 2);
const int backlight = 13;
const int buttonhr = 7; //digital pin used hour adjustment input
const int buttonmin = 8; //digital pin used min adjustment input
int secs = 0;
int secs2 = 0;
int mins = -1;
int hrs = 0;
int millidivsecs = 1000;
int millidivmins = 60000;
int millidivhrs = 360000;
unsigned long prevmillis = 0;
int interval = 1000;
int x = 0;
pinmode(backlight, output);
pinmode(buttonhr, input);
pinmode(buttonmin, input);
digitalwrite(backlight, high);
lcd.begin(16, 2); //set number of cols , rows
//print out lcd clock duisplay
lcd.setcursor(5, 0);
lcd.print("12:00:00 am");
serial.begin(9600);
}
// 8 arrays form each segment of custom numbers
byte lt[8] =
{
b00111,
b01111,
b11111,
b11111,
b11111,
b11111,
b11111,
b11111
};
byte ub[8] =
{
b11111,
b11111,
b11111,
b00000,
b00000,
b00000,
b00000,
b00000
};
byte rt[8] =
{
b11100,
b11110,
b11111,
b11111,
b11111,
b11111,
b11111,
b11111
};
byte ll[8] =
{
b11111,
b11111,
b11111,
b11111,
b11111,
b11111,
b01111,
b00111
};
byte lb[8] =
{
b00000,
b00000,
b00000,
b00000,
b00000,
b11111,
b11111,
b11111
};
byte lr[8] =
{
b11111,
b11111,
b11111,
b11111,
b11111,
b11111,
b11110,
b11100
};
byte umb[8] =
{
b11111,
b11111,
b11111,
b00000,
b00000,
b00000,
b11111,
b11111
};
byte lmb[8] =
{
b11111,
b00000,
b00000,
b00000,
b00000,
b11111,
b11111,
b11111
};
void setup()
{
// assignes each segment write number
lcd.createchar(8, lt);
lcd.createchar(1, ub);
lcd.createchar(2, rt);
lcd.createchar(3, ll);
lcd.createchar(4, lb);
lcd.createchar(5, lr);
lcd.createchar(6, umb);
lcd.createchar(7, lmb);
// sets lcd's rows , colums:
lcd.begin(0, 2);
}
void custom0o()
{ // uses segments build number 0
lcd.setcursor(x, 0);
lcd.write(8);
lcd.write(1);
lcd.write(2);
lcd.setcursor(x, 1);
lcd.write(3);
lcd.write(4);
lcd.write(5);
}
void custom1()
{
lcd.setcursor(x, 0);
lcd.write(1);
lcd.write(2);
lcd.setcursor(x + 1, 1);
lcd.write(255);
}
void custom2()
{
lcd.setcursor(x, 0);
lcd.write(6);
lcd.write(6);
lcd.write(2);
lcd.setcursor(x, 1);
lcd.write(3);
lcd.write(7);
lcd.write(7);
}
void custom3()
{
lcd.setcursor(x, 0);
lcd.write(6);
lcd.write(6);
lcd.write(2);
lcd.setcursor(x, 1);
lcd.write(7);
lcd.write(7);
lcd.write(5);
}
void custom4()
{
lcd.setcursor(x, 0);
lcd.write(3);
lcd.write(4);
lcd.write(2);
lcd.setcursor(x + 2, 1);
lcd.write(255);
}
void custom5()
{
lcd.setcursor(x, 0);
lcd.write(255);
lcd.write(6);
lcd.write(6);
lcd.setcursor(x, 1);
lcd.write(7);
lcd.write(7);
lcd.write(5);
}
void custom6()
{
lcd.setcursor(x, 0);
lcd.write(8);
lcd.write(6);
lcd.write(6);
lcd.setcursor(x, 1);
lcd.write(3);
lcd.write(7);
lcd.write(5);
}
void custom7()
{
lcd.setcursor(x, 0);
lcd.write(1);
lcd.write(1);
lcd.write(2);
lcd.setcursor(x + 1, 1);
lcd.write(8);
}
void custom8()
{
lcd.setcursor(x, 0);
lcd.write(8);
lcd.write(6);
lcd.write(2);
lcd.setcursor(x, 1);
lcd.write(3);
lcd.write(7);
lcd.write(5);
}
void custom9()
{
lcd.setcursor(x, 0);
lcd.write(8);
lcd.write(6);
lcd.write(2);
lcd.setcursor(x + 2, 1);
lcd.write(255);
}
void loop() {
unsigned long currmillis = millis();
//detect button pressing
if (digitalread(buttonhr) == high) {
delay(25);
hrs = hrs + 1;
updatehrs();
//update ampm on button press
if (hrs == 12) {
updateampm();
}
delay(400);
}
if (digitalread(buttonmin) == high) {
delay(25);
mins = mins + 1;
//serial.println(mins);
updatemin();
delay(400);
}
if (currmillis - prevmillis > 999) {
//lcd.clear();
prevmillis = currmillis;
if (secs < 10) {
lcd.setcursor(12, 0);
lcd.print(secs);
lcd.setcursor(11, 0);
lcd.print(0);
}
else {
lcd.setcursor(11, 0);
lcd.print(secs);
}
//display minutes
if (secs == 0) {
mins = mins + 1;
updatemin();
}
//get new seconds system time
secs = (millis() / millidivsecs) % 60; // divide 1000 , mod 60 gives seconds milliseconds
}
}
//update min function
//calls update apm funciton , update hours functions.
void updatemin() {
if (mins > 59) {
hrs = hrs + 1;
updatehrs(); //update hours then
if (hrs == 11 && mins > 59) {
updateampm();
}
mins = 0; //reset mins
lcd.setcursor(8, 0);
lcd.print("00");
}
if (mins < 10) {
lcd.setcursor(9, 0);
}
else {
lcd.setcursor(8, 0);
}
lcd.print(mins);
}
//update hour function
void updatehrs() {
//display hours - needs fixing pm
if (hrs > 12) {
//reset 1
hrs = 1;
}
if (hrs < 10) {
lcd.setcursor(5, 0);
lcd.print(" ");
lcd.setcursor(6, 0);
}
else {
lcd.setcursor(5, 0);
}
lcd.print(hrs);
}
void updateampm() {
if (isam) {
isam = false;
lcd.setcursor(14, 0);
lcd.print("pm");
}
else {
isam = true;
lcd.setcursor(14, 0);
lcd.print("am");
}
}
[/code]
the first thing noticed code:
an int cannot hold 60000 or 360000 on arduino.
perhaps intended long instead of int ?
code: [select]
int millidivmins = 60000;
int millidivhrs = 360000;
an int cannot hold 60000 or 360000 on arduino.
perhaps intended long instead of int ?
Arduino Forum > Using Arduino > Programming Questions > [SOLVED] Trying to combine large font and time with no RTC
arduino
Comments
Post a Comment