help fine-tuning LED binary clock
ok, first real project. it's binary clock -- not bcd, mind you, "true" binary. so, first bit half days, second bit quarter days, eighths, etc. here's example: http://www.abulsme.com/binarytime/
i set on breadboard 10 leds expand 4x4 matrix demuxer.
i thought pretty straight-forward, clock seems gaining 6min/day. i've poked around on forums here , heard normal because uno uses ceramic rather crystal resonator. so, there 2 ways go fixing it: hardware -- rtc crystal resonator ; or software -- measure inaccuracy , compensate in code.
which route should take? able use rtc thing since doesn't use hh:mm:ss? or if go software route, talk me through that? , maybe dumb down little novice?
here's code. thanks!
i set on breadboard 10 leds expand 4x4 matrix demuxer.
i thought pretty straight-forward, clock seems gaining 6min/day. i've poked around on forums here , heard normal because uno uses ceramic rather crystal resonator. so, there 2 ways go fixing it: hardware -- rtc crystal resonator ; or software -- measure inaccuracy , compensate in code.
which route should take? able use rtc thing since doesn't use hh:mm:ss? or if go software route, talk me through that? , maybe dumb down little novice?
here's code. thanks!
code: [select]
const int led1 = 4;
const int led2 = 5;
const int led3 = 6;
const int led4 = 7;
const int led5 = 8;
const int led6 = 9;
const int led7 = 10;
const int led8 = 11;
const int led9 = 12;
const int led10 = 13;
int ledstate1 = low;
int ledstate2 = low;
int ledstate3 = low;
int ledstate4 = low;
int ledstate5 = low;
int ledstate6 = low;
int ledstate7 = low;
int ledstate8 = low;
int ledstate9 = low;
int ledstate10 = low;
long previousmillis1 = 0;
long previousmillis2 = 0;
long previousmillis3 = 0;
long previousmillis4 = 0;
long previousmillis5 = 0;
long previousmillis6 = 0;
long previousmillis7 = 0;
long previousmillis8 = 0;
long previousmillis9 = 0;
long previousmillis10 = 0;
long interval1 = 43200000;
long interval2 = 21600000;
long interval3 = 10800000;
long interval4 = 5400000;
long interval5 = 2700000;
long interval6 = 1350000;
long interval7 = 675000;
long interval8 = 337500;
long interval9 = 168750;
long interval10 = 84375;
void setup() {
pinmode(led1, output);
pinmode(led2, output);
pinmode(led3, output);
pinmode(led4, output);
pinmode(led5, output);
pinmode(led6, output);
pinmode(led7, output);
pinmode(led8, output);
pinmode(led9, output);
pinmode(led10, output);
}
void loop() {
unsigned long currentmillis = millis();
if(currentmillis - previousmillis1 > interval1) {
previousmillis1 = currentmillis;
if (ledstate1 == low)
ledstate1 = high;
else
ledstate1 = low;
digitalwrite(led1, ledstate1);
}
if(currentmillis - previousmillis2 > interval2) {
previousmillis2 = currentmillis;
if (ledstate2 == low)
ledstate2 = high;
else
ledstate2 = low;
digitalwrite(led2, ledstate2);
}
if(currentmillis - previousmillis3 > interval3) {
previousmillis3 = currentmillis;
if (ledstate3 == low)
ledstate3 = high;
else
ledstate3 = low;
digitalwrite(led3, ledstate3);
}
if(currentmillis - previousmillis4 > interval4) {
previousmillis4 = currentmillis;
if (ledstate4 == low)
ledstate4 = high;
else
ledstate4 = low;
digitalwrite(led4, ledstate4);
}
if(currentmillis - previousmillis5 > interval5) {
previousmillis5 = currentmillis;
if (ledstate5 == low)
ledstate5 = high;
else
ledstate5 = low;
digitalwrite(led5, ledstate5);
}
if(currentmillis - previousmillis6 > interval6) {
previousmillis6 = currentmillis;
if (ledstate6 == low)
ledstate6 = high;
else
ledstate6 = low;
digitalwrite(led6, ledstate6);
}
if(currentmillis - previousmillis7 > interval7) {
previousmillis7 = currentmillis;
if (ledstate7 == low)
ledstate7 = high;
else
ledstate7 = low;
digitalwrite(led7, ledstate7);
}
if(currentmillis - previousmillis8 > interval8) {
previousmillis8 = currentmillis;
if (ledstate8 == low)
ledstate8 = high;
else
ledstate8 = low;
digitalwrite(led8, ledstate8);
}
if(currentmillis - previousmillis9 > interval9) {
previousmillis9 = currentmillis;
if (ledstate9 == low)
ledstate9 = high;
else
ledstate9 = low;
digitalwrite(led9, ledstate9);
}
if(currentmillis - previousmillis10 > interval10) {
previousmillis10 = currentmillis;
if (ledstate10 == low)
ledstate10 = high;
else
ledstate10 = low;
digitalwrite(led10, ledstate10);
}
}
rtc far, far simpler since you'll otherwise need reference clock of form work against. can estimate based on time on rtc, , looks @ 16 bits, each bit 1.32s. rtcs give @ least 10ms precision.
or resync gps every day.
or resync gps every day.
Arduino Forum > Using Arduino > Project Guidance > help fine-tuning LED binary clock
arduino
Comments
Post a Comment