Howto calculate Swatch internet time using PHP

date_default_timezone_set("UTC");

function internetMicrotime($get_as_float = false)
{
  //Calculate Swatch internet time

  //Get unix timestamp for the beginning of the this day
  //With 1 hour offset for the Swatch internet timezone
  //(Biel Meantime (BMT): UTC+1 without DST)
  $beginningOfDay = mktime(-1, 0, 0);

  //Calulate total SI seconds in a day
  $totalSIsecondsInDay = 60 * 60 * 24;

  //Define how many beats there are in a day
  $totalBeatsInDay = 1000;

  //SI seconds elapsed since the beginning of the day
  $secondsElapsed = microtime(true) - $beginningOfDay;

  //Calculate factor on how far this day has elapsed
  $factor = $secondsElapsed / $totalSIsecondsInDay;

  //Now calulate the decimal time using
  //the total decimal seconds and the factor
  $internetTime = $totalBeatsInDay *  $factor;

  if ($get_as_float)
    return $internetTime;
  else
    return floor($internetTime);
}

print internetMicrotime(true)."\n";  //495.81894635326
print internetMicrotime(false)."\n"; //495
print date("H:i:s")."\n";            //10:53:58

Further reading: http://www.swatch.com/zz_en/internettime/

Howto calculate local hexadecimal time using PHP

date_default_timezone_set("Europe/Amsterdam");

function hexadecimalTime()
{
  //Calculate hexadecimal local time

  //Get unix timestamp for the beginning of this day
  $beginningOfDay = mktime(0, 0, 0);

  //Calculate total SI seconds in a day
  $totalSIsecondsInDay = 60 * 60 * 24;

  //Define how many hexadecimal seconds there are in a day
  $totalHexadecimalSecondsInDay = 0xFFFF;

  //SI seconds elapsed since the beginning of the day
  $secondsElapsed = microtime(true) - $beginningOfDay;

  //Calculate factor on how far this day has elapsed
  $factor = $secondsElapsed / $totalSIsecondsInDay;

  //Now calculate the hexadecimal time using
  //the total hexadecimal seconds and the factor
  $hexadecimalTime = $totalHexadecimalSecondsInDay *  $factor;

  return dechex(floor($hexadecimalTime));
}

print hexadecimalTime()."\n"; //85fc
print date("H:i:s")."\n";     //12:33:41

Howto calculate local decimal time using PHP

date_default_timezone_set("Europe/Amsterdam");

function decimalMicrotime($get_as_float = false)
{
  //Calculate decimal local microtime

  //Get unix timestamp for the beginning of this day
  $beginningOfDay = mktime(0, 0, 0);

  //Calculate total SI seconds in a day
  $totalSIsecondsInDay = 60 * 60 * 24;

  //Define how many decimal seconds there are in a day
  $totalDecimalSecondsInDay = 100000;

  //SI seconds elapsed since the beginning of the day
  $secondsElapsed = microtime(true) - $beginningOfDay;

  //Calculate factor on how far this day has elapsed
  $factor = $secondsElapsed / $totalSIsecondsInDay;

  //Now calculate the decimal time using
  //the total decimal seconds and the factor
  $decimalTime = $totalDecimalSecondsInDay *  $factor;

  if ($get_as_float)
    return $decimalTime;
  else
    return floor($decimalTime);
}

print decimalMicrotime(true);  //89580.109306784
print decimalMicrotime(false); //89580
print date("H:i:s");           //21:29:57

UNIX Epoch 7-segment led clock.

I am busy testing a modular 7-segment led clock. Each module can contain up to 3 pieces of 7-segment led displays driven by a 74HC595D shift register. Modules can be combined into larger strings.

In the video the modules are driven by an Arduino Nano 3.0 using the SPI interface. The Arduino is connected using USB to a computer which is running a C# program that instructs the Arduino to display a certain number at a specified position. In the video the UNIX time is displayed.

The goal is to connect the display modules to a server which is connected to the GPS atomic clock and display the exact time.

Portable slow whoop alarm for training purposes

Used slow whoop alarms can be recycled into a portable version by adding a switch, a battery and a project box.

This portable version is useful during emergency response training. Persons attending the training can get used to the slow whoop sound and recognizing the alarm when used in real hazard situations.

The slow whoop alarm used in this schematic needs 12V or 24V to work. A simple PP3 9V block battery also works perfect, even when the battery is nearly empty there is still some sound. This slow whoop alarm needs about 10mAh of current, this means that the portable version can be used for 50 hours continuously. When using it for 30 seconds each training, this device can be used for 6000 training sessions. However, the battery will probably die from age before all the energy is used.