Error Code Help

while working on some code i got this error code. Im using a mac can you help me?

Arduino: 1.6.8 (Mac OS X), Board: “Arduino/Genuino Uno”

/Users/YungBeej/Documents/Arduino/sketch_mar11c/sketch_mar11c.ino: In function ‘void __vector_9()’:
sketch_mar11c:117: error: ‘displayActiveRow’ was not declared in this scope
displayActiveRow();
^
/Users/YungBeej/Documents/Arduino/sketch_mar11c/sketch_mar11c.ino: In function ‘void loop()’:
sketch_mar11c:126: error: a function-definition is not allowed here before ‘{’ token
void displayActiveRow() {
^
sketch_mar11c:522: error: expected ‘}’ at end of input
}
^
sketch_mar11c:522: error: expected ‘}’ at end of input
exit status 1
‘displayActiveRow’ was not declared in this scope

This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.

Hello. Post your full sketch, using code tags (the </> icon).

Looks like you're trying to define the function displayActiveRow() inside loop() but that's illegal.... you can't define a function inside a function.

As PaulRB points out, you really ought to post the sketch.

/*
  TODO;
  Flash winning chips
  Intro Mode (automatically drop chips in both colours until a start button is pressed.)
  Find appropriate attributions for inspriation/borrowed code.
  ??Scrolling Text??
*/

#define DEBUG 0
#define BENCH 0

// Pins of CD4021BE
#define latchPin4021 15 // analog 1
#define dataPin4021 16 // analog 2
#define clockPin4021 14 // analog 0

// Pins on 74HC595
#define latchPin595 11
#define clockPin595 10
#define dataPin595 9

#define piezo 8 // piezo pin

// Button Pins on CD4021BE
#define SW_COL7 6
#define SW_COL6 5
#define SW_COL5 4
#define SW_COL4 3
#define SW_COL3 2
#define SW_COL2 1
#define SW_COL1 0

// status led pins
#define STATUS_RED 18
#define STATUS_GRN 17
#define STATUS_BLU 19

#define dropTime 50 // speed of dropping 'chips'
#define MAX_COLS 7 // Columns of Matrix
#define MAX_ROWS 6 // Rows of Matrix
#define REDPLAYER 0 // Index of red player led state
#define GRNPLAYER 1 // Index of green player led state

byte pinForRow[6] = {2, 3, 4, 5, 6, 7}; // Pins for rows (through ULN2803A)
byte buttonList[7] = {SW_COL1, SW_COL2, SW_COL3, SW_COL4, SW_COL5, SW_COL6, SW_COL7};

byte buttons = B1111111; // Default state of buttons
byte lastButtonState = buttons;

byte softPrescaler = 0; // not too sure :)
byte refreshRate = 15;
byte activeRow = 0;
byte startFlag = 0;
byte x;
unsigned long last = 0; // for debouncing buttons
unsigned long before = 0; // for debugging/benchmarking

boolean curPlayer = REDPLAYER; // currently active player
boolean easterEgg = false; // are we showing the easter egg? ;)

byte ledState[2][MAX_ROWS] = { // Current State of Matrix
  { B0000000,  // Red State
    B0000000,
    B0000000,
    B0000000,
    B0000000,
    B0000000
  },

  { B0000000, // Green State
    B0000000,
    B0000000,
    B0000000,
    B0000000,
    B0000000
  }
};

void setup() {
  // Calculation for timer 2
  // 16 MHz / 8 = 2 MHz (prescaler 8)
  // 2 MHz / 256 = 7812 Hz
  // soft_prescaler = 15 ==> 520.8 updates per second
  // 520.8 / 8 rows ==> 65.1 Hz for the complete display
  TCCR2A = 0;           // normal operation
  TCCR2B = (1 << CS21); // prescaler 8
  TIMSK2 = (1 << TOIE2); // enable overflow interrupt

  //Start Serial for debuging purposes
  Serial.begin(9600);
  pinMode (13, OUTPUT); // on board LED
  pinMode (16, INPUT_PULLUP); // button connecting pin to Gnd
  pinMode(latchPin595, OUTPUT);
  pinMode(clockPin595, OUTPUT);
  pinMode(dataPin595, OUTPUT);

  pinMode(latchPin4021, OUTPUT);
  pinMode(clockPin4021, OUTPUT);
  pinMode(dataPin4021, INPUT);

  pinMode(piezo, OUTPUT);

  pinMode(STATUS_RED, OUTPUT);
  pinMode(STATUS_GRN, OUTPUT);
  pinMode(STATUS_BLU, OUTPUT);

  for (int i = 0; i < 6; i++) pinMode(pinForRow[i], OUTPUT);

  digitalWrite(STATUS_RED, LOW);
  digitalWrite(STATUS_GRN, HIGH);
  digitalWrite(STATUS_BLU, HIGH);
}

ISR(TIMER2_OVF_vect) {
  softPrescaler++;
  if (softPrescaler == refreshRate) {
    displayActiveRow();
    softPrescaler = 0;
  }
};
void loop(){
  if (digitalRead(16) == LOW){ // button pushed, allow the fun stuff to start
    startFlag = 1;
  }
  if (startFlag == 1){
void displayActiveRow() {
  // disable current row;
  digitalWrite(pinForRow[activeRow], LOW);

  // set next row;
  activeRow = (activeRow + 1) % MAX_ROWS;

  // shift out values for this row;
  digitalWrite(latchPin595, LOW);
  if (easterEgg) {
    shiftOut(dataPin595, clockPin595, MSBFIRST, random(128));
    shiftOut(dataPin595, clockPin595, MSBFIRST, random(128));
  } else {
    shiftOut(dataPin595, clockPin595, MSBFIRST, ledState[REDPLAYER][activeRow]);
    shiftOut(dataPin595, clockPin595, MSBFIRST, ledState[GRNPLAYER][activeRow]);
  }
  digitalWrite(latchPin595, HIGH);

  // switch to new row;
  digitalWrite(pinForRow[activeRow], HIGH);
}
 for (x=0; x<4; x=+1){
      digitalWrite (13, HIGH);
      delay (250);
      digitalWrite (13, LOW);
      delay (250);
    }
    startFlag = 0; // fun stuff is over, don't start it again until the button is pushed.
  }
} // end loop
void loop() {
  byte button;
  byte finalRow;
if (digitalRead(16) == LOW){ // button pushed, allow the fun stuff to start
    startFlag = 1;
  }
  if (startFlag == 1){
  buttons = shiftIn(dataPin4021, clockPin4021);
  if ((buttons != lastButtonState) && (micros() - last > 50)) {
    if (buttons == B101010) {
      //randomSeed(analogRead(0));
      byte tmp = refreshRate;
      byte tmp2 = PORTC ; // save state of status led
      refreshRate = 100;
      easterEgg = true;
      while ((shiftIn(dataPin4021, clockPin4021)) == B101010) {
        digitalWrite(STATUS_RED, LOW);// very kludgy, and very temporary
        digitalWrite(STATUS_GRN, HIGH);
        digitalWrite(STATUS_BLU, HIGH);
        delay(refreshRate);
        digitalWrite(STATUS_RED, LOW);
        digitalWrite(STATUS_GRN, LOW);
        digitalWrite(STATUS_BLU, HIGH);
        delay(refreshRate);
        digitalWrite(STATUS_RED, LOW);
        digitalWrite(STATUS_GRN, LOW);
        digitalWrite(STATUS_BLU, LOW);
        delay(refreshRate);
        digitalWrite(STATUS_RED, LOW);
        digitalWrite(STATUS_GRN, HIGH);
        digitalWrite(STATUS_BLU, HIGH);
        delay(refreshRate);
        digitalWrite(STATUS_RED, HIGH);
        digitalWrite(STATUS_GRN, LOW);
        digitalWrite(STATUS_BLU, HIGH);
        delay(refreshRate);
        digitalWrite(STATUS_RED, HIGH);
        digitalWrite(STATUS_GRN, HIGH);
        digitalWrite(STATUS_BLU, LOW);
        delay(refreshRate);
      }
      PORTC = tmp2; // return status
      easterEgg = false;
      refreshRate = tmp;
      return;
    }
    last = micros();

    for (int col = 0; col < MAX_COLS; col++) {
      if (!getBit(buttons, buttonList[col])) {
        finalRow = dropChip(buttonList[col]);
        if (BENCH) before = millis();
        if (checkForWin(ledState[curPlayer], finalRow, col)) {
          if (BENCH) {
            Serial.print("Execution Time: ");
            Serial.println(millis() - before);
          }
          playWinTones();
          resetGame();
          if (DEBUG) {
            Serial.println("WINNER FOUND! :D");
          }
        } else {
          swapPlayers();
          if (DEBUG) {
            Serial.println("No Winner :(");
          }
        }
      }
    }
  }
  lastButtonState = buttons;
}
 for (x=0; x<4; x=+1){
      digitalWrite (13, HIGH);
      delay (250);
      digitalWrite (13, LOW);
      delay (250);
    }
    startFlag = 0; // fun stuff is over, don't start it again until the button is pushed.
  }
} // end loop
void swapPlayers() {
  curPlayer = !curPlayer;
  if (curPlayer == REDPLAYER) {
    digitalWrite(STATUS_RED, LOW);
    digitalWrite(STATUS_GRN, HIGH);
  } else {
    digitalWrite(STATUS_RED, HIGH);
    digitalWrite(STATUS_GRN, LOW);
  }
}

void ledOn(byte player, int x, int y) {
  ledState[player][y] |= 1 << x;
}

void ledOff(byte player, int x, int y) {
  ledState[player][y] &= ~(1 << x);
}

boolean getBit(byte myVarIn, byte whatBit) {
  return (myVarIn & (1 << whatBit));
}

boolean isLedOn(int x, int y) {
  return (ledState[REDPLAYER][y] & (1 << x)) || (ledState[GRNPLAYER][y] & (1 << x));
}

byte dropChip(int col) {
  byte finalRow;

  if (DEBUG) {
    Serial.print("Dropping Column #");
    Serial.println(col);
    Serial.print("Current Player: ");
    Serial.println(curPlayer, BIN);
  }

  if (!isLedOn(col, 0)) ledOn(curPlayer, col, 0);
  delay(dropTime);
  for (int r = 1; r < MAX_ROWS; r++) {
    finalRow = r;
    if (!isLedOn(col, r)) {
      ledOff(curPlayer, col, r - 1);
      ledOn(curPlayer, col, r);
    } else {
      finalRow--;
      break;
    }
    delay(dropTime);
  }

  if (DEBUG) Serial.print("Final Row: ");
  if (DEBUG) Serial.println(finalRow, DEC);
  return finalRow;
}

void resetGame() {
  for (int i = 0; i < MAX_ROWS; i++) {
    ledState[REDPLAYER][i] = B0000000;
    ledState[GRNPLAYER][i] = B0000000;
  }
  curPlayer = REDPLAYER;
  digitalWrite(STATUS_RED, LOW);
  digitalWrite(STATUS_GRN, HIGH);
}

void flashWinningChips() {}

boolean checkForWin(byte* gameState, int row, int col) {
  if (DEBUG) {
    Serial.print("Checking FROM: ");
    Serial.print(row);
    Serial.print(" x ");
    Serial.println(col);
  }

  if (checkHorizontal(gameState, row, col)) return true;
  else if (checkVertical(gameState, row, col)) return true;
  else if (checkLeftDiagonal(gameState, row, col)) return true;
  else if (checkRightDiagonal(gameState, row, col)) return true;
  return false;
}

boolean checkHorizontal(byte* gameState, int row, int col) {
  int cnt = 1;

  for (int c = col - 1; c >= 0; c--) { // check to the left
    if (DEBUG) {
      Serial.print("Checking column: ");
      Serial.println(c);
    }
    if (gameState[row] & 1 << c) {
      if (DEBUG) Serial.print("Player Piece Found");
      cnt++;
    } else break;
  }

  for (int c = col + 1; c < MAX_COLS; c++) {
    if (DEBUG) {
      Serial.print("Checking column: ");
      Serial.println(c);
    }
    if (gameState[row] & 1 << c) {
      if (DEBUG) Serial.println("Player Piece Found");
      cnt++;
    } else break;
  }

  if (cnt >= 4) return true;
  return false;
}

boolean checkVertical(byte* gameState, int row, int col) {
  int cnt = 1;

  if (row < MAX_ROWS - 3) {
    for (int i = row + 1; i <= row + 3; i++) {
      if (gameState[i] & 1 << col) cnt++;
    }
  }

  if (cnt >= 4) return true;
  return false;
}

boolean checkLeftDiagonal (byte* gameState, int row, int col) {
  int cnt = 1;
  int r = row - 1;
  int c = col - 1;

  while (r >= 0 && c >= 0) {
    if (DEBUG) {
      Serial.print("Checking Row: ");
      Serial.print(r);
      Serial.print(" Column: ");
      Serial.println(c);
    }
    if (gameState[r] & 1 << c) {
      cnt++;
      r--;
      c--;
      if (DEBUG) {
        Serial.print("Player Piece Found, Counter: ");
        Serial.println(cnt);
      }
    } else break;
  }

  r = row + 1;
  c = col + 1;
  while (r < MAX_ROWS && c < MAX_COLS) {
    if (DEBUG) {
      Serial.print("Checking Row: ");
      Serial.print(r);
      Serial.print(" Column: ");
      Serial.println(c);
    }
    if (gameState[r] & 1 << c) {
      cnt++;
      r++;
      c++;
      if (DEBUG) {
        Serial.print("Player Piece Found, Counter: ");
        Serial.println(cnt);
      }
    } else break;
  }

  if (cnt >= 4) return true;
  return false;
}

boolean checkRightDiagonal (byte* gameState, int row, int col) {
  int cnt = 1;
  int r = row + 1;
  int c = col - 1;
  while (r < MAX_ROWS && c >= 0) {
    if (DEBUG) {
      Serial.print("Checking Row: ");
      Serial.print(r);
      Serial.print(" Column: ");
      Serial.println(c);
    }
    if (gameState[r] & 1 << c) {
      cnt++;
      r++;
      c--;
      if (DEBUG) {
        Serial.print("Player Piece Found, Counter: ");
        Serial.println(cnt);
      }
    } else break;
  }

  r = row - 1;
  c = col + 1;
  while (r >= 0 && c < MAX_COLS) {
    if (DEBUG) {
      Serial.print("Checking Row: ");
      Serial.print(r);
      Serial.print(" Column: ");
      Serial.println(c);
    }
    if (gameState[r] & 1 << c) {
      cnt++;
      r--;
      c++;
      if (DEBUG) {
        Serial.print("Player Piece Found, Counter: ");
        Serial.println(cnt);
      }
    } else break;
  }

  if (cnt >= 4) return true;
  return false;
}

void playWinTones() {
  //  cli();
  buzz(piezo, 523, 1000 / 6); // C 1/8
  buzz(piezo, 523, 1000 / 6); // C 1/8
  buzz(piezo, 523, 1000 / 6); // C 1/8
  buzz(piezo, 523, 1000 / 3); // C 1/4
  buzz(piezo, 415, 1000 / 3); // A-Flat 1/4
  buzz(piezo, 466, 1000 / 3); // B-Flat 1/4
  buzz(piezo, 523, 1000 / 6); // C 1/8
  delay(25); // trial and error 1/8
  buzz(piezo, 466, 1000 / 6); // B-Flat 1/8
  buzz(piezo, 523, 1000 / 1.5); // C 1/2.
  //  sei();
}

void buzz(int targetPin, long frequency, long length) {
  long delayValue = 1000000 / frequency / 2; // calculate the delay value between transitions
  // 1 second's worth of microseconds, divided by the frequency, then split in half since
  // there are two phases to each cycle
  long numCycles = frequency * length / 1000; // calculate the number of cycles for proper timing
  // multiply frequency, which is really cycles per second, by the number of seconds to
  // get the total number of cycles to produce
  for (long i = 0; i < numCycles; i++) { // for the calculated length of time...
    digitalWrite(targetPin, HIGH); // write the buzzer pin high to push out the diaphram
    delayMicroseconds(delayValue); // wait for the calculated delay value
    digitalWrite(targetPin, LOW); // write the buzzer pin low to pull back the diaphram
    delayMicroseconds(delayValue); // wait againf or the calculated delay value
  }
  delayMicroseconds(delayValue * 5);
}

byte shiftIn(int myDataPin, int myClockPin) {
  // internal function setup
  int i;
  int temp = 0;
  byte myDataIn = 0;

  //Pulse the latch pin: set it to 1 to collect parallel data
  digitalWrite(latchPin4021, 1);

  //set it to 1 to collect parallel data, wait
  delayMicroseconds(20);

  // set it to 0 to transmit data serially
  digitalWrite(latchPin4021, 0);

  // we will be holding the clock pin high 8 times (0,..,7) at the
  // end of each time through the for loop
  // at the begining of each loop when we set the clock low, it will
  // be doing the necessary low to high drop to cause the shift
  // register's DataPin to change state based on the value
  // of the next bit in its serial information flow.
  // The register transmits the information about the pins from pin 7 to pin 0
  // so that is why our function counts down
  for (i = 7; i >= 0; i--) {
    digitalWrite(myClockPin, LOW);
    delayMicroseconds(0.2);
    temp = digitalRead(myDataPin);
    if (temp) {
      myDataIn = myDataIn | (1 << i); // set the bit to 0 no matter what
    }
    digitalWrite(myClockPin, HIGH);
  }
  return myDataIn;
}

JimboZA has it spot on.
This bit is wrong:-

void loop(){
  if (digitalRead(16) == LOW){ // button pushed, allow the fun stuff to start
    startFlag = 1;
  }
  if (startFlag == 1){
void displayActiveRow() {  // this defines a function and you can not do that within a function
  // disable current row;
  digitalWrite(pinForRow[activeRow], LOW);

However when you define it properly your code then has two loop functions, something else you can not have.

Yes, don't define it as void displayActiveRow(), there, just use it/call it.

There are tons more errors with that code as well as the two loops. Two loop functions is always a sign of someone who has not written the code and is trying to just stick two codes together. Is this true for you?

I have “corrected” as much as possible and assumes your “shift in” function wants a MSBFIRST bit order is this right? You had one too many } braces in that second loop function. I have renamed it loop2 and called it at the end of the loop function but it doesn’t look right because it seems to reproduce the same sort of thing as the start of the first loop function.

Note that while the code compiles there is no guarantee that it will actually do what you want. In fact I would be staggered if it did.

sketch_temp.ino (13.7 KB)