An interactive Advent calendar

Mastermind

A central control unit, or mastermind, keeps all of the electronic components working together properly. The primary function of the unit is to sit and wait for the button to be pressed and start the programs and scripts for the relevant date.

Some components, like the audio player, need to start asynchronously in a discrete process. The master script (mcp.pl; Listing 4) manages other processes, such as the control for the stepper motors, directly. Once the script starts up, it will run continuously for 24 days. You should start it in an SSH shell by entering

nohup perl mcp.pl &

Listing 4

Master Script

01 do {
02    $tag=(localtime(time))[3];
03    $tag = $tag < 10 ? $tag = "0".$tag : $tag;
04    print "Waiting for button";
05    do {
06       open($t,"gpio read 10 |");
07       $i=<$t>;sleep 1;
08    } while($i=~m/0/);
09    print "Current day: $tag\n";
10    system ("nohup ogg123 ./music/$tag* &");
11    print "Music started\n";
12    system ("gpio write 11 1");
13    system ("gpio write 11 0");
14    system ("gpio write 11 1");
15    system ("gpio write 11 0");
16    print "Day set\n";
17    system ("nohup perl ./led/$tag.pl &");
18    sleep 25;
19    system ("perl ./servo/$tag*");
20    sleep 1000;
21 } while($tag<=24);

You will find all of the steps necessary for initializing the hardware in the script init.pl file (Listing  5), which can be executed, for example, after a reboot.

Listing 5

Initializing Hardware

01 system("gpio load i2c");
02 print "I2C Driver loaded\n";
03 system("gpio mode 11 out");
04 system("gpio write 11 0");
05 system("gpio mode 10 in");
06 print "IO Ports configured\n";
07 system("sudo ~/PiBits/ServoBlaster/user/servod --p1pins=7,11,12,15 --pcm");
08 print ("ServoBlaster started\n");

Festive and Chic

The aesthetics of the framework used for the calendar are admittedly somewhat unique for the Christmas season, but it is easy to change the appearance for something more festive and elegant simply by using some holiday decorations (Figure  6).

Figure 6: The Advent calendar might start out as a bit of an ugly duckling, but it is easy to transform for the holiday season.

Buy this article as PDF

Express-Checkout as PDF

Pages: 6

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content