Page 1 of 1

7-segment LED counter

Posted: Wed Jan 11, 2012 2:31 pm
by moof
Okay, so, I'm making a mock Halo assault rifle, and it's gonna have the firing sounds, LED muzzle flashing, a 7-seg ammunition counter and vibrating effects. It's already proving to be a very fun and rewarding project, but I have now reached very unknown territories: electronics and programming.
This USBDroid seems to be the way to go, as it surely supports all/most of these features.
But I am VERY new to this whole sketching thing, and it'll take me quite some time to get this thing together. SO!
Is there any chance of myself getting some help with this? Especially the ammunition counter and how to sync LEDs with sound. so far all i've been able to do is play with the onboard (D13) LED and make it flash a different speeds and intervals.
But i can tell this'll be a nice and challenging project! I would super appreciate any help that anyone can lend :)

Re: 7-segment LED counter

Posted: Thu Jan 12, 2012 12:42 am
by jonoxer
That sounds like a fun project. I think the best way to get help with it will be to break it down a bit and be specific about how you're doing it, so people can provide suggestions etc on specific parts of the project. Perhaps you could write a brief description of exactly how you imagine it working (what inputs it would use - switch as a trigger, for example?), what outputs, what will happen when the trigger is pulled (decrement counter, make sound?).

The step beyond that is to explain how you've connected things together.

Then if you're having trouble with something like how to drive the 7-segment display (just as an example), people can see how you're connecting it and give suggestions. Posting source code could help, too.

Also: pictures! I'd love to see what you've built so far.

Re: 7-segment LED counter

Posted: Thu Jan 12, 2012 1:36 pm
by moof
hiya jon!

it does make sense to break it into parts. my vision has:

- [input] main switch - turns whole thing on, engages light and 'weapon equip' sounds
- [input] momentary switch / "trigger" - linked to counter, muzzle flash and sounds
- [output] decreasing ammunition counter (7 seg) (32 rounds total)
- [output] firing sounds (speaker 1 - front-mounted)
- [output] dry clip and trigger sounds (speaker 2 - rear-mounted)
- [output] muzzle flash (super-bright LED) (synced to counter)
- [output] weighted DC motor (simulates vibration)
--- [NOTE] - trigger linked to the counter, firing sounds, muzzle and DC motor ---
- [output] changing lights on the side (green = has ammo, changes to red when the clip is empty)
- [input] reload system - rests the ammunition counter to 32 when a new clip is inserted
- [input] dummy bolt system - bolt is clipped back, and releases when the clip is dry, must be locked back forward so gun can fire new clip (release is an output, lock-forward is an input)
- [input] button/system change - button on the side which has system swap its operation as an assault rifle (32 rounds, fully automatic) to a battle rifle (36 rounds, 3 round burst/select fire) (this one isn't totally necessary, it would just be a lot of fun :D)

that's about as much as i've thought up. of course, some of it is a little overboard (like the actuated bolt), but i figured as soon as i took on this project i may as well make it as detailed as possible in every way.

so far i've done a first-draft pepakura paper model, i'll be starting on the first layer of resin tonight. this is just a simple test for me to get to understand fibreglass and painting, and this mock-up will most likely contain few electronics. at most, just the trigger, firing sounds, muzzle flash and reload system. no fancy rear speakers or actuator or side lights. just a simplified version.

the first part of the electronics i'd like to tackle is definitely the trigger and ammunition counter, as just about everything to do with the system relies on it. i really don't know the first thing about how i'm going to rig it. i know roughly where everything will fit into the rifle, and i have a drawn up version of it, i suppose that could do for the first picture :D
it's a little old, so a few of the features have been moved or changed for something else.


thanks so much for showing such interest, by the way! hopefully i an communicate my ideas and vision so well that i can get some help with this all from some fine people around here :D
you rock!

Re: 7-segment LED counter

Posted: Thu Jan 12, 2012 10:36 pm
by jonoxer
That's great, having a plan like that is a perfect starting point. It really helps lay out the various steps you'll need to take, and breaking it down into subsystems means you can work on it progressively and have wins early on rather than trying to build the whole thing as one epic project.

I'd definitely start with the trigger and counter, as you say. That's the core functionality. Everything else can be tacked on around that as you go. To start with I'd mock up just that part of it on a prototyping shield or something: all you need is two buttons (one for trigger, one for reload) and a 2-digit LED display. Perhaps wire up the display so it's a separate module on a small piece of veroboard or something, and use a ribbon cable to connect it to the shield. That way you can use it later in the gun itself.

For the software, version 1 will be quite simple. You just need a sketch with a setup that primes an "ammo" variable with 32, and an interrupt service routine (ISR) that does nothing but decrement it by 1 when invoked - which reminds me, connect the trigger and reload buttons to inputs with interrupts associated with them. You'll need some de-bounce on the trigger switch, though. In the main program loop it just needs to drive the displays using the current value from the ammo variable.

It sounds like you don't have much experience with Arduino yet so it's likely that the paragraph didn't mean very much to you. Don't worry, it's not as hard as it sounds. There are a few concepts in there (such as interrupts and debouncing, and probably multiplexing for the display driver) that may seem daunting, but once again if it's broken down into steps you'll get there in the end.

If I get a chance I'll mock up a quick skeleton of a sketch to get you started, but right now I'm ridiculously behind on preparing for Maker Faire, the Arduino Miniconf, and next week so I really shouldn't even be reading this forum!

Re: 7-segment LED counter

Posted: Fri Jan 13, 2012 2:36 am
by moof
Jon you're brilliant :D

i've seen a few mock ups of trigger and counting systems before: ... re=related ... own-timer/
these look alright, but i still don't really know how they're done. my uncle is an electrician, perhaps he can make some real sense of it :D

i'm getting to work on the pieces for the counter board and reload system. once it's working, i'll add in the light, and then the sounds. then slowly add more and more to it. is it likely that i will have more code than what the USB droid can fit? i know they can be 'stacked', but having multiples of them could make for some very confusing times ahead. but as you said, the more that i'll be around these things, the more i will understand of them :D

aha yeah at first the paragraph on sketching and programming didn't make a great deal of sense, but i'm reading more into it now and on the second read i am kinda grasping it :D you sure know your stuff!

mighty impressive work history there by the way :D you definitely get yourself up to scratch before lending a hand to little old me haha! just your support so far has already been completely awesome! good luck with your work!