Thursday, 17 September 2015

Penumbra: Code

Coding the sundial has been a challenge throughout this project.  Though I have basic knowledge in C++ from my undergraduate in Mechanical Engineering, I have had to adapt substantial amounts of code to get the sundial working as it should.  During the last module, I successfully managed to write a code for the sun progression during the day, and programmed the moon to rise and set at specific times for the week that it was on display.  For this prototype, my aim was to get the clock fully working, so that it calculates sun- and moon- rise and set itself based on the latitude and longitude of its position and its time zone.  I quickly found out that there is a code library for calculating sunrise and sunset times that I can easily call into my code, but moonrise and moonset require calculating from first principles.  Thankfully, someone else has worked out the maths, and all I need to do is combine it into one programme and then write the code to get my LEDs to respond.

Essentially, the programme in my sundial has four features; sunrise and set (1) , moonrise and set (2), change colour depending on the time of day (3)  (red at sunset, yellow/white at noon etc.) and, position the LEDs to cast a shadow for the time (i.e. 180° from normal clock hands).  This equates to a fairly large amount of code, and so mistake finding can be challenging.  Thankfully there is time before the exhibition begins to watch the clock and fix any errors that might occur.


1. Modelled from: Dawn Dusk Timer for LED lighting strips by Tom Loos
Using: TimeLord astronomical library by Michael Rice []
Using: Astronomical Night Lamp project code by Paulo Oliveira. []

2. Modelled from: Moon in my Room Code by “Slackmasterstan”

3. Modelled from: ds1307 RGB led day night cycle by Mccluskey1181