Error messages please help :)

Hi I am making a roller coaster control panel using the Leonardo board. I have got an error but I was wondering if someone could check the code as well. The board is designed to work for a website called ride sims and each push button will send a key stroke to the PC. I have got the following error message;

:50: error: a function-definition is not allowed here before ‘{’ token
void loop() {
^
hopefully_final_panel_code:207: error: expected ‘}’ at end of input
}
^
exit status 1
a function-definition is not allowed here before ‘{’ token

Here is my script:

#include <Keyboard.h>

//Set Pin Values for buttons
int endofday;
int reset;
int switch1;
int switch2;
int switch3;
int switch4;
int sstop;
int preshow;
int estop;
int gates;
int restraints;
int tilt;
int stationselect;
int launch;
int dispatch;

// Initial variable states
int gateHX;
int restraintHX;
int selectorHX;
int estopHX;
int tiltHX;
int rcsenable;
int stationstopmode = 0; // S Stop is off
int disrdy = false; //dispatch ready is false

void setup() {

// Set buttons pinmodes
pinMode(endofday, INPUT_PULLUP);
pinMode(reset, INPUT_PULLUP);
pinMode(switch1, INPUT_PULLUP);
pinMode(switch2, INPUT_PULLUP);
pinMode(switch3, INPUT_PULLUP);
pinMode(switch4, INPUT_PULLUP);
pinMode(sstop, INPUT_PULLUP);
pinMode(preshow, INPUT_PULLUP);
pinMode(estop, INPUT_PULLUP);
pinMode(gates, INPUT_PULLUP);
pinMode(restraints, INPUT_PULLUP);
pinMode(tilt, INPUT_PULLUP);
pinMode(stationselect, INPUT_PULLUP);
pinMode(launch, INPUT_PULLUP);
pinMode(dispatch, INPUT_PULLUP);

void loop() {
// Set variables for button states

int endofdayPOS = digitalRead(endofday);
int resetPOS = digitalRead(reset);
int switch1POS = digitalRead(switch1);
int switch2POS = digitalRead(switch2);
int switch3POS = digitalRead(switch3);
int switch4POS = digitalRead(switch4);
int sstopPOS = digitalRead(sstop);
int preshowPOS = digitalRead(preshow);
int estopPOS = digitalRead(estop);
int gatePOS = digitalRead(gates);
int restraintPOS = digitalRead(restraints);
int tiltPOS = digitalRead(tilt);
int selectorPOS = digitalRead(stationselect);
int launchPOS = digitalRead(launch);
int dispatchPOS = digitalRead(dispatch);

// RCS MODE: Enabled

// sets the system to enabled RCS Mode anytime RCSenable variable is high and estop is high
if (restraintPOS == HIGH){
disrdy = false;}
else if (gatePOS == HIGH){
disrdy = false;}
else
disrdy = true;

// End Of Day function control
if (endofdayPOS == LOW){
Keyboard.end();} // Keyboard disabled
if (endofdayPOS == HIGH){
Keyboard.begin()} // Key strokes can be sent to PC

// Station Stop function control
if (sstopPOS == LOW){
stationstopmode = 1;} // Station Stop is ON
if (sstopPOS == HIGH){
stationstopmode = 0;} // Station stop is off

// Restraint function control
if (restraintHX != restraintPOS){
delay (100);}
if (restraintPOS == LOW){ // closed pos
Keyboard.press(KEY_DOWN_ARROW);
delay (100);
Keyboard.releaseAll();
restraintHX = restraintPOS;}
else{
Keyboard.press(KEY_UP_ARROW); // Open pos
delay (100);
Keyboard.releaseAll();
restraintHX = restraintPOS;}

// Gate function control
if (gateHX != gatePOS){
delay (100);}
if (gatePOS == LOW){ // If switch is in the closed position
Keyboard.press(KEY_LEFT_ARROW);
delay (100);
Keyboard.releaseAll();
gateHX = gatePOS;}
else{
Keyboard.press(KEY_RIGHT_ARROW);
delay (100);
Keyboard.releaseAll();
gateHX = gatePOS;}

// Selector function control
if (selectorHX != selectorPOS){
delay (100);}
if (selectorPOS == LOW){ // If switch is in the ‘one’ position
Keyboard.press(KEY_LEFT_ARROW);
delay (100);
Keyboard.releaseAll();
selectorHX = selectorPOS;}
else{
Keyboard.press(KEY_RIGHT_ARROW); // If switch is in the ‘two’ position
delay (100);
Keyboard.releaseAll();
selectorHX = selectorPOS;}

// Dispatch function control
if (dispatchPOS == LOW && stationstopmode == 0 && disrdy == true);{
Keyboard.press(’ ');
delay (100);
Keyboard.releaseAll();}

// Auto-stop when dispatch not ready
if (disrdy == false){
if (dispatchPOS == LOW)
Keyboard.press(‘s’);
delay (100);
Keyboard.releaseAll();
estopHX = LOW;
rcsenable = LOW;}

// RCS Mode: E-Stop
if (estopPOS == LOW){
rcsenable = LOW;}

if (estopPOS == LOW && estopHX == HIGH){
Keyboard.press(‘s’);
estopHX = estopPOS;
delay (100);
Keyboard.releaseAll();}

// RCS Mode: Reset
if (resetPOS == LOW && estopPOS == HIGH && rcsenable == LOW){
rcsenable = HIGH;
estopHX = estopPOS;
Keyboard.press(‘r’);
delay (100);
Keyboard.releaseAll();}

//Preshow doors/start function
if (preshowPOS == LOW){
Keyboard.press(KEY_RETURN);
delay (100);
Keyboard.releaseAll();}

// Switch functions
if (switch1POS == LOW){
Keyboard.press(‘1’);
delay (100);
Keyboard.releaseAll();}

if (switch2POS == LOW){
Keyboard.press(‘2’);
delay (100);
Keyboard.releaseAll();}

if (switch3POS == LOW){
Keyboard.press(‘3’);
delay (100);
Keyboard.releaseAll();}

if (switch4POS == LOW){
Keyboard.press(‘4’);
delay (100);
Keyboard.releaseAll();}

// launch function
if (launchPOS == LOW && stationstopmode == 0){
Keyboard.press(‘l’);
delay (100);
Keyboard.releaseAll();}

// Tilt function
if (tiltPOS == HIGH && tiltHX == LOW && stationstopmode == 0){
Keyboard.release(KEY_RETURN);
tiltHX = tiltPOS;}
else{
Keyboard.press(KEY_RETURN);}

}

Your help would be greatly appreciated.

Thanks :slight_smile:

(deleted)

Please use code tags instead of quote; easier to read, easier to copy

...
...
void setup() {

  ...
  ...

  void loop() {
    ...
    ...

If you auto-format your code in the IDE (T), you can easily see what is wrong. Functions should always start at the beginning of a line. If they don’t, you (usually) have a mismatch in ‘{’ and ‘}’.

loop() does not start at the beginning of a line, in this case because you did not close setup() with a ‘}’.

Thank You ! I have fixed it and no longer have any errors! Thanks! :)