Digital Dice project

Hello all :slight_smile:
Having some trouble coming up with a clear path to my current project, which is a set of digital dice.
First I will give a quick overview of my project, then I will get to the problem I am having.

I am trying to build these dice with multiple modes. They are based on a full set of D&D dice, so the dice values I want to use are 2, 4, 6, 8, 10, 12, and 20. I am using a push button to switch dice modes, then a tilt switch to "roll" the dice.

I have already made this work fairly easily with a single 7 segment display, using the dot segment to indicate a double digit number. Now I am trying to use two 7 segment displays to show the results.
I am trying to do this without using any off-arduino ICs. I am using two common cathode 7 seg displays. I have the segments tied together and a couple of 2n2222a transistors on the common cathodes to handle the switching, giving a multiplex effect.

I would post my code, but nothing I have wrote has even come close to working. I have tried modifying some examples I have found to suit my project, but haven't had any luck there either. All of the samples I can find either use external ICs or they scroll a prepackaged message, rather than simply displaying the result of a random function.
I know how to get the random function to work, and how to tell the arduino where to set the result limits based on which dice mode you are in.
What I do not know is how to take that result, break it down into two separate digits, and display one number on each 7 seg.

If anyone has any suggestions, or can point me to some sample code that could be modified to get this working, I would greatly appreciate it!

Thanks in advance for any suggestions

I have some code that might help you at Google Code Archive - Long-term storage for Google Code Project Hosting.. Look for the library to control 2 seven segment displays. In wrote this as a utility piece to show numbers like you are trying to do.

Thanks for the response and the link to the list of libraries!
Looks like you have some useful ones in there :slight_smile:
couple of questions,
do you have any example code you could show me for handling the library?
is there a way to use the library if I don't have the HC595 IC? (I don't have any 72 series ICs, only some 74 series and a 4026, which I honestly haven't figured out how to combine, which is why I am trying to do this without the ICs at the moment.)
if I am understanding this correctly, your code uses the HC595 shift register to handle the output. The ICs I have are all TTL, and I don't know if they will do the same thing. I am nearly as new to electronics in general as I am to Arduino.
I can take a schematic and make it a working circuit, but I don't always know what is happening within the circuit.

Sorry for my lack of experience, I am learning as fast as I can, but the amount of available information can be an overload at times. Especially when you are trying to make a simple project like this. Many options, but none seem to fit the exact project design I have come up with.

What I do not know is how to take that result, break it down into two separate digits, and display one number on each 7 se

digit1 = number / 10;
digit2 = number % 10;

Have you got resistors in the segments?
You need to multiplex the display, that is first show one number and then the other rapidly so it looks like they are both on at the same time. There are plenty of examples in the playground and learning section for this.

I have some code but I am traveling and it is not with me. Back at home next week end and if you are still interested I can load that. Usually I have an examples folder with the library - was one not there?

Any 595 type IC will work. The LS and HC differ in the technology used to implement the IC, but they are functionally equivalent.

You should get familiar with these shift registers as they will allow you to expand the number of I/O while still only using 3 pins. Eventually you run out of pins otherwise. Lots of schematics on how to implement these, just look for them on this forum or Google. I think this is the easiest technique despite using some additional hardware.

The are other ways you can achieve this by multiplexing, but the software becomes more complicated and you may not always want to be updating the display as a major task for the CPU.

I have updated the MD_Seg7x2 library with an example on how to use it.

Thanks for alerting me to the fact the example was missing.

Wow, I have no idea how I missed those last two replies from marco_c and Grumpy_Mike...
I must have clicked on the thread and got distracted without checking down to the bottom or something.
Grumpy_Mike completely solved my last issue, and I had no idea it was even here.
I ended up going with what I call a "cop out" and using an 16x2 LCD with the liquidCrystal library. Made finishing the project a snap.
I really do like the LCD option, due to ease of use, and more display functionality, but a big part of me really wanted to make the 7segs work.

With this new information in hand, I will likely give it another go, and see if I can't get the 7seg working properly. Someone else on this forum is having similar issues, and if nothing else, I might be able to help him solve his 7seg problem if I can get mine working right.
I understood the multiplexing code structure I needed to use, but couldn't for the life of me figure out how to make it WORK.
Now I even feel a bit more foolish, because I have run into that same code to break down the answer into it's individual components, but couldn't seem to find it when I needed it.

I do intend on picking up some shift registers, but honestly, I am not patient when it comes to ordering parts online. When I have an idea, I like to just go with it, and see if I can make it work with on hand parts. The waiting for mail delivery kills me :stuck_out_tongue: It's kind of funny because I am usually a very patient person, but mail order just isn't me speed I guess.

Thank you very much for adding some sample code to work from marco_c, I will absolutely check it out, and make myself do a little online shopping. Will I also need a BDC or can I make this work with just the arduino and the shift register? I have seen youtube videos of people using shift registers, and a BDC together for multiplexing, but not sure I have seen anyone using a shift register alone. I do have a handful of 4026 ICs which might work, but I am not sure if the two are compatible. I am not even sure the 4026 isn't a BDC, but I don't think so, will have to look that one up again....

Thank you guys so much, and I am sorry I missed your posts! I like to at least respond to everyone who comments on a thread of mine. I figure it is common curtsey, if someone takes the time to provide information, I should respond in kind. I will have to be a bit more diligent in the future, don't want anyone thinking I ignored them, that is not the way to inspire people to lend you a hand when you need it.

Ok, I have been long winded enough, off to get some rest, got to work all this weekend, but monday and tuesday might find a little bit of new life breathed into my 7seg project!