Having completed adding the sound in my last Blog I decided to improve the LED part a little bit. I took three of the LEDs white wooden snowflakes shapes and fixed them to the front and sides of the box. Rather than just these three LEDS on and off I decided to fade them on and off. To do this I just connected the three LEDs in parallel and then the positive (the anode) to the +5V from the Nano and the negative (the cathode) to the D5 output of the Nano. The LEDs will all come on when D5 is driven low. To create the fade on and off effect I used pulse width modulation implemented as next for loops, as illustrated in the code fragment below. I used a function just to make it tidier. The value input into the function controls the maximum brightness achieved by the LED, which also controls the frequency of the LED slowly pulsing.
void pulse_WHITE(int brightness)
{
int move_index, LED_index;
for (move_index = 1; move_index < brightness; move_index++)
{
for (LED_index = 0; LED_index < LED_speed; LED_index++)
{
digitalWrite(LED1, LOW);
delayMicroseconds(move_index);
digitalWrite(LED1, HIGH);
delayMicroseconds(252- move_index);
} /* for */
} /* for */
for (move_index = brightness ; move_index > 0; move_index--)
{
for (LED_index = 0; LED_index < LED_speed; LED_index++)
{
digitalWrite(LED1, LOW);
delayMicroseconds(move_index);
digitalWrite(LED1, HIGH);
delayMicroseconds(252- move_index);
} /* for */
} /* for */
} /* pulse_WHITE
I added this to the Nano programme, adjusted when the sound should start playing back the recorded audio and tidied it up as best as I could. Below is the final video of the whole thing. I decided to add some clockwork Father Christmasses and Reindeers to provide that little bit extra enhancement and merriment(!).
It's been fun but I'm glad it's over now as the constant tuneless recorded singing was beginning to drive me mad!
Dubbie
Top Comments