Go Down

Topic: reusing a 4*7segments from clockradio (Read 2186 times) previous topic - next topic

clabis

Sep 26, 2013, 08:16 pm Last Edit: Sep 26, 2013, 08:18 pm by clabis Reason: 1
Hi.
I searched to use display from my broken radioclock, its look the same as show here:
http://www.electroniq.net/other-projects/digital-clock-alarm-based-lm8560.html
http://postimg.org/image/s5owqafz1/ (here i added output in red)
So it was finaly controled via two 74HC595

Here is the code for a fast clock:
Code: [Select]
long previous1 = 0;
long interval1 = 10;
long previous2 = 0;
long interval2 = 200;
int digit[4]={8,8,8,8};
int heure=0;
int minute=0;
int SER_Pin = 2;   //pin 14 on the 75HC595 SPI mosi
int RCLK_Pin = 3;  //pin 12 on the 75HC595 SPI ss
int SRCLK_Pin = 4; //pin 11 on the 75HC595 SPI clock

#define number_of_74hc595s 2

#define numOfRegisterPins number_of_74hc595s * 8
int phase = 0;
boolean registers[numOfRegisterPins];
byte seven_seg_digits[11][7] = { { 1,1,1,1,1,1,0 },  // = 0
                                 { 0,1,1,0,0,0,0 },  // = 1
                                 { 1,1,0,1,1,0,1 },  // = 2
                                 { 1,1,1,1,0,0,1 },  // = 3
                                 { 0,1,1,0,0,1,1 },  // = 4
                                 { 1,0,1,1,0,1,1 },  // = 5
                                 { 1,0,1,1,1,1,1 },  // = 6
                                 { 1,1,1,0,0,0,0 },  // = 7
                                 { 1,1,1,1,1,1,1 },  // = 8
                                 { 1,1,1,1,0,1,1 },  // = 9
                                 { 0,0,0,0,0,0,0 },  //
                                 }; 

//                   A  B  C  D  E  F  G
byte seg[4][2][7]={{{2, 4, 3, 0, 0, 0, 0},
                    {0, 0, 0, 3, 5, 2, 4}},
                   {{0, 0, 0, 6, 5, 8, 7},
                    {8, 7, 6, 0, 0, 0, 0}},
                   {{9, 11,10,0, 0, 0, 0},
                    {0, 0, 0, 10,12,9, 11}},
                   {{0, 15,12,0, 13,0, 14},
                    {14,0, 0, 13,0, 0, 0}}};
void setup(){
  pinMode(SER_Pin, OUTPUT);
  pinMode(RCLK_Pin, OUTPUT);
  pinMode(SRCLK_Pin, OUTPUT);

  clearRegisters();
  writeRegisters();

 
}               

void clearRegisters(){
  for(int i = numOfRegisterPins - 1; i >=  0; i--){
     registers[i] = LOW;
  }
}

void writeRegisters(){

  digitalWrite(RCLK_Pin, LOW);

  for(int i = numOfRegisterPins - 1; i >=  0; i--){
    digitalWrite(SRCLK_Pin, LOW);

    int val = registers[i];

    digitalWrite(SER_Pin, val);
    digitalWrite(SRCLK_Pin, HIGH);

  }
  digitalWrite(RCLK_Pin, HIGH);

}

void setRegisterPin(int index, int value){
  registers[index] = value;
}


void loop()
{
  long currentMillis = millis();
  if(currentMillis - previous1 > interval1) {
    clearRegisters();
    previous1 = currentMillis;
    for (byte d = 0; d < 4; ++d) {
    for (byte segCount = 0; segCount < 7; ++segCount) {
        int n=seg[d][phase][segCount];
        if (n>0){
          setRegisterPin(n,seven_seg_digits[digit[3-d]][segCount]);
        }
      }
  }
    if (phase==0){
      setRegisterPin(0, 1);
      setRegisterPin(1, 0);
    }
    if (phase==1){
      setRegisterPin(0, 0);
      setRegisterPin(1, 1);
    }
    writeRegisters();
    phase++;
    if (phase>1){phase=0;}
   
   
  }
  if(currentMillis - previous2 > interval2) {
    previous2 = currentMillis;
    minute++;
    if (minute>59){
      minute=0;
      heure++;
    }
    if (heure>23){
      heure=0;
    }
    int h1=heure/10;
    if (h1==0){
      digit[0]=10;}
    else{
      digit[0]=h1;
    }
    digit[1]=heure%10;
    digit[2]=minute/10;
    digit[3]=minute%10;
  }
 
}

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy