I'm a newbie here. And sorry for my bad English first of all.
Right now I'm working on VLC (Visible Light Communication). I have working code, in which output is displayed on the Serial Monitor. But now I want to print this output on an LCD.
I made necessary changes like including the LCD library and instead of Serial.print
I used lcd.print
. But nothing is displayed on the LCD.
Here is the modified code including LCD:
static int TRESHOLD = 500;
static unsigned int standardDelay = 13500000; //1350 is limit
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 7,6,5,4);
void setup() {
Serial.begin(9600); // 9600 bits per second
pinMode(3,OUTPUT); //digital PWM 3 on output
int sensorValue = 0;
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// initialize the serial communications:
}
void loop() {
WriteChar('h');
WriteChar('e');
WriteChar('l');
WriteChar('l');
WriteChar('o');
WriteChar('w');
WriteChar('o');
WriteChar('r');
WriteChar('l');
WriteChar('d');
}
void WriteChar(char str){
switch (str - '0'){
case 49:
//code for a is 011 0001
LightFlash(false, true, true, false, false, false, true);
break;
case 50:
//code for b is 011 0010
LightFlash(false, true, true, false, false, true, false);
break;
case 51:
//code for c is 011 0011
LightFlash(false, true, true, false, false, true, true);
break;
case 52:
//code for d is 011 0100
LightFlash(false, true, true, false, true, false, false);
break;
case 53:
//code for e is 011 0101
LightFlash(false, true, true, false, true, false, true);
break;
case 54:
//code for f is 011 0110
LightFlash(false, true, true, false, true, true, false);
break;
case 55:
//code for g is 011 0111
LightFlash(false, true, true, false, true, true, true);
break;
case 56:
//code for h is 011 1000
LightFlash(false, true, true, true, false, false, false);
break;
case 57:
//code for i is 011 1001
LightFlash(false, true, true, true, false, false, true);
break;
case 58:
//code for j is 011 1010
LightFlash(false, true, true, true, false, true, false);
break;
case 59:
//code for k is 011 1011
LightFlash(false, true, true, true, false, true, true);
break;
case 60:
//code for l is 011 1100
LightFlash(false, true, true, true, true, false, false);
break;
case 61:
//code for m is 011 1101
LightFlash(false, true, true, true, true, false, true);
break;
case 62:
//code for n is 011 1110
LightFlash(false, true, true, true, true, true, false);
break;
case 63:
//code for o is 011 1111
LightFlash(false, true, true, true, true, true, true);
break;
case 64:
//code for p is 100 0000
LightFlash(true, false, false, false, false, false, false);
break;
case 65:
//code for q is 100 0001
LightFlash(true, false, false, false, false, false, true);
break;
case 66:
//code for r is 100 0010
LightFlash(true, false, false, false, false, true, false);
break;
case 67:
//code for s is 100 0011
LightFlash(true, false, false, false, false, true, true);
break;
case 68:
//code for t is 100 0100
LightFlash(true, false, false, false, true, false, false);
break;
case 69:
//code for u is 100 0101
LightFlash(true, false, false, false, true, false, true);
break;
case 70:
//code for v is 100 0110
LightFlash(true, false, false, false, true, true, false);
break;
case 71:
//code for w is 100 0111
LightFlash(true, false, false, false, true, true, true);
break;
case 72:
//code for x is 100 1000
LightFlash(true, false, false, true, false, false, false);
break;
case 73:
//code for y is 100 1001
LightFlash(true, false, false, true, false, false, true);
break;
case 74:
//code for z is 100 1010
LightFlash(true, false, false, true, false, true, false);
break;
default:
lcd.print(str - '0');
lcd.print("CAME IN DEFAULT IN WRITECHAR");
break;
}
}
void LightFlash(boolean a, boolean b, boolean c, boolean d, boolean e, boolean f, boolean g){
digitalWrite(3,LOW);
if (a == true){
digitalWrite(3,HIGH);
}
delayMicroseconds(standardDelay/2);
boolean sensorValue1 = (analogRead(A0)>TRESHOLD);
delayMicroseconds(standardDelay/2);
digitalWrite(3,LOW);
if (b == true){
digitalWrite(3,HIGH);
}
delayMicroseconds(standardDelay/2);
boolean sensorValue2 = (analogRead(A0)>TRESHOLD);
delayMicroseconds(standardDelay/2);
digitalWrite(3,LOW);
if (c == true){
digitalWrite(3,HIGH);
}
delayMicroseconds(standardDelay/2);
boolean sensorValue3 = (analogRead(A0)>TRESHOLD);
delayMicroseconds(standardDelay/2);
digitalWrite(3,LOW);
if (d == true){
digitalWrite(3,HIGH);
}
delayMicroseconds(standardDelay/2);
boolean sensorValue4 = (analogRead(A0)>TRESHOLD);
delayMicroseconds(standardDelay/2);
digitalWrite(3,LOW);
if (e == true){
digitalWrite(3,HIGH);
}
delayMicroseconds(standardDelay/2);
boolean sensorValue5 = (analogRead(A0)>TRESHOLD);
delayMicroseconds(standardDelay/2);
digitalWrite(3,LOW);
if (f == true){
digitalWrite(3,HIGH);
}
delayMicroseconds(standardDelay/2);
boolean sensorValue6 = (analogRead(A0)>TRESHOLD);
delayMicroseconds(standardDelay/2);
digitalWrite(3,LOW);
if (g == true){
digitalWrite(3,HIGH);
}
delayMicroseconds(standardDelay/2);
boolean sensorValue7 = (analogRead(A0)>TRESHOLD);
delayMicroseconds(standardDelay/2);
delayMicroseconds(3*standardDelay); //1 second passed
long result = 0;
result = 1000000*sensorValue1 + 100000*sensorValue2 + 10000*sensorValue3
+ 1000*sensorValue4 + 100*sensorValue5 + 10*sensorValue6 + 1*sensorValue7;
//lcd.print(result);
PrintChar(result);
}
void PrintChar(long binary){
switch (binary){
case 110001:
//code for a is 011 0001
lcd.write("a");
break;
case 110010:
//code for b is 011 0010
lcd.print("b");
break;
case 110011:
//code for c is 011 0011
lcd.print("c");
break;
case 110100:
//code for d is 011 0100
lcd.print("d");
break;
case 110101:
//code for e is 011 0101
lcd.print("e");
break;
case 110110:
//code for f is 011 0110
lcd.print("f");
break;
case 110111:
//code for g is 011 0111
lcd.print("g");
break;
case 111000:
//code for h is 011 1000
lcd.print("h");
break;
case 111001:
//code for i is 011 1001
lcd.print("i");
break;
case 111010:
//code for j is 011 1010
lcd.print("j");
break;
case 111011:
//code for k is 011 1011
lcd.print("k");
break;
case 111100:
//code for l is 011 1100
lcd.print("l");
break;
case 111101:
//code for m is 011 1101
lcd.print("m");
break;
case 111110:
//code for n is 011 1110
lcd.print("n");
break;
case 111111:
//code for o is 011 1111
lcd.print("o");
break;
case 1000000:
//code for p is 100 0000
lcd.print("p");
break;
case 1000001:
//code for q is 100 0001
lcd.print("q");
break;
case 1000010:
//code for r is 100 0010
lcd.print("r");
break;
case 1000011:
//code for s is 100 0011
lcd.print("s");
break;
case 1000100:
//code for t is 100 0100
lcd.print("t");
break;
case 1000101:
//code for u is 100 0101
lcd.print("u");
break;
case 1000110:
//code for v is 100 0110
lcd.print("v");
break;
case 1000111:
//code for w is 100 0111
lcd.print("w");
break;
case 1001000:
//code for x is 100 1000
lcd.print("x");
break;
case 1001001:
//code for y is 100 1001
lcd.print("y");
break;
case 1001010:
//code for z is 100 1010
lcd.print("z");
break;
case 11000:
lcd.print("dit gebeurt vaak");
break;
case 1011001:
lcd.print("dit ook");
break;
case 100001:
lcd.print("tenslotte dit nog");
break;
case 1011000:
lcd.print("en dit is de laatste denk ik");
break;
default:
lcd.print(binary);
lcd.print("CAME IN DEFAULT ON PRINTCHAR");
break;
}
}
I want to print this output on LCD. But I'm not able to do that. Please help me out.
Circuits:
(1) VLC Circuit
(2) LCD Circuit
I combined both circuits above and made a final circuit.
The VLC circuit is set up in which DATA is transmitted from SIMPLE LED and Capture on PHOTODIODE. And using LCD Circuit I want to display data on LCD.
-
1I don't see any code related to the LCD.Michel Keijzers– Michel Keijzers2017年07月10日 11:24:15 +00:00Commented Jul 10, 2017 at 11:24
-
@MichelKeijzers Becuase I remove it and upload original code. Already I mention that thing. Just check it out above the code. Ok...PRATIK I PANCHAL– PRATIK I PANCHAL2017年07月10日 11:25:25 +00:00Commented Jul 10, 2017 at 11:25
-
Not enough information. Post your LCD code and schematics.user31481– user314812017年07月10日 11:31:29 +00:00Commented Jul 10, 2017 at 11:31
-
@LookAlterno Ok, let me.PRATIK I PANCHAL– PRATIK I PANCHAL2017年07月10日 11:32:13 +00:00Commented Jul 10, 2017 at 11:32
-
1Connecting a LCD display to an Arduino is not easy because of all those wires and the contrast and the cheap displays need enough voltage (above 4.5 V). I had some trouble with it myself. The second time it was a piece of cake. Forget your project for a moment and make a sketch that only uses the LCD. Start here: arduino.cc/en/Reference/LiquidCrystalJot– Jot2017年07月10日 11:45:24 +00:00Commented Jul 10, 2017 at 11:45
2 Answers 2
There is so many problems with your code. It can be so much short.
Take WriteChar. Why mess with binary value for chars? Use char directly, just here:
void setup() {
Serial.begin(9600);
WriteChar('h');
WriteChar('e');
}
void loop() {
}
void WriteChar(char c) {
boolean b7 = c & B1000000;
boolean b6 = c & B0100000;
boolean b5 = c & B0010000;
boolean b4 = c & B0001000;
boolean b3 = c & B0000100;
boolean b2 = c & B0000010;
boolean b1 = c & B0000001;
Serial.println(c);
LightFlash(b7, b6, b5, b4, b3, b2, b1);
}
void LightFlash(boolean b7, boolean b6, boolean b5, boolean b4, boolean b3, boolean b2, boolean b1) {
Serial.print(b7 ? "1" : "0");
Serial.print(b6 ? "1" : "0");
Serial.print(b5 ? "1" : "0");
Serial.print(b4 ? "1" : "0");
Serial.print(b3 ? "1" : "0");
Serial.print(b2 ? "1" : "0");
Serial.println(b1 ? "1" : "0");
}
There is more simply ways to write that (using arrays and loops) but this is easier to understand. And better, pass the char directly to LightBlash.
Don't use a string when you just pass a char to a function.
Finally, got the problem. My code is working fine. I have a problem with my LCD connection.
I write
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
Instead of
LiquidCrystal lcd(12, 11, 4, 5, 6, 7);