a function-definition is not allowed here before '{' problem

If you properly indent your code (use tools -> auto format in the IDE), you will probably see where you went wrong. Each function definition should start at the beginning of a line.

Using a cellphone at this moment but it looks like loop() is missing a closing }.