I am very new to the arduino world and am struggling to recover that one high school programing class I took 8 years ago.

I'm trying to write a program to help roll dice for a tabletop game named 'shadowrun' and then display the results on some LED's. It is supposed to read the number of dice the user is supposed to roll and then roll that many six sided die. The program works great for single digit numbers, but when I enter 11, for instance, it rolls two sets of one dice each. or for 13 it rolls one dice then a set of three.

The program does some extra stuff specific to 'shadowrun' rules which you can ignore. If someone has an easy solution or just wants to provide some handy tips on my code let me know. My only request is to keep it simple I'm still pretty green.

The easy "on-the-spot" solution would be to always send two digits instead of one. So you will always read two digits, if it's a one digit number, send 0 and the number.

For example for 13 you will 1 and 3for 8 you will send 0 and 8

That solution won't scale well though (if you want to roll a dice of 6 digit numbers ). So you might use some kind of terminator character at the end of each number, which will tell you that the number is complete.

edit: me - dumb*ss You can simply send your number as a byte that way you can have up to 255 dice at once. I don't know which language you are using on the computer end so can't really help you there, but when you read the number don't subtract the '0' char and what you'll receive will be the byte you have sent.

This code uses a handshake method. Start and stop characters are used, so the serial will start reading when it gets chr(10), and it stop's reading when it gets chr(13). Whatever is in between you add together using "code[bytesread] = val;"

You should be able to adapt this to suit your needs, otherwise there's plenty of other material around the forums for doing the same job.