Pages: [1]   Go Down
Author Topic: Help! I get a error  (Read 157 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i'm a newbie ,i want to make a Computer with using arduino.
but i get a error,
this is the code:
Code:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

long number1;
long number2;
char symbol;
long ans;

void setup() {
  Serial.begin(9600);
  lcd.begin(16,2);
  Serial.println("Welcome to the Number Computer V1");
}

void loop() {
  long _in;
  String Number = "";
  if(Serial.available()) {
    _in = Serial.read;
    Number += _in;
    if(_in == '/n') {
      number1 = Number.substring(0,6);
      number2 = Number.substring(7);
      symbol = Number.charAt(6);
      switch(symbol) {
        case '+' :
          ans = number1 + number2;
          break;
        case '-' :
          ans = number1 - number2;
          break;
        case '*' :
          ans = number1 * number2;
          break;
        case '/' :
          ans = number1 / number2;
          break;
      }
      Serial.print(number1);
      Serial.print(symbol);
      Serial.println(number2);
      Serial.print("Your ans: ");
      Serial.println(ans);
      lcd.setCursor(0,0);
      lcd.print(number1);
      lcd.print(symbol);
      lcd.print(number2);
      lcd.setCursor(0,1);
      lcd.print("Ans:");
      lcd.setCursor(4,1);
      lcd.print(ans);
    }
  }
}

i get this error:
sketch_apr19a:21: error: argument of type 'int (HardwareSerial:smiley()' does not match 'long int'
sketch_apr19a:24: error: cannot convert 'String' to 'long int' in assignment
sketch_apr19a:25: error: cannot convert 'String' to 'long int' in assignment

who can help me?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 630
Posts: 50009
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
    if(_in == '/n') {
Are you certain that slash is leaning the right way? I'm certain that it isn't.

Code:
    _in = Serial.read;
Function calls require ().

Serial.read() returns a byte. Why are you storing that byte in a long?

Code:
      number1 = Number.substring(0,6);
      number2 = Number.substring(7);
The compiler is right. You can't do this. A substring can only be stored in a String.
Logged

Offline Offline
Edison Member
*
Karma: 41
Posts: 1271
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Tell us what you want to do, we can tell how to do that.
What is the serial data ? A number ?
There is a special function for that : http://arduino.cc/en/Reference/ParseInt

The Serial.read() is a function, you must use the ()
The substring(..) operator on a string returns a string (a sub string), you can not assign that to a number that way.

PaulS replied when I was typing this, he also noticed the /n instead of \n
Logged

Pages: [1]   Go Up
Jump to: