I`m completely new to arduino, circuits, programming, etc - but I went to the Make Fair in NYC a couple weeks ago and left feeling inspired to build my own binary clock.
I picked up the Arduino starter kit from this site and have successfully been through the older set of tutorials (the newer ones require a shift-register and that's in the mail).
The big question that I have is that my clock isn't accurate. I've been losing ~1 second every hour. I had read online that these boards are good for 1-2 seconds per day, so I`m well above that.
Here's my code:
Code: Select all
#include <Time.h> //Need this to count the seconds.
int s1 = 0;
int s10 = 0;
int m1 = 0;
int m10 = 0;
int hours = 0;
int h1 = 0;
int h10 = 0;
int timecheck;
void setup() {
Serial.begin(9600); //Set up serial communication at 9600bps
setTime(12,0,0,1,1,11);
timecheck = second(); }
void loop(){
////////// time keeping //////////
if (timecheck != second()) {
s1++;
timecheck = second();
if (s1 == 10) {
s1=0;
s10++; }
if (s10 == 6 ) {
s10 = 0;
m1++; }
if (m1 == 10) {
m1 = 0;
m10++; }
if(m10 == 6) {
m10 = 0;
hours++; }
if(hours<10) {
h1 = hours;
h10 = 0; }
else {
if(hours<12) {
h1 = hours-10;
h10 = 1; }
else {
hours=0;
}}
// The next bits print to Serial, and I assume they're not relevant to this issue
}
////////// seconds ones display //////////
if (s1 == 1 || s1 == 3 || s1 == 5 || s1 == 7 || s1 == 9) {
digitalWrite(8,HIGH); }
else { digitalWrite(8,LOW); }
//similar if's for the other LED lights to display seconds as 0-9
//once i get the shift registers there will be lots more similar code
}
I thought about just using the hour(), minute(), second(), etc that load with Time.h, but it seems like that would make the LED display more complicated.
Thanks in advance!