Okay ... I am making a clock with my 16*2 lcd and I am using the serial time library (the one you use unix time for so you can make a clock with only a usb and a lcd. I am trying to make a "large text" lcd script and i was trying to do a little bit of math....
The only thing i cant get is how to take a 0-60 minute time format to just tens of minutes and ones of the minutes
like instead of the computer seeing 53 minutes it sees
5 as tens of minutes
and 3 as ones of minutes
so i can program my old script without alot of changes.
Also I would like help doing this with hours and seconds...
I'm not entirely clear on what you want. To use your example, if it was 53 minutes, would you want a 5 in one variable and a 3 in another?
YES! Sorry for that ... bugged out atm about this...
No worries. Just to be clear, you're using this Time library?
http://www.arduino.cc/playground/Code/Time
Yep
if you wish to see the "large text" script to see how it runs... here it is
/*
A set of custom made large numbers for a 16x2 LCD using the
LiquidCrystal librabry. Works with displays compatible with the
Hitachi HD44780 driver.
The Cuicuit:
LCD RS pin to D12
LCD Enable pin to D11
LCD D4 pin to D5
LCD D5 pin to D4
LCD D6 pin to D3
LCD D7 pin to D2
LCD Vee tied to a pot to control brightness
LCD Vss and R/W tied to ground
LCD Vcc to +5V
LCD pin 15 tied to pushbutton for control of backlight
Made by Michael Pilcher
2/9/2010
*/
// include the library
#include <LiquidCrystal.h>
#include <Time.h>
int h = hour()
int m = (minute()/10-(
int mm = minute
#define TIME_MSG_LEN 11 // time sync to PC is HEADER followed by unix time_t as ten ascii digits
#define TIME_HEADER 'T' // Header tag for serial time sync message
#define TIME_REQUEST 7
// initialize the interface pins
LiquidCrystal lcd(7,8,9,10,11,12);
int x = 0;
// the 8 arrays that form each segment of the 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()
{
Serial.begin(9600);
setSyncProvider( requestSync); //set function to call when sync required
Serial.println("Waiting for sync message");
// assignes each segment a write number
lcd.createChar(0,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 the LCD's rows and colums:
lcd.begin(16, 2);
}
void custom0O()
{ // uses segments to build the number 0
lcd.setCursor(x, 0);
lcd.write(0);
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(5);
}
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(5);
}
void custom5S()
{
lcd.setCursor(x,0);
lcd.write(0);
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(0);
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(0);
}
void custom8()
{
lcd.setCursor(x,0);
lcd.write(0);
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(0);
lcd.write(6);
lcd.write(2);
lcd.setCursor(x+2, 1);
lcd.write(5);
}
void customA()
{
lcd.setCursor(x,0);
lcd.write(0);
lcd.write(6);
lcd.write(2);
lcd.setCursor(x, 1);
lcd.write(3);
lcd.print(" ");
lcd.write(5);
}
void customB()
{
lcd.setCursor(x,0);
lcd.write(0);
lcd.write(6);
lcd.write(5);
lcd.setCursor(x, 1);
lcd.write(3);
lcd.write(7);
lcd.write(2);
}
void customC()
{
lcd.setCursor(x,0);
lcd.write(0);
lcd.write(1);
lcd.write(1);
lcd.setCursor(x,1);
lcd.write(3);
lcd.write(4);
lcd.write(4);
}
void customD()
{
lcd.setCursor(x, 0);
lcd.write(2);
lcd.write(1);
lcd.write(2);
lcd.setCursor(x, 1);
lcd.write(5);
lcd.write(4);
lcd.write(5);
}
void customE()
{
lcd.setCursor(x,0);
lcd.write(0);
lcd.write(6);
lcd.write(6);
lcd.setCursor(x, 1);
lcd.write(3);
lcd.write(7);
lcd.write(7);
}
void customF()
{
lcd.setCursor(x,0);
lcd.write(0);
lcd.write(6);
lcd.write(6);
lcd.setCursor(x, 1);
lcd.write(3);
}
void customG()
{
lcd.setCursor(x,0);
lcd.write(0);
lcd.write(1);
lcd.write(1);
lcd.setCursor(x,1);
lcd.write(3);
lcd.write(4);
lcd.write(2);
}
void customH()
{
lcd.setCursor(x,0);
lcd.write(0);
lcd.write(4);
lcd.write(2);
lcd.setCursor(x, 1);
lcd.write(3);
lcd.print(" ");
lcd.write(5);
}
void customI()
{
lcd.setCursor(x,0);
lcd.write(1);
lcd.write(2);
lcd.write(1);
lcd.setCursor(x,1);
lcd.write(4);
lcd.write(5);
lcd.write(4);
}
void customJ()
{
lcd.setCursor(x+2,0);
lcd.write(2);
lcd.setCursor(x,1);
lcd.write(4);
lcd.write(4);
lcd.write(5);
}
void customK()
{
lcd.setCursor(x,0);
lcd.write(0);
lcd.write(4);
lcd.write(5);
lcd.setCursor(x,1);
lcd.write(3);
lcd.print(" ");
lcd.write(2);
}
void customL()
{
lcd.setCursor(x,0);
lcd.write(0);
lcd.setCursor(x,1);
lcd.write(3);
lcd.write(4);
lcd.write(4);
}
void customM()
{
lcd.setCursor(x,0);
lcd.write(0);
lcd.write(1);
lcd.write(3);
lcd.write(1);
lcd.write(2);
lcd.setCursor(x,1);
lcd.write(3);
lcd.print(" ");
lcd.write(5);
}
the rest (max was reached)
void customN()
{
lcd.setCursor(x,0);
lcd.write(0);
lcd.write(3);
lcd.print(" ");
lcd.write(2);
lcd.setCursor(x,1);
lcd.write(3);
lcd.print(" ");
lcd.write(2);
lcd.write(5);
}
void customP()
{
lcd.setCursor(x,0);
lcd.write(0);
lcd.write(6);
lcd.write(2);
lcd.setCursor(x, 1);
lcd.write(3);
}
void customQ()
{
lcd.setCursor(x,0);
lcd.write(0);
lcd.write(1);
lcd.write(2);
lcd.setCursor(x, 1);
lcd.write(3);
lcd.write(4);
lcd.write(3);
lcd.write(4);
}
void customR()
{
lcd.setCursor(x,0);
lcd.write(0);
lcd.write(6);
lcd.write(5);
lcd.setCursor(x,1);
lcd.write(3);
lcd.print(" ");
lcd.write(2);
}
void customT()
{
lcd.setCursor(x,0);
lcd.write(1);
lcd.write(2);
lcd.write(1);
lcd.setCursor(x,1);
lcd.print(" ");
lcd.write(5);
}
void customU()
{
lcd.setCursor(x, 0);
lcd.write(0);
lcd.print(" ");
lcd.write(2);
lcd.setCursor(x, 1);
lcd.write(3);
lcd.write(4);
lcd.write(5);
}
void customV()
{
lcd.setCursor(x, 0);
lcd.write(3);
lcd.print(" ");
lcd.write(5);
lcd.setCursor(x+1, 1);
lcd.write(3);
lcd.write(5);
}
void customW()
{
lcd.setCursor(x,0);
lcd.write(0);
lcd.print(" ");
lcd.write(2);
lcd.setCursor(x,1);
lcd.write(3);
lcd.write(4);
lcd.write(0);
lcd.write(4);
lcd.write(5);
}
void customX()
{
lcd.setCursor(x,0);
lcd.write(3);
lcd.write(4);
lcd.write(5);
lcd.setCursor(x,1);
lcd.write(0);
lcd.print(" ");
lcd.write(2);
}
void customY()
{
lcd.setCursor(x,0);
lcd.write(3);
lcd.write(4);
lcd.write(5);
lcd.setCursor(x+1,1);
lcd.write(5);
}
void customZ()
{
lcd.setCursor(x,0);
lcd.write(1);
lcd.write(6);
lcd.write(5);
lcd.setCursor(x, 1);
lcd.write(0);
lcd.write(7);
lcd.write(4);
}
void loop()
{
//* custom1();
// x = x + 4;
// custom2();
// x = x + 4;
// setCursor(x,0);
// lcd.print(".");
// setCursor(x,1);
// lcd.print("*");
//x = x + 1;
//custom5();
// x=x+4;
//custom9();
//x=x+4;
//delay(1000);
// lcd.clear();
if(Serial.available() )
{
processSyncMessage();
}
if(timeStatus()!= timeNotSet)
{
digitalWrite(13,timeStatus() == timeSet); // on if synced, off if needs refresh
digitalClockDisplay();
}
delay(100);
}
void digitalClockDisplay(){
// digital clock display of the time
printDigits(hour());
printDigits(minute());
printDigits(second());
Serial.print(" ");
Serial.print(day());
Serial.print(" ");
Serial.print(month());
Serial.print(" ");
Serial.print(year());
Serial.println();
}
void printDigits(int digits){
// utility function for digital clock display: prints preceding colon and leading 0
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}
void processSyncMessage() {
// if time sync available from serial port, update time and return true
while(Serial.available() >= TIME_MSG_LEN ){ // time message consists of a header and ten ascii digits
char c = Serial.read() ;
Serial.print(c);
if( c == TIME_HEADER ) {
time_t pctime = 0;
for(int i=0; i < TIME_MSG_LEN -1; i++){
c = Serial.read();
if( c >= '0' && c <= '9'){
pctime = (10 * pctime) + (c - '0') ; // convert digits to a number
}
}
setTime(pctime); // Sync Arduino clock to the time received on the serial port
}
}
}
time_t requestSync()
{
Serial.print(TIME_REQUEST,BYTE);
return 0; // the time will be sent later in response to serial mesg
}
I might do something like
time_t timeNow;
int minutesNow, minutesTens, minutesOnes;
...
timeNow = now();
minutesNow = minute(timeNow);
minutesTens = minutesNow / 10;
minutesOnes = minutesNow % 10;
53/10 = 53%*10
Awsomdk:
53/10 = 53%*10
Sorry ... What??
minutesTens = minutesNow / 10;
minutesOnes = minutesNow % 10;
they both would equal the same thing?
Can someone help me with this?Pweeze
Ah! No, they are not the same thing. The "%" is the modulo operator, sometimes called remaindering (has nothing to do with percentage). See: http://arduino.cc/en/Reference/Modulo
Awsomdk:
Can someone help me with this?Pweeze
Try the code I posted and you should find that 53 / 10 = 5 and 53 % 10 = 3