If you look at this sketch you will hopefully see what I am trying to do. I want to be able to insert the variables a,b,c,d,e,f and have these values shown on the lcd. Any help would be appreciated.
/ include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// initialize the digital pins as an output.
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
// here I want to enter the values of a,b,c,d,e,f, so that they will be entered automatically below
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print(" a c e ");
b d f
}
void loop() {
digitalWrite(6, HIGH); // Turns ON Relay 3 on digital pin 6 (blue)
delay(a); // size of drop in ms best size for trajectory
digitalWrite(6, LOW); // Turns OFF Relay 3 on digital pin 6
delay(b); // time between 1st and 2nd drops
digitalWrite(7, HIGH); // Turns ON Relay 2 on digital pin 7 (yellow)
delay(c); // size of drop in ms
digitalWrite(7, LOW); // Turns OFF Relay 2 on digital pin 7
delay(d); // time between 2nd and 3rd drops
digitalWrite(8, HIGH); // Turns ON Relay 4 on digital pin 8 (red)
delay(e); // size of drop in ms
digitalWrite(8, LOW); // Turns OFF Relay 4 on digital pin 8
delay(f); // Delay before recycling
}
Moderator edit: [code] ... [/code] tags added. (Nick Gammon)
Since you're using these variables in the delay() functions I presume they're typed as integers, however I don't see you declaring them nor giving them a value in this code segment. Without that, this won't work. But I presume you have that somewhere so to get them to output in a neat row under your headings is simple however you've got to deal with being limited to 16 characters by 2 rows, so it will take some juggling depending on the values of each, and since you've allowed 9 spaces between each heading I can only presume they could be up to 10 chars long when represented on screen...so maybe something like this will help:
// in loop() function
lcd.Clear();
lcd.print("a: "); // allows space for 14 char variable value next
lcd.print(a);
lcd.setCursor(0,1); // 1st position on 2nd row
lcd.print("b:");
lcd.print(b);
delay(500); // ugly, but you need to allow time to read! deduct these delays from your overall loop delay
lcd.Clear();
lcd.print("c: ");
lcd.print(c);
lcd.setCursor(0,1); // 1st position on 2nd row
lcd.print("d:");
lcd.print(d);
delay(500);
lcd.Clear();
lcd.print("e: ");
lcd.print(e);
lcd.setCursor(0,1); // 1st position on 2nd row
lcd.print("f:");
lcd.print(f);
delay(500);
You'll find this can be simplified by using an array rather than individual variables for the delays.
// declared globally
int valueArray[6];
// and then, in loop() function
for(int i = 0; i <6; i=i+2) {
lcd.Clear();
for(int j=0; j <2; j++) {
lcd.setCursor(0,j);
lcd.print("[");
lcd.print(i+j);
lcd.print("]:"); // allows space for 12 char variable value next
lcd.print(valueArray[i+j]);
}
delay(500); // allow time to read your display
}
Apologies if I've introduced any errors by coding-as-I-type...
Cheers ! Geoff
[edit: grr already I fixed 2 typos in my code, hopefully this works now !]
Hi Geoff,
As you have probably realised I am pretty new to this. I managed to write the code without using the lcd and by entering the values directly for a,b..f, and that worked ok. Now I have complecated it by wanting an lcd to display my values. By introducing a,b...f I asumed it would be easier to get these values to show on the lcd. As yet I don't know how to do this either. I am trying to study the books, but have found no reference on how to do it yet. Thanks for your help. I will get on to the lcd bit next.
Ah, well in that case you're going to need to add the declarations for the delays as global variables (ie at the top, outside of the setup() or loop() functions. They might look something like this:
// since negatives aren't going to be used, unsigned integer type gives twice the maximum size of normal integers
unsigned int a = 1000; // 1 sec
unsigned int b = 1500; // 1.5 sec
unsigned int c = 10000; // 10 sec
unsigned int d = 5500; // 5.5 sec
unsigned int e = 65535; // if using unsigned integer type that's the max
unsigned int f = 5; // 5ms
or for the array example I gave the same would look like:
Hi Geoff.
Got the variables to work ok. However I have problems with the display. When compiling get this error Error class liquid crystal has no member named 'clear'
I would like the lcd to give the values of a,b...f during the delay at the end before the next cycle starts. Three columns as such
a c e
b d f
Here is what I have done so far
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// here I want to enter the values of a,b,c,d,e,f, so that they will be entered automatically below
// since negatives aren't going to be used, unsigned integer type gives twice the maximum size of normal integers
unsigned int a = 55; // size of first drop in ms (best size for trajectory)
unsigned int b = 85; // time between 1st and 2nd drops
unsigned int c = 55; // size of second drop in ms
unsigned int d = 85; // time between 2nd and 3rd drops
unsigned int e = 55; // size of third drop in ms
unsigned int f = 5000; // 5 sec before restarting
void setup() {
// initialize the digital pins as an output.
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
}
void loop() {
digitalWrite(6, HIGH); // Turns ON Relay 3 on digital pin 6 (blue)
delay(a); // size of drop in ms best size for trajectory
digitalWrite(6, LOW); // Turns OFF Relay 3 on digital pin 6
delay(b); // time between 1st and 2nd drops
digitalWrite(7, HIGH); // Turns ON Relay 2 on digital pin 7 (yellow)
delay(c); // size of drop in ms
digitalWrite(7, LOW); // Turns OFF Relay 2 on digital pin 7
delay(d); // time between 2nd and 3rd drops
digitalWrite(8, HIGH); // Turns ON Relay 1 on digital pin 8 (red)
delay(e); // size of drop in ms
digitalWrite(8, LOW); // Turns OFF Relay 1 on digital pin 8
// here I want the display info
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print(" a c e ");
// b d f
delay(f); // Delay before recycling
}
Firstly I see the mods keep editing your posts Remember to use the # button to encode the sketch samples inside CODE tags.
I'm not sure what the impact of running this over and over is, but I'd move it to inside the setup() function as it only needs to be initialised the once:
lcd.begin(16, 2);
I don't see where you're using clear() in the code you've provided to give you that error though?
I said I was a novice
What does this mean?
'Firstly I see the mods keep editing your posts Remember to use the # button to encode the sketch samples inside CODE tags'
Where do I find the info on this please
Well I am really proud of myself.
The lcd displays the information that I want and it stays there until it is altered,
Thanks to those who gave me guidance
The full sketch
/ include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// here I want to enter the values of a,b,c,d,e,f, so that they will be entered automatically below
unsigned int a = 55; // size of first drop in ms (best size for trajectory)
unsigned int b = 85; // time between 1st and 2nd drops
unsigned int c = 55; // size of second drop in ms
unsigned int d = 85; // time between 2nd and 3rd drops
unsigned int e = 55; // size of third drop in ms
unsigned int f = 5000; // 5 sec before restarting
void setup() {
// initialize the digital pins as an output.
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
}
void loop() {
digitalWrite(6, HIGH); // Turns ON Relay 3 on digital pin 6 (blue)
delay(a); // size of drop in ms best size for trajectory
digitalWrite(6, LOW); // Turns OFF Relay 3 on digital pin 6
delay(b); // time between 1st and 2nd drops
digitalWrite(7, HIGH); // Turns ON Relay 2 on digital pin 7 (yellow)
delay(c); // size of drop in ms
digitalWrite(7, LOW); // Turns OFF Relay 2 on digital pin 7
delay(d); // time between 2nd and 3rd drops
digitalWrite(8, HIGH); // Turns ON Relay 1 on digital pin 8 (red)
delay(e); // size of drop in ms
digitalWrite(8, LOW); // Turns OFF Relay 1 on digital pin 8
// here I want to display the timeing info on the lcd
// Print a message to the lcd in this format
// a c e
// b d f
lcd.setCursor(0,0); //1st position 1st row
lcd.print(a);
lcd.print(" ");
lcd.print(c);
lcd.print(" ");
lcd.print(e);
lcd.setCursor(0,1); // 1st position on 2nd row
lcd.print(b);
lcd.print(" ");
lcd.print(d);
lcd.print(" ");
lcd.print(f);
delay(f); // Delay before recycling
}