#include #include #include #include #define TIME_MSG_LEN 11 // time sync to PC is HEADER followed by Unix time_t as ten ASCII digits #define TIME_HEADER 'T' // Header tag for serial time sync message #define TIME_REQUEST 7 // ASCII bell character requests a time sync message // T1262347200 //noon Jan 1 2010 #define outPin 8 // Arduino pin to Ge Color Effects Lights #define relayPin 9 // Arduino to Relay that controls power to GE Lights #define lightCount 60 //Total # of lights on string (usually 50, 48, or 36) #define WH_MIN 2//wormhole min and max run times (Seconds) #define WH_MAX 5 byte CHEVRON_COLOR[3] = {10,1,0};//orangish byte WORMHOLE_COLOR[3] = {4,8,15};//blueish static uint16_t c; static uint16_t Leds [lightCount][2]; // Second[0-59] [0=Color] [1=Intensity] static unsigned long timerSec = millis(); // byte LIGHT_INTENSITY = DEFAULT_INTENSITY; // 0xCC or 204 byte LIGHT_INTENSITY = 0x20; // 0xCC or 204 GEColorEffects lights(outPin, lightCount); //Constructor // ============================================================================================ // Function EnumerateLeds // ============================================================================================ int EnumerateLeds() { int i; digitalWrite(relayPin, HIGH); // Disconnect Power from GE Lights delay(2000); // Wait for a few seconds digitalWrite(relayPin, LOW); // Enable Power to GE Lights delay(2000); // Set 1st led to max light count to get it out of the way for (i=0; i= 12) { hrLed = (hour - 12) * 5; } else { hrLed = hour * 5; } // Increment the led for every 12 minutes through the hour if (minute >= (12*1)) { hrLed++; } if (minute >= (12*2)) { hrLed++; } if (minute >= (12*3)) { hrLed++; } if (minute >= (12*4)) { hrLed++; } // Find Hour Led Minus 1 if (hrLed == 0) { hrLedM1 = 59; } else { hrLedM1 = hrLed - 1; } // Find Hour Led Minus 2 if (hrLedM1 == 0) { hrLedM2 = 59; } else { hrLedM2 = hrLedM1 - 1; } // Find Hour Led Plus 1 hrLedP1 = (hrLed+1) % lightCount; // Find Hour Led Plus 2 hrLedP2 = (hrLedP1+1) % lightCount; Leds[hrLedM2][0] = COLOR((0xF),0,0); Leds[hrLedM2][1] = 15; Leds[hrLedM1][0] = COLOR((0xF),0,0); Leds[hrLedM1][1] = 63; Leds[hrLed][0] = COLOR((0xF),0,0); // Red Leds[hrLed][1] = LIGHT_INTENSITY; Leds[hrLedP1][0] = COLOR((0xF),0,0); Leds[hrLedP1][1] = 63; Leds[hrLedP2][0] = COLOR((0xF),0,0); Leds[hrLedP2][1] = 15; } // ============================================================================================ // Function setClockMinute // ============================================================================================ void setClockMinute(int hour, int minute, int second){ int minLedM1, minLedP1; // Find Minute Led Minus 1 if (minute == 0) { minLedM1 = 59; } else { minLedM1 = minute - 1; } // Find Hour Led Plus 1 minLedP1 = (minute+1) % lightCount; Leds[minLedM1][0] = COLOR(0,(0xF),0); Leds[minLedM1][1] = 45; Leds[minute][0] = COLOR(0,(0xF),0); // Green Leds[minute][1] = LIGHT_INTENSITY; Leds[minLedP1][0] = COLOR(0,(0xF),0); Leds[minLedP1][1] = 45; } // ============================================================================================ // Function setClockSecond // ============================================================================================ void setClockSecond(int hour, int minute, int second){ int secLedM1; float prop = (millis()-timerSec) / 1000.0; float iprop = 1.0-prop; // Find Minute Led Minus 1 if (second == 0) { secLedM1 = 59; } else { secLedM1 = second - 1; } Leds[secLedM1][0] = COLOR(0,0,(0xF)); Leds[secLedM1][1] = LIGHT_INTENSITY*iprop; Leds[second][0] = COLOR(0,0,(0xF)); // Blue Leds[second][1] = LIGHT_INTENSITY*prop; } // ============================================================================================ // Function displayClock // ============================================================================================ void displayClock(int hour, int minute, int second){ clearLeds(); setClockMarks(); setClockHour (hour, minute, second); setClockMinute(hour, minute, second); //setClockMarks(); setClockSecond(hour, minute, second); updateLeds(); } // ============================================================================================ // setChevron // ============================================================================================ void setChevron(int chevron) { //add chevron for current state //chervons are orange int led1 = 0; int led2 = 0; int led3 = 0; if(chevron == 0) { return; } if(chevron == 1){led1 = 6; led2 = led1+1; led3 = led1+2;} if(chevron == 2){led1 = 12; led2 = led1+1; led3 = led1+2;} if(chevron == 3){led1 = 19; led2 = led1+1; led3 = led1+2;} if(chevron == 4){led1 = 39; led2 = led1+1; led3 = led1+2;} if(chevron == 5){led1 = 46; led2 = led1+1; led3 = led1+2;} if(chevron == 6){led1 = 52; led2 = led1+1; led3 = led1+2;} if(chevron == 7){led1 = 26; led2 = led1+1; led3 = led1+2;} if(chevron == 8){led1 = 32; led2 = led1+1; led3 = led1+2;} if(chevron == 9){led1 = 59; led2 = 0; led3 = 1;} Leds[led1][0] = COLOR(CHEVRON_COLOR[0],CHEVRON_COLOR[1],CHEVRON_COLOR[2]); Leds[led2][0] = COLOR(CHEVRON_COLOR[0],CHEVRON_COLOR[1],CHEVRON_COLOR[2]); Leds[led3][0] = COLOR(CHEVRON_COLOR[0],CHEVRON_COLOR[1],CHEVRON_COLOR[2]); } // ============================================================================================ // addChevronFade -- adds a single chevron to the array at the faded amount // ============================================================================================ void addChevronFade(int chevron, int intensity) { int led1 = 0; int led2 = 0; int led3 = 0; if(chevron == 0) { return; } if(chevron == 1){led1 = 6; led2 = led1+1; led3 = led1+2;} if(chevron == 2){led1 = 12; led2 = led1+1; led3 = led1+2;} if(chevron == 3){led1 = 19; led2 = led1+1; led3 = led1+2;} if(chevron == 4){led1 = 39; led2 = led1+1; led3 = led1+2;} if(chevron == 5){led1 = 46; led2 = led1+1; led3 = led1+2;} if(chevron == 6){led1 = 52; led2 = led1+1; led3 = led1+2;} if(chevron == 7){led1 = 26; led2 = led1+1; led3 = led1+2;} if(chevron == 8){led1 = 32; led2 = led1+1; led3 = led1+2;} if(chevron == 9){led1 = 59; led2 = 0; led3 = 1;} Leds[led1][0] = COLOR(CHEVRON_COLOR[0],CHEVRON_COLOR[1],CHEVRON_COLOR[2]); Leds[led1][1] = intensity; Leds[led2][0] = COLOR(CHEVRON_COLOR[0],CHEVRON_COLOR[1],CHEVRON_COLOR[2]); Leds[led2][1] = intensity; Leds[led3][0] = COLOR(CHEVRON_COLOR[0],CHEVRON_COLOR[1],CHEVRON_COLOR[2]); Leds[led3][1] = intensity; } // ============================================================================================ // Function dialGate // ============================================================================================ void dialGate() { //run a stargate dialing effect int dialSpeed = 5; int chevrons = 0; int dotPosition = 0; clearLeds(); updateLeds(); for (int i = 0; i <= 9; i++) { int dialAmount = random(20,59); //alter this to make it dial diffent Amounts int dialDirection = random(0,5); //do ifs to determine direction if (i != 0) { // dial first for(int k = 0; k <= LIGHT_INTENSITY; k=k+5)//fadedown sequence { LightChevron(i, k); LightChevron(9, k); delay(5); } } if (i != 9) { if (i != 0) { ChevronFadeDown(9); } setChevron(i); // delay(500); // Chevron Engaging, delay dialing while (dialAmount>0) { updateLeds(); // also turns off dot if (dialAmount != 0) //if we are still moving the dot { // Don't overwrite chevron leds if (Leds[dotPosition][0] == COLOR_BLACK) { if (dialAmount>1) { // Don't set the last dot befor chevron lights.set_color(dotPosition, LIGHT_INTENSITY, COLOR_WHITE); } } if(dialDirection >2) dotPosition++; //increase dot else dotPosition--; //decrease dot //checks if(dotPosition > 59) dotPosition=0; if(dotPosition < 0) dotPosition = 59; //delay(dialSpeed); dialAmount--; //reduce the distance to dial } } } } delay(500); } // ============================================================================================ // Function kawoosh // ============================================================================================ void kawoosh() { int fadeDelay = 50; // Flash //for (int c=0; c<2; c++) { for (int i=0; i= 0; k=k-5)//fadedown sequence { LightChevron(chevron, k); delay(fadeDelay); } } // ============================================================================================ // Function dialIn - all chevrons fade in // ============================================================================================ void dialIn() { int fadeDelay = 3; clearLeds(); for(int j=0; j < LIGHT_INTENSITY; j=j+5)//fadeup sequence { addChevronFade(1 ,j); addChevronFade(2 ,j); addChevronFade(3 ,j); addChevronFade(4 ,j); addChevronFade(5 ,j); addChevronFade(6 ,j); addChevronFade(7 ,j); addChevronFade(8 ,j); addChevronFade(9 ,j); delay(fadeDelay); updateLeds(); } delay(1000); } // ============================================================================================ // Function checkchime // ============================================================================================ void checkChime() { int sequence = random(0,6); // sequence = 6; if (1 || minute() == 0 && second() == 0) { switch(sequence) { case 1: dialGate(); dialFailSparks(); break; case 2: dialGate(); kawoosh(); wormhole(); wormholeEnd(); break; case 3: dialGate(); kawoosh(); wormhole(); wormholeUnstable(); break; case 4: dialIn(); kawoosh(); wormhole(); wormholeEnd(); break; case 5: dialIn(); kawoosh(); wormhole(); wormholeUnstable(); break; default: dialGate(); dialFail(); break; } } } // ============================================================================================ // Function printDigits // ============================================================================================ void printDigits(int digits) { // utility function for digital clock display: prints preceding colon and leading 0 Serial.print(":"); if(digits < 10) Serial.print('0'); Serial.print(digits); } // ============================================================================================ // Function printClockTime // ============================================================================================ void printClockTime(int hour, int minute, int second) { // digital clock display of the time Serial.print(hour); printDigits(minute); printDigits(second); Serial.print(" "); Serial.print(day()); Serial.print(" "); Serial.print(month()); Serial.print(" "); Serial.print(year()); Serial.println(); } // ============================================================================================ // Function processSyncMessage // ============================================================================================ void processSyncMessage() { // if time sync available from serial port, update time and return true while(Serial.available() >= TIME_MSG_LEN ){ // time message consists of header & 10 ASCII digits 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') ; // convert digits to a number } } setTime(pctime); // Sync Arduino clock to the time received on the serial port RTC.set(pctime); // set the RTC and the system time to the received value printClockTime(hour(), minute(), second()); } } } // ============================================================================================ // Function updateLeds // ============================================================================================ void RebootLedCheck(){ for (int c=0; c 0) { lights.set_color(c-1, LIGHT_INTENSITY, COLOR_BLACK); } delay(10); } lights.set_color(c, LIGHT_INTENSITY, COLOR_BLACK); } // ============================================================================================ // Function setup // ============================================================================================ void setup() { Serial.begin(9600); pinMode(relayPin, OUTPUT); setSyncProvider(RTC.get); // the function to get the time from the RTC randomSeed((unsigned int)RTC.get); EnumerateLeds(); //Enumerate lights on string to enable individual tick addressing RebootLedCheck(); } // ============================================================================================ // Function loop // ============================================================================================ void loop() { int h, m, s; static int lastminute=0; static int lastsecond=0; // Control Brightnew // LIGHT_INTENSITY = 64; if(Serial.available() ) { processSyncMessage(); } if(timeStatus() == timeNotSet) { Serial.println("waiting for sync message"); printClockTime(hour(), minute(), second()); delay (1000); } else { h = hour(); m = minute(); s = second(); if (lastsecond != s) { timerSec = millis(); lastsecond=s; if ((m == 5) && (s == 0)) { setSyncProvider(RTC.get); // set arduino clock from rtc } } // Do chome before updating the clock if (((m%15) == 0) && s == 0) { // On the hour and half hour checkChime(); } displayClock(h, m, s); // Output to Serial the time if (lastminute != m) { printClockTime(h, m, s); lastminute=m; } } }