codeee

int latchPin = 6;
int clockPin = 7;
int dataPin = 5;
byte cijfers[] = {
  192, 249, 164, 176, 153, 146, 130, 248, 128, 144, 255, 231, 255-32-64,231-32-64, 255-8, 255-2  };
byte dig[] = {
  255,231,192,192,176,255,176};
byte anz=0;// een van de 5 cathodes
volatile unsigned long seconden = 0;
unsigned long seconden_oud = 0;
int seco;
int minu;
int uren;
boolean star = 0;
boolean leng = 0;
boolean chan = 0;
boolean scnd = 0;
ISR(TIMER1_OVF_vect) {
  TCNT1=0xBDC;
  seconden = seconden+1;
}
void setup() {
  Serial.begin(9600);
  TIMSK1=0×01; // enabled global and timer overflow interrupt;
  TCCR1A = 0×00; // normal operation page 148 (mode0);
  TCNT1=0xBDC; // set initial value to remove time error (16bit counter register)
  TCCR1B = 0×04; // start timer/ set clock
  zetTijd();
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
}
void zetTijd(){
  String tijd = __TIME__;
  uren = (tijd.charAt(0)-48)*10+tijd.charAt(1)-48;
  minu = (tijd.charAt(3)-48)*10+tijd.charAt(4)-48;
  seco = (tijd.charAt(6)-48)*10+tijd.charAt(7)-48;
}
void loop () {
  tijd();
  if ((seco%10) >4){
    zetSec();
  }
  else{
    zetUurMin();
  }
  draw();
}
void zetSec(){
  dig[0] = 255 – 4;
  dig[1] = 255;
  dig[2] = cijfers[seco/10];
  dig[3] = cijfers[seco%10];
  dig[4] = 255;
}
void zetUurMin(){
  dig[0] = cijfers[14+uren/12];
  //dig[0] = dig[0] – 64*star;
  //dig[0] = dig[0] – 32*leng;
  //dig[0] = dig[0] – 16*chan;
  //dig[0] = dig[0] – 4*scnd;
  dig[1] = cijfers[10+2*(seco%2)+(uren%12)/10];
  dig[2] = cijfers[(uren%12)%10];
  dig[3] = cijfers[minu/10];
  dig[4] = cijfers[minu%10];
}
void tijd(){
  if (seconden_oud != seconden){
    seco = seco + (seconden – seconden_oud);
    seconden_oud = seconden;
    if (seco == 60){
      seco = 0;
      minu++;
      if (minu == 60){
        minu = 0;
        uren++;
        if (uren == 24){
          uren = 0;
        }
      }
    }
  }
}
void draw(){
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, LSBFIRST, dig[anz]);
  shiftOut(dataPin, clockPin, LSBFIRST, 16>>anz);
  digitalWrite(latchPin, HIGH);
  delayMicroseconds(5);
  anz++;
  if (anz>5) anz=0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>