0

This is my first time to try program arduino, and I am clueless. I have a friend who told me about things work, and he told me the programming language is C (or similar to C) which we have learned in our class. I just program as my friend examples, but it doesn't work and return error codes about expected ; before ( or ) before ; etc.

I'm not sure why this wont work. This is the hardware (simulated) I going to make. hw-planned

here's the code:

#define dw 8; //buttons down
#define ri 9; //buttons right
#define le 10; //buttons left
#define up 11; //buttons up
#define ok 12; //buttons ok
#define mn 13; //buttons menu
#include <LiquidCrystal.h>
LiquidCrystal lcd(6,5,4,3,2,1);
int i=0;
char input[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

void setup()
{
  pinMode(dw, INPUT);
  pinMode(ri, INPUT);
  pinMode(le, INPUT);
  pinMode(up, INPUT);
  pinMode(ok, INPUT);
  pinMode(mn, INPUT);  
}
void intext()
{
  int c=0, lim=16;
  for(i=0;i<lim;)
  {
    lcd.setCursor(c,1);
    input[i]=97;
    if(dw=HIGH)
    {
      if(input[i]>122)
        input[i]=97;
      input[i]=input[i]+1;
      lcd.print(input[i]);
    }
    if(up=HIGH)
    {
      if(input[i]>97)
        input[i]=122;
      input[i]=input[i]-1;
      lcd.print(input[i]);
    }
    if(ri=HIGH)
    {
      c=c+1;
      lcd.setCursor(c,1);
      lcd.print(input[i]);      
    }
    if(le=HIGH)
    {
      c=c-1;
      lcd.setCursor(c,1);
      lcd.print(input[i]);
    }
    if(ok=HIGH)
    {
      lim=i+1;
    }
  }
}

void loop()
{
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("Masukan kata:");
  intext();
}

I have no idea why it wouldn't work. I'm sorry if I'm too stupid to understand. Thank you!

Edit: oh yeah, the errors, here:

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.
Arduino: 1.0.6 (Windows NT (unknown)), Board: "Arduino Uno"
programyuhu.ino: In function 'void setup()':
programyuhu:14: error: expected `)' before ';' token
programyuhu:14: error: expected primary-expression before ',' token
programyuhu:14: error: expected `;' before ')' token
programyuhu:15: error: expected `)' before ';' token
programyuhu:15: error: expected primary-expression before ',' token
programyuhu:15: error: expected `;' before ')' token
programyuhu:16: error: expected `)' before ';' token
programyuhu:16: error: expected primary-expression before ',' token
programyuhu:16: error: expected `;' before ')' token
programyuhu:17: error: expected `)' before ';' token
programyuhu:17: error: expected primary-expression before ',' token
programyuhu:17: error: expected `;' before ')' token
programyuhu:18: error: expected `)' before ';' token
programyuhu:18: error: expected primary-expression before ',' token
programyuhu:18: error: expected `;' before ')' token
programyuhu:19: error: expected `)' before ';' token
programyuhu:19: error: expected primary-expression before ',' token
programyuhu:19: error: expected `;' before ')' token
programyuhu.ino: In function 'void intext()':
programyuhu:28: error: expected `)' before ';' token
programyuhu:28: error: expected primary-expression before '=' token
programyuhu:28: error: expected `;' before ')' token
programyuhu:35: error: expected `)' before ';' token
programyuhu:35: error: expected primary-expression before '=' token
programyuhu:35: error: expected `;' before ')' token
programyuhu:42: error: expected `)' before ';' token
programyuhu:42: error: expected primary-expression before '=' token
programyuhu:42: error: expected `;' before ')' token
programyuhu:48: error: expected `)' before ';' token
programyuhu:48: error: expected primary-expression before '=' token
programyuhu:48: error: expected `;' before ')' token
programyuhu:54: error: expected `)' before ';' token
programyuhu:54: error: expected primary-expression before '=' token
programyuhu:54: error: expected `;' before ')' token
2

In C and in C++, #define is not an instruction of the language, but a directive of the pre-processor.

What it does is define a "macro" which will be replaced everywhere it appears later on in the source file.

For instance:

#define DUMMY 152

int x = x + DUMMY;
myfunction(DUMMY);

will be changed, before compilation, into:

int x = x + 152;
myfuntion(152);

In the example above, DUMMY is replaced everywhere by what follows it in the #define line, i.e. 152.

As pre-processor directive is not an instruction, it shall not be ended by ;. If you add ; at the end of a #define, then it will be part of the replacement:

#define DUMMY 152;

int x = x + 152;;
myfuntion(152;);

As you can see now, DUMMY is replaced by 152;, not just 152.

So the solution in you example is to remove all ; that are at the end of #define lines:

//buttons down
#define dw 8
//buttons right
#define ri 9
//buttons left
#define le 10
//buttons up
#define up 11
//buttons ok
#define ok 12
//buttons menu
#define mn 13

Note that comments should also be removed from the #define otherwise they would also appear everywhere the replacements are done.

6

Here's the first line of your code:

#define dw 8; //buttons down

Here's the first error line:

pinMode(dw, INPUT);

Let's put them together and see what we get:

pinMode(8; //buttons down, INPUT);

That's not valid C++. Using the output I've shown you, modify the input until it looks correct. And then keep doing it until the code compiles.

6
  • I am sorry for asking this, but did you mean (pinMode(8; buttons down, INPUT);) ? I don't quite understand on the comment part. – Febri Kurniawan Dec 24 '14 at 4:38
  • Did you read the code you wrote? Did you read the parts I extracted? – Ignacio Vazquez-Abrams Dec 24 '14 at 4:42
  • Sorry again if I don't understand, I don't know about C++ at all (as I only learn about the regular C). So I just copy your code as is? I'm lost – Febri Kurniawan Dec 24 '14 at 4:46
  • 1
    Look at the first line of code in my answer. Look at the second line of code in my answer. When taken together, they result in the third line of code in my answer. Does this make sense to you? – Ignacio Vazquez-Abrams Dec 24 '14 at 4:51
  • I tried it but it's still doesn't work. I will try to redo/change my code using another way. Sorry for the trouble I have caused. Thank you for your assistance. You made me realize how difference C++ with C is. Again Thank you. – Febri Kurniawan Dec 24 '14 at 4:57
2

The errors are in your #define statements.

These should not have ; as they are not executable statements

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.