(not a ) switch case question (anymore...)

Jimmy60:
Yes you can but I don't see why you'd need to in this case.

It sounds to me like you select a mode once, then roll as often as you want. You could use an array to store how many sides each mode represents then use the mode as the index. I don't really see a need for a switch statement at all but you must have another idea.

// I see it like this

int mode = 0;
int dice[] = {2, 4, 6, 8, 10, 12, 20}; // or whatever your dice are

void loop(){

// Check the button and increment mode with rollover (0..6)

// if the device is shaken call the random function (I'll assume it's seeded)

int rollResult = random(dice[mode]); // you may want to add one to this

// display roll result

}

// there is quite a bit of code assumed in these comments I was really just demonstrating my logic

lol, you actually jumped ahead of me a bit :stuck_out_tongue:
right now, I am trying to work this out step by step. Then once I have it working and I know why it works the way it does, I was planning on implementing an array to shorten it and learn some short cuts in the code.
I did this with my last project (sonar distance sensor with LED bar graph and Piezzo buzzer tones) and felt like I learned much more by figuring out two totally different ways to "skin this cat"

I have a lot of plans on things I want to build with the Arduino, and I am trying to focus on making projects that teach me code that I can use later for some of these bigger projects.
makes toys now to learn off of, and when I know better what I am doing, start working on bigger more complicated projects for my home :slight_smile:
working on getting "off grid" step by step, and I can see many ways in which Arduino will make this much easier!
Plus I am a tinker-er at heart, and thoroughly enjoy the process.

Thanks for the advice, and when I get this one working today, I am sure I will be back to work out how to work in arrays and lose the switches :slight_smile: