why isn't my clock changing with time
in
Programming Questions
•
7 months ago
Hi
I'm trying to make a clock that shows real time, so it can work as a timer as well as trigger events. ( i want it for sunrise and sunset. I found some code here in the forum that helps as far as it creates the clock, but it doesn't refresh.
What am I doing wrong?
ps is the if statement right as a trigger (it's not accurate, but will be linked up to yahoo xml)?
thanks
nanette
here is the code:
import java.util.*;
Calendar calendar = new GregorianCalendar();
String am_pm;
int hour = calendar.get(Calendar.HOUR);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
// int framerate (60);
void setup() {
size (200, 200);
smooth();
background (255);
if (calendar.get(Calendar.AM_PM) == 0) {
am_pm = "AM";
}
else {
am_pm = "PM";
}
println("Current Time : " + hour + ":" + minute + ":" + second + " " + am_pm);
}
void draw () {
background (255);
fill (0);
textAlign (CENTER);
textSize (20);
text ("Current Time : \n "+ hour + ":" + minute + ":" + second + " " + am_pm, width/2, height/2);
if (hour>6 && minute>= 53 && am_pm== "AM") {
fill (0,255,255);
rect (width/2, 10, 40, 40);
}
if (hour>6 && minute>= 13 && am_pm== "PM") {
fill(255,255,255);
rect (width/2, 10, 40, 40);
}
}
I'm trying to make a clock that shows real time, so it can work as a timer as well as trigger events. ( i want it for sunrise and sunset. I found some code here in the forum that helps as far as it creates the clock, but it doesn't refresh.
What am I doing wrong?
ps is the if statement right as a trigger (it's not accurate, but will be linked up to yahoo xml)?
thanks
nanette
here is the code:
import java.util.*;
Calendar calendar = new GregorianCalendar();
String am_pm;
int hour = calendar.get(Calendar.HOUR);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
// int framerate (60);
void setup() {
size (200, 200);
smooth();
background (255);
if (calendar.get(Calendar.AM_PM) == 0) {
am_pm = "AM";
}
else {
am_pm = "PM";
}
println("Current Time : " + hour + ":" + minute + ":" + second + " " + am_pm);
}
void draw () {
background (255);
fill (0);
textAlign (CENTER);
textSize (20);
text ("Current Time : \n "+ hour + ":" + minute + ":" + second + " " + am_pm, width/2, height/2);
if (hour>6 && minute>= 53 && am_pm== "AM") {
fill (0,255,255);
rect (width/2, 10, 40, 40);
}
if (hour>6 && minute>= 13 && am_pm== "PM") {
fill(255,255,255);
rect (width/2, 10, 40, 40);
}
}
1