Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Skull Clock 2018
- //This code is for personal and hobby use only. Commercial use and sale of items using this code
- //is expressly forbidden
- //Code is originally heavily based on Wordclockproject by Reddit user Wordclock
- //Original post by him here: https://imgur.com/a/sMtUi#ZDGCskd
- //His code to be found here: http://pastebin.com/fwnuVQ5z
- //Also inspired by Reddit User u/themakermonster
- //His post found here https://www.reddit.com/r/DIY/comments/95aj3s/how_i_turned_a_skull_into_a_clock/
- //Major modifications and improved features in this project include
- //TIMEZONE CHANGE Ability - for BST (UK Currently) but easily adjustable for any potential timezone
- //using the excellent Timezone library linked below. Just copy and paste your own timezone
- //from the library and change ''local = UK.toLocal(utc, &tcr);'' to the correct timezone
- //abbreviation.
- //AUTO EYE CALIBRATION - Original skull clock used stepper motors and kept time poorly, This project
- //uses S125 servos which can be set regardless of previous power cuts etc.
- //MOVING JAW using a third servo to open and close a spring loaded jaw.
- #include <DS3232RTC.h> //http://www.arduino.cc/playground/Code/Time
- #include <Time.h> //http://www.arduino.cc/playground/Code/Time
- #include <Timezone.h> //https://github.com/JChristensen/Timezone
- #include <Wire.h> //http://arduino.cc/en/Reference/Wire (supplied with the Arduino IDE)
- #include <TimeLib.h>
- #include <Streaming.h>
- #include <Servo.h>
- unsigned long seconds = 1000L;
- unsigned long minutes = seconds * 60;
- unsigned long hours = minutes * 60;
- //United Kingdom (London, Belfast)
- TimeChangeRule BST = {"BST", Last, Sun, Mar, 1, 60}; //British Summer Time
- TimeChangeRule GMT = {"GMT", Last, Sun, Oct, 2, 0}; //Standard Time
- Timezone UK(BST, GMT);
- //If TimeChangeRules are already stored in EEPROM, comment out the three
- //lines above and uncomment the line below.
- //Timezone myTZ(100); //assumes rules stored at EEPROM address 100
- TimeChangeRule *tcr; //pointer to the time change rule, use to get TZ abbrev
- time_t utc, local;
- Servo hourservo, minuteservo, jawservo; //create servos for attachment later
- int pos = 0; //variable to store servo position
- void setup(void)
- {
- Serial.begin(115200);
- setSyncProvider(RTC.get); // the function to get the time from the RTC
- if(timeStatus()!= timeSet)
- Serial.println("Unable to sync with the RTC");
- else
- Serial.println("RTC has set the system time");
- }
- void loop(void)
- {
- Serial.println();
- utc = now();
- printTime(utc, "UTC");
- local = UK.toLocal(utc, &tcr);
- printTime(local, tcr -> abbrev);
- delay(1000);
- static time_t tLast;
- time_t t;
- tmElements_t tm;
- //check for input to set the RTC, minimum length is 12, i.e. yy,m,d,h,m,s
- if (Serial.available() >= 12) {
- //note that the tmElements_t Year member is an offset from 1970,
- //but the RTC wants the last two digits of the calendar year.
- //use the convenience macros from Time.h to do the conversions.
- int y = Serial.parseInt();
- if (y >= 100 && y < 1000)
- Serial << F("Error: Year must be two digits or four digits!") << endl;
- else {
- if (y >= 1000)
- tm.Year = CalendarYrToTm(y);
- else //(y < 100)
- tm.Year = y2kYearToTm(y);
- tm.Month = Serial.parseInt();
- tm.Day = Serial.parseInt();
- tm.Hour = Serial.parseInt();
- tm.Minute = Serial.parseInt();
- tm.Second = Serial.parseInt();
- t = makeTime(tm);
- RTC.set(t); //use the time_t value to ensure correct weekday is set
- setTime(t);
- Serial << F("RTC set to: ");
- printTime(t, local);
- Serial << endl;
- //dump any extraneous input
- while (Serial.available() > 0) Serial.read();
- }
- }
- t = now();
- if (t != tLast) {
- tLast = t;
- if (second(t) == 0) {
- float c = RTC.temperature() / 4.;
- float f = c * 9. / 5. + 32.;
- Serial << F(" ") << c << F(" C ") << f << F(" F");
- }
- displayeyes(local);
- }
- }
- void displayeyes(time_t local) {
- if(minute(local) < 5) {
- showOnHour();
- } else if(minute(local) < 10) {
- showFivexxx();
- } else if(minute(local) < 15) {
- showTen();
- } else if(minute(local) < 20) {
- showQuarter();
- } else if(minute(local) < 25) {
- showTwenty();
- } else if(minute(local) < 30) {
- showTwentyFive();
- } else if(minute(local) < 35) {
- showHalfxxx();
- } else if(minute(local) < 40) {
- showThirtyFive();
- } else if(minute(local) < 45) {
- showForty();
- } else if(minute(local) < 50) {
- showFortyFive();
- } else if(minute(local) < 55) {
- showFifty();
- } else {
- showFiftyFive();
- }
- if(hour(local) == 0 || hour(local) == 12) {
- showHourTwelve();
- }
- else if(hour(local) == 1 || hour(local) == 13) {
- showHourOne();
- }
- else if(hour(local) == 2 || hour(local) == 14) {
- showHourTwo();
- }
- else if(hour(local) == 3 || hour(local) == 15) {
- showHourThree();
- }
- else if(hour(local) == 4 || hour(local) == 16) {
- showHourFour();
- }
- else if(hour(local) == 5 || hour(local) == 17) {
- showHourFive();
- }
- else if(hour(local) == 6 || hour(local) == 18) {
- showHourSix();
- }
- else if(hour(local) == 7 || hour(local) == 19) {
- showHourSeven();
- }
- else if(hour(local) == 8 || hour(local) == 20) {
- showHourEight();
- }
- else if(hour(local) == 9 || hour(local) == 21) {
- showHourNine();
- }
- else if(hour(local) == 10 || hour(local) == 22) {
- showHourTen();
- }
- else if(hour(local) == 11 || hour(local) == 23) {
- showHourEleven();
- }
- else {
- showHourTwelve();
- }
- if(hour(local) == 8 || hour(local) == 20 && minute(local)==0) {
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- delay(1 * minutes);
- }
- if(hour(local) == 9 || hour(local) == 21 && minute(local)==0) {
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- delay(1 * minutes);
- }
- if(hour(local) == 10 || hour(local) == 22 && minute(local)==0) {
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- delay(1 * minutes);
- }
- if(hour(local) == 11 && minute(local)==0) {
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- delay(1 * minutes);
- }
- if(hour(local) == 12 && minute(local)==0) {
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- delay(1 * minutes);
- }
- if(hour(local) == 13 && minute(local)==0) {
- openjaw();
- delay(1 * minutes);
- }
- if(hour(local) == 14 && minute(local)==0) {
- openjaw();
- openjaw();
- delay(1 * minutes);
- }
- if(hour(local) == 15 && minute(local)==0) {
- openjaw();
- openjaw();
- openjaw();
- delay(1 * minutes);
- }
- if(hour(local) == 16 && minute(local)==0) {
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- delay(1 * minutes);
- }
- if(hour(local) == 17 && minute(local)==0) {
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- delay(1 * minutes);
- }
- if(hour(local) == 18 && minute(local)==0) {
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- delay(1 * minutes);
- }
- if(hour(local) == 19 && minute(local)==0) {
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- openjaw();
- delay(1 * minutes);
- }
- }
- void showOnHour() {
- minuteservo.attach(9);
- minuteservo.writeMicroseconds(2000);
- delay(2000);
- minuteservo.detach();
- }
- void showFivexxx() {
- minuteservo.attach(9);
- minuteservo.writeMicroseconds(1950);
- delay(2000);
- minuteservo.detach();
- }
- void showTen() {
- minuteservo.attach(9);
- minuteservo.writeMicroseconds(1890);
- delay(2000);
- minuteservo.detach();
- }
- void showQuarter() {
- minuteservo.attach(9);
- minuteservo.writeMicroseconds(1815);
- delay(2000);
- minuteservo.detach();
- }
- void showTwenty() {
- minuteservo.attach(9);
- minuteservo.writeMicroseconds(1737);
- delay(2000);
- minuteservo.detach();
- }
- void showTwentyFive() {
- minuteservo.attach(9);
- minuteservo.writeMicroseconds(1670);
- delay(2000);
- minuteservo.detach();
- }
- void showHalfxxx() {
- minuteservo.attach(9);
- minuteservo.writeMicroseconds(1570);
- delay(2000);
- minuteservo.detach();
- }
- void showThirtyFive() {
- minuteservo.attach(9);
- minuteservo.writeMicroseconds(1485);
- delay(2000);
- minuteservo.detach();
- }
- void showForty() {
- minuteservo.attach(9);
- minuteservo.writeMicroseconds(1395);
- delay(2000);
- minuteservo.detach();
- }
- void showFortyFive() {
- minuteservo.attach(9);
- minuteservo.writeMicroseconds(1310);
- delay(2000);
- minuteservo.detach();
- }
- void showFifty() {
- minuteservo.attach(9);
- minuteservo.writeMicroseconds(1220);
- delay(2000);
- minuteservo.detach();
- }
- void showFiftyFive() {
- minuteservo.attach(9);
- minuteservo.writeMicroseconds(1120);
- delay(2000);
- minuteservo.detach();
- }
- void showHourOne() {
- hourservo.attach(10);
- hourservo.writeMicroseconds(1950);
- delay(2000);
- hourservo.detach();
- }
- void showHourTwo() {
- hourservo.attach(10);
- hourservo.writeMicroseconds(1890);
- delay(2000);
- hourservo.detach();
- }
- void showHourThree() {
- hourservo.attach(10);
- hourservo.writeMicroseconds(1800);
- delay(2000);
- hourservo.detach();
- }
- void showHourFour() {
- hourservo.attach(10);
- hourservo.writeMicroseconds(1737);
- delay(2000);
- hourservo.detach();
- }
- void showHourFive() {
- hourservo.attach(10);
- hourservo.writeMicroseconds(1670);
- delay(2000);
- hourservo.detach();
- }
- void showHourSix() {
- hourservo.attach(10);
- hourservo.writeMicroseconds(1570);
- delay(2000);
- hourservo.detach();
- }
- void showHourSeven() {
- hourservo.attach(10);
- hourservo.writeMicroseconds(1485);
- delay(2000);
- hourservo.detach();
- }
- void showHourEight() {
- hourservo.attach(10);
- hourservo.writeMicroseconds(1400);
- delay(2000);
- hourservo.detach();
- }
- void showHourNine() {
- hourservo.attach(10);
- hourservo.writeMicroseconds(1310);
- delay(2000);
- hourservo.detach();
- }
- void showHourTen() {
- hourservo.attach(10);
- hourservo.writeMicroseconds(1220);
- delay(2000);
- hourservo.detach();
- }
- void showHourEleven() {
- hourservo.attach(10);
- hourservo.writeMicroseconds(1150);
- delay(2000);
- hourservo.detach();
- }
- void showHourTwelve() {
- hourservo.attach(10);
- hourservo.writeMicroseconds(2000);
- delay(2000);
- hourservo.detach();
- }
- void openjaw() {
- jawservo.attach(11);
- jawservo.writeMicroseconds(1350);
- delay(1500);
- jawservo.writeMicroseconds(1060);
- delay(1500);
- }
- //Function to print time with time zone
- void printTime(time_t t, char *tz)
- {
- sPrintI00(hour(t));
- sPrintDigits(minute(t));
- sPrintDigits(second(t));
- Serial.print(' ');
- Serial.print(dayShortStr(weekday(t)));
- Serial.print(' ');
- sPrintI00(day(t));
- Serial.print(' ');
- Serial.print(monthShortStr(month(t)));
- Serial.print(' ');
- Serial.print(year(t));
- Serial.print(' ');
- Serial.print(tz);
- Serial.println();
- }
- //Print an integer in "00" format (with leading zero).
- //Input value assumed to be between 0 and 99.
- void sPrintI00(int val)
- {
- if (val < 10) Serial.print('0');
- Serial.print(val, DEC);
- return;
- }
- //Print an integer in ":00" format (with leading zero).
- //Input value assumed to be between 0 and 99.
- void sPrintDigits(int val)
- {
- Serial.print(':');
- if(val < 10) Serial.print('0');
- Serial.print(val, DEC);
- }
Add Comment
Please, Sign In to add comment