Go Down

Topic: 7 Segment Display clock - TIME (Read 3 times) previous topic - next topic

Portyy

Hello guys,

so basically, my idea is a clock on 2 multiplexed 7SD, and minutes and hours will be switching with period 2 secs with LED indicator which one is active now. I did that, its working fine but i have big issues with getting time from PC (they will be near PC so...). I downloaded Time library, and used reference code to get time from unix timestamp entered to serial monitor. But the problem is, i put in timestamp from 1 1 1970 and somehow that stamp is saved, so everytime i try to save a actual one, it still displays in serial monitor that is 1 1 1970 00 00 00 ... idk whats happening, where is problem. I restarted arduino, turn off/on power... nothing. Here is the code, designed mostly in slovak but you may understood at least where can the problem with Time may be..
Code: [Select]

#include <Time.h>

#define TIME_MSG_LEN 11
#define TIME_HEADER 'T'
#define TIME_REQUEST 7

//T1262347200

int timer = 150;                                        //            DISPLEJ
int a = 6;                                              //            ---a---     
int b = 7;                                                //          |     |
int c = 8;                                                  //        f     b
int d = 5;                                                    //      |     |
int e = 4;                                                      //    ---g---
int f = 2;                                                        //  |     |
int g = 3;                                                       //   e     c
int dot = 9;                                                    //    |     |
int horny = 11;                                               //      ---d---   .h
int dolny = 10;                                               
int hrLED = 12;
int minLED = 13;
int hod = hour();
int mins = 1;


void setup() {
  Serial.begin(9600);
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  digitalWrite(dot, HIGH);
}

void loop() {
  // SERIAL //
  if(Serial.available() )
  {
    processSyncMessage();
  }
  if(timeStatus() == timeNotSet) 
    Serial.println("waiting for sync");
 
  else
    hodiny();
    digitalClockDisplay();
  delay(1000);
}

void hodiny() {
  // hodiny
  if (hod == 9) {
   
      //disp1
      delay(1);
      digitalWrite(a, 1);
      digitalWrite(b, 0);
      digitalWrite(c, 0);
      digitalWrite(d, 1);
      digitalWrite(e, 0);
      digitalWrite(f, 0);
      digitalWrite(g, 1);
      digitalWrite(horny, 0);
      digitalWrite(dolny, 1);
      delay(1);
      //disp2
      digitalWrite(a, 0);
      digitalWrite(b, 1);
      digitalWrite(c, 0);
      digitalWrite(d, 0);
      digitalWrite(e, 1);
      digitalWrite(f, 0);
      digitalWrite(g, 1);
      digitalWrite(horny, 1);
      digitalWrite(dolny, 0);
      delay(1);
   
  }
  if (hod == 7) {
 
      //disp 1
      digitalWrite(a, 0);
      digitalWrite(b, 0);
      digitalWrite(c, 0);
      digitalWrite(d, 0);
      digitalWrite(e, 0);
      digitalWrite(f, 0);
      digitalWrite(g, 1);
      digitalWrite(horny, 1);
      digitalWrite(dolny, 0);
      digitalWrite(hrLED, 1);
      digitalWrite(minLED, 0);
      delay(1);
      //disp 2
      digitalWrite(a, 0);
      digitalWrite(b, 0);
      digitalWrite(c, 0);
      digitalWrite(d, 1);
      digitalWrite(e, 1);
      digitalWrite(f, 1);
      digitalWrite(g, 1);
      digitalWrite(horny, 0);
      digitalWrite(dolny, 1);
      digitalWrite(hrLED, 1);
      digitalWrite(minLED, 0);
      delay(1);
  }

}

void digitalClockDisplay(){
 
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year());
  Serial.println();
}

void printDigits(int digits){

  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

void processSyncMessage() {

  while(Serial.available() >=  TIME_MSG_LEN ){
    char c = Serial.read() ;
    Serial.print(c); 
    if( c == TIME_HEADER ) {       
      time_t pctime = 0;
      for(int i=0; i < TIME_MSG_LEN -1; i++){   
        c = Serial.read();         
        if( c >= '0' && c <= '9'){   
          pctime = (10 * pctime) + (c - '0') ;   
        }
      }   
      setTime(pctime);
    } 
  }
}


again, problem is that arduino have stored timestamp T1262347200 which stands for 1st of january 1970 midnight, and everytime i run program and opens serial monitor arduino displays that time and wants to synchronize (get a new stamp) at the same time which is weird and i canĀ“t find the problem.. :/ any help is welcome :)

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