Hi,
One code has a way to definite LCD like:
//LCD Output
#ifdef LCD_PRINT
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2); //RS,E,D4,D5,D6,D7
#endif
any specialities and advantages?
Thanks
Adam
Hi,
One code has a way to definite LCD like:
//LCD Output
#ifdef LCD_PRINT
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2); //RS,E,D4,D5,D6,D7
#endif
any specialities and advantages?
Thanks
Adam
Compared to what?
What other way(s) have you seen it definited?
a7
HI @shanren
For this library (<LiquidCrystal.h>) this is the default format.
RV mineirin
class LiquidCrystal : public Print {
public:
LiquidCrystal(uint8_t rs, uint8_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);
LiquidCrystal(uint8_t rs, uint8_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);
Thanks.
I used to do this way, and that works.
#include <LiquidCrystal.h>
///// const int rs = 8, en = 9, d4 = 10, d5 = 11, d6 = 12, d7 = 13;
const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(7, 6, 5, 4, 3, 2); //RS,E,D4,D5,D6,D7
Explain better.
Thanks.
Attached a code below, that doesn't make my LCD work. if comment out all #ifdef LCD_PRINT
and #endif
, my LCD works.
/*
#include <LiquidCrystal.h>
///// const int rs = 8, en = 9, d4 = 10, d5 = 11, d6 = 12, d7 = 13;
const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
*/
//LCD Output
#ifdef LCD_PRINT
#include <LiquidCrystal.h>
///// const int rs = 8, en = 9, d4 = 10, d5 = 11, d6 = 12, d7 = 13;
const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(7, 6, 5, 4, 3, 2); //RS,E,D4,D5,D6,D7
#endif
void setup() {
// put your setup code here, to run once:
#ifdef LCD_PRINT
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("ADAMDIY-ADMM");
delay(1000);
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("hello, world!");
delay(1000);
#endif
}
void loop() {
// put your main code here, to run repeatedly:
}
Go learn about
# define
# ifdef
and
# endif
You don’t
# define LCD_PRINT
anywhere, so you code gets skipped. Not included.
a7
Hi @shanren
There is no definition of LCD_PRINT
try this sketch:
/*
#include <LiquidCrystal.h>
///// const int rs = 8, en = 9, d4 = 10, d5 = 11, d6 = 12, d7 = 13;
const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
*/
#define LCD_PRINT
//LCD Output
#ifdef LCD_PRINT
#include <LiquidCrystal.h>
///// const int rs = 8, en = 9, d4 = 10, d5 = 11, d6 = 12, d7 = 13;
//const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(7, 6, 5, 4, 3, 2); //RS,E,D4,D5,D6,D7
#endif
void setup() {
// put your setup code here, to run once:
#ifdef LCD_PRINT
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("ADAMDIY-ADMM");
delay(1000);
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("hello, world!");
delay(1000);
#endif
}
void loop() {
// put your main code here, to run repeatedly:
}
Thanks.
Thanks.
The sketch works well.
Is this mean every time if I like to display some thing, I always need use this pattern?
#ifdef LCD_PRINT
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("xxxx");
delay(1000);
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("yyyy");
delay(1000);
#endif
and how about the post #3, that just need one time right?
Thanks.
In post #3 I just showed how it is written inside the library "LiquidCrystal".
RV mineirin
Thank you.
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.