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
CodeBug
  • Learn
  • Learning Center
  • STEM Academy
  • CodeBug
  • More
  • Cancel
CodeBug
Forum Help with a CodeBug Halloween Project
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join CodeBug to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 7 replies
  • Subscribers 10 subscribers
  • Views 1815 views
  • Users 0 members are here
  • codebug
  • halloween
  • ghostbusters
  • servo
Related

Help with a CodeBug Halloween Project

spannerspencer
spannerspencer over 9 years ago

S'up y'all!

 

Okay, I've been playing this one a little close to my chest, but I've reached that point where I could use a big of classic element14 community collaboration! image

 

I'm pretty well on with the build, but looking at my calendar (I'm off for a week, and then in Rome for the Maker Faire as soon as I get back) I'm starting to think that it'll be a bit close to the bone in terms of getting it finished for Halloween. So I was hoping I could solicit a bit of assistance from you guys, who are invariably better with coding than I am! I'm pretty good with the hardware, but I fumble when it comes time to code.

 

Here's the project, followed by a specification I was hoping you guys could help me out with for programming the actual CodeBug.

 

Ghostbusters Trap - Desk Lamp

I'm a sucker for the pop culture references, and I've been working building a ghost trap from Ghostbusters, complete with working trap door mechanism, LED lighting, a footswitch and a miniature smoke machine. You know the one I mean (WARNING: don't look directly into the trap):

image

This will all be run by a CodeBug, of course, and I've had a degree of success in proving its ability to drive a servo to open the doors. However, the code I used seems a bit flaky (sometimes works, sometimes doesn't -- not sure if it's the CodeBug or the servo, to be honest), and I'd rather it didn't run the servo backwards and forwards if you hold the button down.

 

The actual trap is coming along very nicely -- it's mostly built, with a 5V power supply, and the servo in place to open and close the trap doors. I've hacked up an e-cig cartomizer along with a small priming pump to create the fog (using a blend of water and sugar glycerine to create the smoke -- no nicotine or strange poisons involved!), and I've butchered three ultra-cheap LED torches to get a very neat array of 27 white LEDs, all of which I'll post in a build along when it's all up and running.

 

But here's where I could use a little assistance...

 

Who Ya Gonna Code?

My efforts to pull everything together into a reasonably optimised block of code for the CodeBug have been limited, and time's against me. So here's what I'd like the CodeBug to do, which I was hoping someone with better coding chops could help out with.

 

On Power Up

Right at the outset, the CodeBug should set the servo's PWM to 170 via Leg 1, which closes the trap doors. This is just in case the doors were open when the trap was powered off.

 

Turning It On

The trap is turned on using a latching foot switch (first press closes the switch, second press opens it again). I was thinking of using Leg 0 as an input, which is grounded by the latching foot switch for the duration of the trap being on (on = doors open, lights on). When the foot switch is pressed (or latched) the following should happen, in this order:

    • The fog machine is switched on for 5 seconds to generate a bit of atmospheric smoke. This will be achieved by switching a 5V relay and/or a transistor via Leg 3, as the fog machine takes more current than I suspect the CodeBug could handle (it gets a little hot).
    • After five seconds, the PWM for the servo is set to 60 (opening the trap doors on top), which outputs via Leg 1. (Leg1 is connected to the signal lead on the servo).
    • At the same time, the LEDs are switched on using a 5V relay and/or a transistor via Leg 4.
    • The following animation is displayed on the CodeBug: http://www.codebug.org.uk/explore/codebug/1240/

At this point, the LEDs remain lit, the above animation cycles, and the doors remain open until the foot switch is pressed again.

 

Turning It Off

Once the foot switch is unlatched by pressing it a second time, Leg 0 is no longer grounded and the following happens in this order.

    • The PWM for the servo is set to 170 (closing the trap doors on top), which outputs via Leg 1.
    • The fog machine is switched on for 5 seconds to generate a bit of more smoke that'll seep out of the trap (as if there was a ghost inside).
    • The LEDs are turned off.
    • The following animation is displayed on the CodeBug for around two minutes: http://www.codebug.org.uk/explore/codebug/1241/

 

If anyone's got the CodeBug kung fu to help me out with that, Zuul will bestow her blessings upon you! And so will I image

 

Ps. The full build along is coming soon!

  • Sign in to reply
  • Cancel

Top Replies

  • pettitda
    pettitda over 9 years ago +1
    www.codebug.org.uk/explore/codebug/1242/
  • pettitda
    pettitda over 9 years ago in reply to spannerspencer +1
    Super fast, but probably wrong. I assumed that leg 1 was a hardware PWM. Oops!
Parents
  • pettitda
    pettitda over 9 years ago

    I updated the code to count out the pwm width.  However, I'm a little fuzzy as to whether the servo needs a periodic refresh of the position.  Try it out and let me know how it works.

     

    http://www.codebug.org.uk/explore/codebug/1242/

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • spannerspencer
    spannerspencer over 9 years ago in reply to pettitda

    Sorry for the delay in replying -- been away image

     

    Thanks for the remix on this, but it doesn't seem to work, unfortunately (I don't think the legs count as buttons, when it's told to sleep until there's a change). Here's one I've been working on, that kinda works if I remove the display stuff. With that in, the servo doesn't move. That said, the initial code to position the servo at 170 doesn't do anything either, which I can't explain.

     

    Also, for some reason the whole thing becomes unresponsive (if I run it without the display stuff) if I don't press the button for a short while. Say 15 seconds or longer. Any thoughts on why it's not quite behaving as I think it should here?

     

    CodeBug – Servo Driver

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • spannerspencer
    spannerspencer over 9 years ago in reply to pettitda

    Sorry for the delay in replying -- been away image

     

    Thanks for the remix on this, but it doesn't seem to work, unfortunately (I don't think the legs count as buttons, when it's told to sleep until there's a change). Here's one I've been working on, that kinda works if I remove the display stuff. With that in, the servo doesn't move. That said, the initial code to position the servo at 170 doesn't do anything either, which I can't explain.

     

    Also, for some reason the whole thing becomes unresponsive (if I run it without the display stuff) if I don't press the button for a short while. Say 15 seconds or longer. Any thoughts on why it's not quite behaving as I think it should here?

     

    CodeBug – Servo Driver

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
  • pettitda
    pettitda over 9 years ago in reply to spannerspencer

    Everything I've seen seems to indicate that the PWM needs to be continuous (on the order of 1 pulse every 20 ms).  So, I'm guessing that's the problem.

     

    So, I'm thinking that we need to set up a timed loop.  For example, set it up to go through the loop every 75 ms.  Each time through the loop it does as much as it can and then does a pulse at the end.  We could set up a state machine to determine what to do during each loop and then delay to eat up any extra time remaining.  This will take some experimentation to make each loop an equal amount of time.  It would be a whole lot easier if there were interrupts or if there was a timer where we could query the clock value. 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • 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