Expected ')' before char. (Can't seem to find it)

Hey community!

I’ve written a bit of code, and cant seem to find the error that has been found in it.

Here’s the code:

//----------libararies----------
#include <Keypad.h>;
//------------------------------

//-----------settings-----------
int changeH = 5;
int changeL = -5;
//------------------------------

//-----------integers-----------
int companyA = 50;
int companyB = 50;
int companyC = 50;
int companyD = 50;
int companyAChange;
int companyBChange;
int companyCChange;
int companyDChange;
int chanceA;
int chanceB;
int chanceC;
int chanceD;
//------------------------------

//-----------buttonpad----------
const byte rows = 4;
const byte cols = 5;
char keys[rows][cols] = {
 {'13','14','15','16','s'},
 {'9','10','11','12','b'},
 {'5','6','7','8','b'},
 {'1','2','3','4','b'}
};
byte rowPins[rows] = {5, 4, 3, 2};
byte colPins[cols] = {12, 11, 10, 9, 8};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );
//------------------------------

//---------- constants----------

//------------------------------

void setup() {
  // put your setup code here, to run once:
  randomSeed(analogRead(0)); //analog noise will generate a random seed for the stock prices
}

void loop() {
  char waitForKey();
  if(char getKey() == 's') {
   companyA = companyA + random(changeL, changeH + 1);
   companyB = companyB + random(changeL, changeH + 1);
   companyC = companyC + random(changeL, changeH + 1);
   companyD = companyD + random(changeL, changeH + 1);
  }
}
if(char getKey() == 's') {

It's that one. I don't know the Keypad library, but just try removing it.

Removed the line at question, and it's been fixed.

Problem is, I need that line for my project to work...

Just remove the char, not the whole line…

Oh, but isn’t that necessary for the function to work?

By the way, I don’t have an Arduino on my at the moment, so I cant test it

If you create a function you need to define the return type. But when using it you don't. Als, the getKey() is past of the library object. The line should read

if(keypad.getKey() == 's') {

septillion:
If you create a function you need to define the return type. But when using it you don’t. Als, the getKey() is past of the library object. The line should read

if(keypad.getKey() == 's') {

Awesome! Thanks!

I dunno if this’ll happen but can someone update the http://playground.arduino.cc/Code/Keypad page so that people like me don’t get confused the same way?

Why? It just gives you the prototype of the function inside the library. It tells you what parameters to provide and what to expect in return. Just read trough the examples :)

Do they ever do that in the example code there? I don't see it, in a quick reading

Yeah, I was halfway through writing that when my computer crashed....

They should update the page so that it doesn't confuse people like me xD

I fixed it btw!

The page isn't confusing. They gave a good example:

void loop(){
  char key = keypad.getKey();

  if (key != NO_KEY){
    Serial.println(key);
  }
}

There is a certain style used for computer documentation, and one of them is that you state the return type on a function prototype, so people know what to expect. It's a form of shorthand. You learn it.

char keys[rows][cols] = {
 {'13','14','15','16','s'},
 {'9','10','11','12','b'},

Can you post a picture of your keyboard with the 13 key circled?

Single quotes are for SINGLE characters. Which ONE key did you press to get '13', '14', etc?

I think you can replace the ascii numbers with just numbers (but I have to say I never used the library)

char keys[rows][cols] = {
 {13, 14, 15, 16, 's'},
 {9, 10, 11, 12, 'b'},
 {5, 6, 7, 8, 'b'},
 {1, 2, 3, 4, 'b'}
};
char keys[rows][cols] = {
 {'13','14','15','16','s'},
 {'9','10','11','12','b'},
 {'5','6','7','8','b'},
 {'1','2','3','4','b'}
};

Apart from what PaulS and septillion said, three of your keys are going to return 'b'. Isn't that confusing?

ShadowGaming: I dunno if this'll happen but can someone update the http://playground.arduino.cc/Code/Keypad page so that people like me don't get confused the same way?

No, because the declaration that getKey() returns a char is important. People who get confused by this get confused because they haven't learned how to program in C++. That is, this is not about the Arduino library in particular, it's about the syntax of C++ as a programming language.

What you need is a tutorial on C++ by itself. You can only get just so far by copying and pasting and guessing. To get further than that, you need to understand what is going on.

Same as anything, really.