element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Merry Boxes & LEDs
  • Challenges & Projects
  • Project14
  • Merry Boxes & LEDs
  • More
  • Cancel
Merry Boxes & LEDs
Blog JackBox #6 : The Completed Article
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Merry Boxes & LEDs to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: dubbie
  • Date Created: 9 Jan 2019 5:27 PM Date Created
  • Views 4003 views
  • Likes 16 likes
  • Comments 17 comments
  • merryboxesledsch
  • holidayspecial19ch
  • leds.
  • buildapresentch
Related
Recommended

JackBox #6 : The Completed Article

dubbie
dubbie
9 Jan 2019

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(!).

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

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

  • Sign in to reply

Top Comments

  • DAB
    DAB over 6 years ago +6
    Fun project for the holidays. Easily replicated for any specific holiday or event you want. DAB
  • ntewinkel
    ntewinkel over 6 years ago +5
    So cool! I like that you hit all the targets: it's merry, it's a box, it has LEDs. The Santas and reindeer added a total bonus to complete the effect -Nico
  • three-phase
    three-phase over 6 years ago +4
    Good to see the project finished Kind regards
  • shabaz
    shabaz over 6 years ago in reply to dubbie

    Awesome, thanks!!

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • dubbie
    dubbie over 6 years ago in reply to shabaz

    Shabaz,

     

    I thought I had put the code up somewhere, but it was probably only bits of it. The full programme is listed below. It's not the prettiest code in the world, but I generally do bottom-up coding which can leave things a bit ragged. I also follow my early programming experience of laying out programmes from my Pascal and assembly days. I like to keep it simple with only one active statement on a line.

     

    Dubbie

     

    /

    * 
     Arduino Jack in the Box : Merry Boxes and LEDs
     Uses a servo to open a box from the inside and display
     some LEDs
     Dubbie
    
     3rd Jan'19
     Just for Fun
    */
    #include <Servo.h>
    #define start 1
    #define end 70
    #define stepdelay 50
    #define playback 4
    #define LED1 5
    #define LED_speed 60
    #define max_bright 250
    Servo lidopen;
    void setup() 
    {
      lidopen.attach(3);  // attaches the servos
      pinMode(playback, OUTPUT);
      pinMode(LED1, OUTPUT);
    }
    void loop()
    {
    int lidvalue;
    int replay;
    
      digitalWrite(playback, HIGH); 
      lidvalue = 5;
      lidopen.write(lidvalue); 
      pulse_WHITE(max_bright);
      
      while(1)
        { 
        digitalWrite(playback, LOW);
        delay(100);
        digitalWrite(playback, HIGH);
        delay(100);
      
      for (lidvalue = start; lidvalue <= end; lidvalue++) 
        { 
          lidopen.write(lidvalue);                    
          delay(stepdelay);                       
        } /* for */
      pulse_WHITE(max_bright/2);
        digitalWrite(playback, LOW);
        delay(100);
        digitalWrite(playback, HIGH);
        delay(100);
        
      for (lidvalue = end; lidvalue >= start; lidvalue--) 
        { 
          lidopen.write(lidvalue);                    
          delay(stepdelay);                       
        } /* for */
      } /* while */
    } /* loop */
    
    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 */

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz over 6 years ago

    Awesome project! Mechanical projects are always fun : )

    I may have missed it, is the final source code going to be published somewhere?

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • dubbie
    dubbie over 6 years ago in reply to balearicdynamics

    Enrico,

     

    Thank you for this support. I wasn't sure it was going to get finished at times. Trying to understand what is going on inside a closed box was quite surreal.

     

    Dubbie

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • dubbie
    dubbie over 6 years ago in reply to tonydbeck

    Tony,

     

    Thanks. It put many smiles on my face, especially when the lid popped up and down for the first time, especially when it snapped shut when reset!

     

    Dubbie

    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube