How to randomley select input pins for Sonic Screwdriver LED display


I'm trying to build a sonic screwdriver

Because I'm a bit of a control freak I opted for a 8 way dial switch so I had control of what pattern would display when I put the power on.

I would now like it that when dial position 8 is selected (sw8) it would make a random selection and play a random selection from sw1 to sw7

I have received some guidance but I can not get it in to my original code with out a error. Its a "I don't know what I'm doing" error and I'm very sure its something very obvious and I'm hoping someone can advice me.

Unfortunately the script is too big to post here so I am including the links for git hub

This is my original code which works

and this is the one where I have tried to integrate the random function by introducing a case.

I would be greatful for anyone to point out the obvious for me

Many thanks in advance


the errors are

"Arduino: 1.8.2 (Windows 10), Board: "Adafruit Feather 32u4"

Build options changed, rebuilding all C:\Users\Jolen\OneDrive\Pictures\Documents\Arduino\sonic_proto_2_random_add_not_working\sonic_proto_2_random_add_not_working.ino: In function 'void setup()':

sonic_proto_2_random_add_not_working:91: error: a function-definition is not allowed here before '{' token



sonic_proto_2_random_add_not_working:574: error: expected '}' at end of input



exit status 1 a function-definition is not allowed here before '{' token

function-definition is not allowed here

Is when you try and define a function while already in a function. Normally this is due to a miss match in braces, most of the time you have missed a closing brace.

So put your cursor on the opening brace of the start of the function definition before the error and click, then the matching brace will be highlighted. You will find it is not where you thought it was.

Many thanks will stick in notepad ++ and give it a good going over, as I will admit I did only check the {} of the text that I put in, and as I stuck it in an area between }{ thought it would be ok.

...... got me thinking now.....


Hi Mike

Yes found one syntax error however, this has now opened the flood gate for a whole host of other errors
around the

void loop(std::uniform_int_distribution<>& dis, std::mt19937& gen)


again the code is too big to include here please find it at

Ive never come across the std:: function before and can’t work out how it works.

if there is any other advice you could give me on how to fix this I would be forever grateful.
Got to the point where I am so defeated I will be happy to pay for support

void loop(std::uniform_int_distribution<>& dis, std::mt19937& gen)

Was this written for an Arduino? I think not, the loop function does not accept variables.

    if (digitalRead(sw6) == LOW) doAction (7)
    if (digitalRead(sw7) == LOW) doAction (8)

Has no ; at the end of the lines.

Why has the code got a main function, these are not used for Arduinos. It is never referenced in the code so why is it there?

while (true)
        loop(dis, gen);

You can not call the loop function from another function.

std::mt19937 gen(rd());

That is not the way you define things in C. And being defined in the main function means it is not avaliable anywhere else.

Seeing as these lines

////////////////////////////////////////////////////////////////////////////////// random finish
      strip.begin();; // Initialize all pixels to 'off'

Follow a while 1 loop they will never be reached.

case 16: tardis(sw8); return

Missing ;

So you need to sort out how to use loop and main in your head, then do it in the code. I am assuming you bodjed this together from code you did not understand and did not write.