Society of Robots - Robot Forum

Software => Software => Topic started by: galannthegreat on September 27, 2009, 09:22:09 PM

Title: I'm trying to read an analog value and print it to an LCD
Post by: galannthegreat on September 27, 2009, 09:22:09 PM
I don't know what's wrong but all it gives me is:
error: expected "," or ";" before "int"

Code: [Select]
#include <LiquidCrystal.h>

LiquidCrystal lcd(12,11,10,5,4,3,2)
int analogPin = 2;
int val = 0;

void setup()
{
  lcd.begin(2,16);
}

void loop()
{
  val = analogRead(analogPin);
  lcd.print(val);
}

Can someone help me figure this out?
Title: Re: I'm trying to read an analog value and print it to an LCD
Post by: galannthegreat on September 27, 2009, 09:39:09 PM
Maybe it would help if I told you what I was using. I'm using an Arduino with a 2x16 character LCD display and a Sharp GP2D12 IR rangefinder.
Title: Re: I'm trying to read an analog value and print it to an LCD
Post by: chelmi on September 27, 2009, 09:42:07 PM
The message is pretty clear (for once :) ). The compiler was expecting a dot or a semicolon before the int on line 4.
You need to had a semicolon after the lcd initialization:

Code: [Select]
LiquidCrystal lcd(12,11,10,5,4,3,2);
int analogPin = 2;
Title: Re: I'm trying to read an analog value and print it to an LCD
Post by: galannthegreat on September 27, 2009, 10:12:32 PM
Wow, I must have been interpreting that error wrong for the past hour or so, thanks! :)

Now it's time to get the code right to display what I want. I'm just getting "the matrix" thing now. lol
Title: Re: I'm trying to read an analog value and print it to an LCD
Post by: galannthegreat on September 28, 2009, 12:45:27 AM
I seem to have hit a "bump". I've got my system working with the Sharp IR and the LCD, but the Sharp IR seems to be spitting out random values only within a range of 930-1023. I don't know why when I adjust an object to be at different distances from the sensor that it just keeps spitting those values out. Anyone know why this may be? Any solution?

Here's the new code that works for me now:
Code: [Select]
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
int analogPin = 3;
int val = 0;

void setup()
{
  lcd.begin(2, 16);
  Serial.begin(9600);
}

void loop()
{
  val = analogRead(analogPin);
  lcd.setCursor(0, 1);
  delay(50);
  lcd.print(val);
  delay(1000);
  lcd.clear();
  Serial.println(val);
}