I have been using the U8GLIB library with a 128X64 LCD for some time.
Now I am trying to do the same with a 16X2 LCD using the LiquidCrystal library.
But now when I use lcd.print commands in the loop, the text keeps repeating itself, on both lines.
Like this:
lcd.setCursor(0, 0); // top left
lcd.print("Delay:");
lcd.setCursor(9, 0); // top left
lcd.print(shutter_delay);
lcd.setCursor(14, 0); // top left
lcd.print("mS");
I'm missing something I think?!
both lines.
You are only printing to one line
lcd.setCursor(0, 0); // top left
lcd.setCursor(9, 0); // top left
lcd.setCursor(14, 0); // top left
They can't all be top left can they ?
I await your full code with interest.
It looks OK, so, like holmes4 suggests the problem must be in other place of the code. For example, how do you made the initialization of the LCD?
Help :~
#include <LiquidCrystal.h>
#include <Encoder.h>
#include <NewPing.h>
#define TRIGGER_PIN 12 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 11 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
Encoder myEnc(2, 3);
int set_value; //encoder selected value
int y = 2; //push button, store on off value
byte q; //menu selection variable
int distance; //actual distance
int locked; //user locked distance
int shutter_delay = 500; //relay repeated activation delay
void setup(void) {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
pinMode(4, INPUT); // encoder select button
pinMode(5, INPUT); // distance lock button
pinMode(6, OUTPUT); // relay pin
}
long oldPosition = -999; //encoder
void loop(void) {
lcd.setCursor(0, 0); // top left
lcd.print("Delay:");
lcd.setCursor(9, 0); // top left
lcd.print(shutter_delay);
lcd.setCursor(14, 0); // top left
lcd.print("mS");
// -------------------------------menu selection
y = digitalRead(4);
if (y ==1 && q < 4)
{ q++;
delay (200);
}
y = digitalRead(4);
if (y ==1 && q >=4)
{ q=0;
delay (200);
}
if( q==1)
{
delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
distance = (uS / US_ROUNDTRIP_CM);
}
// ultrasound relay activation code
y = digitalRead(5); // locks distance
if (y ==1 )
{ locked = distance;
}
if ( (locked > (distance + set_value) || locked < (distance - set_value) ) && locked != 0 )
{
digitalWrite(6, HIGH);
delay(shutter_delay);
digitalWrite(6, LOW);
}
else
{
digitalWrite(6, LOW);
}
long newPosition = myEnc.read(); //encoder
if (newPosition != oldPosition) { //encoder
oldPosition = newPosition; //encoder
}
set_value = oldPosition;
//--------------------- encoder writing to shutter_delay
if(q==4)
{
long newPosition = myEnc.read(); //encoder
if (newPosition != oldPosition) { //encoder
oldPosition = newPosition; //encoder
}
shutter_delay = (oldPosition *10);
}
delay(100);
}
edit:
The rotary encoder is not connected, so it should be safe to ignore my double use of pins 2 + 3
Pins 4 and 5 are being used by the LCD and are also set to INPUT each time through loop()
What is that all about ?
XD
thanks that was the problem
y = digitalRead(4);
if (y ==1 && q < 4)
{ q++;
delay (200);
}
//
y = digitalRead(4);
if (y ==1 && q >=4)
{ q=0;
delay (200);
}
This was the remains from when I used the U8glib, I forgot the conflicting pins, somehow they messed it up, it works now