Error message byte 2

wim_s_button_box_code.ino (6.4 KB)

I cant seem to figure out what is wrong with my code this is the error I am getting .

#include <Keypad.h>
#include <Joystick.h>

//DEFINITIONS
#define ENABLE_PULLUPS
#define NUMROTARIES 1 //replace "?" with number of rotary encoders you are using
#define NUMBUTTONS 7 //replace "?"with number of buttong you are using
#define NUMROWS 3 //replace "?" with number of rows you have
#define NUMCOLS 2 //replace "?" with number of columns you have

//BUTTON MATRIX
//first change number of rows and columns to match your button matrix,
//then replace all "?" with numbers (starting from 0)
byte buttons[NUMROWS][NUMCOLS] = {
  {0, 1, 2},
  {3, 4, 5},
  {6, 7, 8},
},

struct rotariesdef {
  byte pin1;
  byte pin2;
  int ccwchar;
  int cwchar;
  volatile unsigned char state;
};

//ROTARY ENCODERS
//each line controls a different rotary encoder
//the first two numbers refer to the pins the encoder is connected to
//the second two are the buttons each click of the encoder wil press
//do NOT exceed 31 for the final button number
rotariesdef rotaries[NUMROTARIES] {
  {0, 1, 22, 23, 0}, //rotary 1

};

And this is my error message

Arduino: 1.8.13 (Windows Store 1.8.42.0) (Windows 10), Board: "Arduino Micro"





















wim_s_button_box_code:18:1: error: too many initializers for 'byte [2] {aka unsigned char [2]}'

 },

 ^

wim_s_button_box_code:18:1: error: too many initializers for 'byte [2] {aka unsigned char [2]}'

wim_s_button_box_code:18:1: error: too many initializers for 'byte [2] {aka unsigned char [2]}'

wim_s_button_box_code:20:1: error: expected unqualified-id before 'struct'

 struct rotariesdef {

 ^~~~~~

wim_s_button_box_code:33:1: error: 'rotariesdef' does not name a type

 rotariesdef rotaries[NUMROTARIES] {

 ^~~~~~~~~~~

C:\Users\Camden Ramos\Desktop\wim_s_button_box_code\wim_s_button_box_code.ino: In function 'void CheckAllPotentiometers()':

wim_s_button_box_code:142:41: error: 'potentiometerPin1' was not declared in this scope

   currentOutputLevel = getAverageOutput(potentiometerPin1);

                                         ^~~~~~~~~~~~~~~~~

wim_s_button_box_code:143:3: error: 'zAxis_' was not declared in this scope

   zAxis_ = map(currentOutputLevel, 0, 1023, 0, 255);

   ^~~~~~

wim_s_button_box_code:147:41: error: 'potentiometerPin2' was not declared in this scope

   currentOutputLevel = getAverageOutput(potentiometerPin2);

                                         ^~~~~~~~~~~~~~~~~

wim_s_button_box_code:148:3: error: 'RxAxis_' was not declared in this scope

   RxAxis_ = map(currentOutputLevel, 0, 1023, 0, 255);

   ^~~~~~~

C:\Users\Camden Ramos\Desktop\wim_s_button_box_code\wim_s_button_box_code.ino: In function 'void rotary_init()':

wim_s_button_box_code:193:13: error: 'rotaries' was not declared in this scope

     pinMode(rotaries[i].pin1, INPUT);

             ^~~~~~~~

C:\Users\Camden Ramos\Desktop\wim_s_button_box_code\wim_s_button_box_code.ino:193:13: note: suggested alternative: 'rowPins'

     pinMode(rotaries[i].pin1, INPUT);

             ^~~~~~~~

             rowPins

C:\Users\Camden Ramos\Desktop\wim_s_button_box_code\wim_s_button_box_code.ino: In function 'unsigned char rotary_process(int)':

wim_s_button_box_code:206:41: error: 'rotaries' was not declared in this scope

   unsigned char pinstate = (digitalRead(rotaries[_i].pin2) << 1) | digitalRead(rotaries[_i].pin1);

                                         ^~~~~~~~

C:\Users\Camden Ramos\Desktop\wim_s_button_box_code\wim_s_button_box_code.ino:206:41: note: suggested alternative: 'rowPins'

   unsigned char pinstate = (digitalRead(rotaries[_i].pin2) << 1) | digitalRead(rotaries[_i].pin1);

                                         ^~~~~~~~

                                         rowPins

C:\Users\Camden Ramos\Desktop\wim_s_button_box_code\wim_s_button_box_code.ino: In function 'void CheckAllEncoders()':

wim_s_button_box_code:219:26: error: 'rotaries' was not declared in this scope

       Joystick.setButton(rotaries[i].ccwchar, 1); delay(50); Joystick.setButton(rotaries[i].ccwchar, 0);

                          ^~~~~~~~

C:\Users\Camden Ramos\Desktop\wim_s_button_box_code\wim_s_button_box_code.ino:219:26: note: suggested alternative: 'rowPins'

       Joystick.setButton(rotaries[i].ccwchar, 1); delay(50); Joystick.setButton(rotaries[i].ccwchar, 0);

                          ^~~~~~~~

                          rowPins

wim_s_button_box_code:225:26: error: 'rotaries' was not declared in this scope

       Joystick.setButton(rotaries[i].cwchar, 1); delay(50); Joystick.setButton(rotaries[i].cwchar, 0);

                          ^~~~~~~~

C:\Users\Camden Ramos\Desktop\wim_s_button_box_code\wim_s_button_box_code.ino:225:26: note: suggested alternative: 'rowPins'

       Joystick.setButton(rotaries[i].cwchar, 1); delay(50); Joystick.setButton(rotaries[i].cwchar, 0);

                          ^~~~~~~~

                          rowPins

exit status 1

too many initializers for 'byte [2] {aka unsigned char [2]}'



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Please post your full sketch here

The easier you make it to read and copy the code the more likely it is that you will get help

Please follow the advice given in the link below when posting code

You seem to be using three rows and three columns but you are saying you say you are going to use three rows and TWO columns. That's why the compiler is tell you you have too many initializers (three where you said to expect two).

WARNING! You are using a key value of 0 and the Keypad library reserves the value 0 for "NO_KEY". The library will produce odd results if the value 0 is used. The comment to replace "?" with numbers starting with 0 is incorrect unless the ? was '?' to be replaced with '0', a character.

I fixed that problem but no I am getting this error

Arduino: 1.8.13 (Windows Store 1.8.42.0) (Windows 10), Board: "Arduino Micro"





















wim_s_button_box_code:20:1: error: expected unqualified-id before 'struct'

 struct rotariesdef {

 ^~~~~~

wim_s_button_box_code:33:1: error: 'rotariesdef' does not name a type

 rotariesdef rotaries[NUMROTARIES] {

 ^~~~~~~~~~~

C:\Users\Camden Ramos\Desktop\wim_s_button_box_code\wim_s_button_box_code.ino: In function 'void CheckAllPotentiometers()':

wim_s_button_box_code:142:41: error: 'potentiometerPin1' was not declared in this scope

   currentOutputLevel = getAverageOutput(potentiometerPin1);

                                         ^~~~~~~~~~~~~~~~~

wim_s_button_box_code:143:3: error: 'zAxis_' was not declared in this scope

   zAxis_ = map(currentOutputLevel, 0, 1023, 0, 255);

   ^~~~~~

wim_s_button_box_code:147:41: error: 'potentiometerPin2' was not declared in this scope

   currentOutputLevel = getAverageOutput(potentiometerPin2);

                                         ^~~~~~~~~~~~~~~~~

wim_s_button_box_code:148:3: error: 'RxAxis_' was not declared in this scope

   RxAxis_ = map(currentOutputLevel, 0, 1023, 0, 255);

   ^~~~~~~

C:\Users\Camden Ramos\Desktop\wim_s_button_box_code\wim_s_button_box_code.ino: In function 'void rotary_init()':

wim_s_button_box_code:193:13: error: 'rotaries' was not declared in this scope

     pinMode(rotaries[i].pin1, INPUT);

             ^~~~~~~~

C:\Users\Camden Ramos\Desktop\wim_s_button_box_code\wim_s_button_box_code.ino:193:13: note: suggested alternative: 'rowPins'

     pinMode(rotaries[i].pin1, INPUT);

             ^~~~~~~~

             rowPins

C:\Users\Camden Ramos\Desktop\wim_s_button_box_code\wim_s_button_box_code.ino: In function 'unsigned char rotary_process(int)':

wim_s_button_box_code:206:41: error: 'rotaries' was not declared in this scope

   unsigned char pinstate = (digitalRead(rotaries[_i].pin2) << 1) | digitalRead(rotaries[_i].pin1);

                                         ^~~~~~~~

C:\Users\Camden Ramos\Desktop\wim_s_button_box_code\wim_s_button_box_code.ino:206:41: note: suggested alternative: 'rowPins'

   unsigned char pinstate = (digitalRead(rotaries[_i].pin2) << 1) | digitalRead(rotaries[_i].pin1);

                                         ^~~~~~~~

                                         rowPins

C:\Users\Camden Ramos\Desktop\wim_s_button_box_code\wim_s_button_box_code.ino: In function 'void CheckAllEncoders()':

wim_s_button_box_code:219:26: error: 'rotaries' was not declared in this scope

       Joystick.setButton(rotaries[i].ccwchar, 1); delay(50); Joystick.setButton(rotaries[i].ccwchar, 0);

                          ^~~~~~~~

C:\Users\Camden Ramos\Desktop\wim_s_button_box_code\wim_s_button_box_code.ino:219:26: note: suggested alternative: 'rowPins'

       Joystick.setButton(rotaries[i].ccwchar, 1); delay(50); Joystick.setButton(rotaries[i].ccwchar, 0);

                          ^~~~~~~~

                          rowPins

wim_s_button_box_code:225:26: error: 'rotaries' was not declared in this scope

       Joystick.setButton(rotaries[i].cwchar, 1); delay(50); Joystick.setButton(rotaries[i].cwchar, 0);

                          ^~~~~~~~

C:\Users\Camden Ramos\Desktop\wim_s_button_box_code\wim_s_button_box_code.ino:225:26: note: suggested alternative: 'rowPins'

       Joystick.setButton(rotaries[i].cwchar, 1); delay(50); Joystick.setButton(rotaries[i].cwchar, 0);

                          ^~~~~~~~

                          rowPins

exit status 1

expected unqualified-id before 'struct'



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

When you make changes to your code, even small changes, post the new version so that we can keep up.

sorry here is the most up-to-date version wim_s_button_box_code.ino (6.5 KB)

So, what is wrong just before Line 20? My guess is that ending your declaration of 'buttons' with a comma instead of the traditional semicolon is the culprit.

If you want help here, post your code here.

Okay I fixed that but now I'm getting this problem

Arduino: 1.8.13 (Windows Store 1.8.42.0) (Windows 10), Board: "Arduino Micro"





















S:\wim_s_button_box_code\wim_s_button_box_code.ino: In function 'void setup()':

wim_s_button_box_code:123:3: error: 'rotary_init' was not declared in this scope

   rotary_init();

   ^~~~~~~~~~~

S:\wim_s_button_box_code\wim_s_button_box_code.ino:123:3: note: suggested alternative: 'rotaries'

   rotary_init();

   ^~~~~~~~~~~

   rotaries

S:\wim_s_button_box_code\wim_s_button_box_code.ino: In function 'void loop()':

wim_s_button_box_code:131:3: error: 'CheckAllEncoders' was not declared in this scope

   CheckAllEncoders();

   ^~~~~~~~~~~~~~~~

wim_s_button_box_code:132:3: error: 'CheckAllButtons' was not declared in this scope

   CheckAllButtons();

   ^~~~~~~~~~~~~~~

wim_s_button_box_code:133:3: error: 'CheckAllPotentiometers' was not declared in this scope

   CheckAllPotentiometers();

   ^~~~~~~~~~~~~~~~~~~~~~

S:\wim_s_button_box_code\wim_s_button_box_code.ino: At global scope:

wim_s_button_box_code:137:1: error: expected declaration before '}' token

 }

 ^

exit status 1

'rotary_init' was not declared in this scope



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

here is my current code wim_s_button_box_code.ino (6.0 KB)

void loop()
{

  CheckAllEncoders();
  CheckAllButtons();
  CheckAllPotentiometers();

}

}

Extra '}' after loop(). Fix that and check that ALL of your functions have matching brackets. Using Tools->Auto Format on your sketch will help you find such mistakes.

It all works now thank you so much

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.