// sidereal clock // Antonio C B Oliveira // Observatorio Longa Vista // cal@longavista.com.br // www.longavista.com.br // November 2011 #include #include #include // a basic DS1307 library that returns time as a time_t #include "HT1632.h" // ethernet libraries #include #include #include // global variables, some have to be changed for each observatory #include "gmst0.h" // control pins for display #define DATA 2 #define WR 3 #define CS 5 #define CS2 6 #define LED 8 // brigthness control potentiometer #define POT 0 // dispaly definition HT1632LEDMatrix matrix = HT1632LEDMatrix(DATA, WR, CS, CS2); // NTP time stamp is in the first 48 bytes of the message const int NTP_PACKET_SIZE=48; // buffer to hold incoming and outgoing messages byte pb[NTP_PACKET_SIZE]; //local port to listen for UDP packets unsigned int localPort=8888; int valPot; int8_t brilho=15,brilhoAnt=15; // display variables char displayUT[9]; char displayLST[9]; time_t lastSyncNTP; const int syncInterval=600; void setup() { // deselect SD card pinMode(4,OUTPUT); digitalWrite(4 , HIGH); pinMode(LED, OUTPUT); // sync real time clock with arduino setSyncProvider(RTC.get); while(timeStatus()!= timeSet); // inicialize LED matrix matrix.begin(HT1632_COMMON_16NMOS); matrix.fillScreen(); delay(500); // start Ethernet and UDP Ethernet.begin(mac, ip); Udp.begin(localPort); delay(5000); // clear display matrix.clearScreen(); matrix.setTextSize(1); // size 1 == 8 pixels high matrix.setTextColor(1); // 'lit' LEDs lastSyncNTP=0; } void loop() { time_t agora=now(); clockDisplay(agora); time_t proximo=agora+1; // adjust brightness valPot=analogRead(POT); brilho=valPot/64; if (brilho!=brilhoAnt) { matrix.setBrightness(brilho); brilhoAnt=brilho; } // NTP sync if ((agora-lastSyncNTP)>=syncInterval) { lastSyncNTP=syncNTP(); } // wait for next second while (agora=0 && deltaDia