Hello all,
I am having trouble implementing a 4-wire sainsmart lcd2004 into my project. I have a working project without the lcd, but i need to add it in. It is due for class in a few hours, so you can imagine it is time sensitive. The LCD is 20x4. The wire inputs are VCC at Arduino VCC, ground at Arduino ground, SDA at A4, and SCL at A5. Any help would be much appreciated. Thank you!
Here is my code:
#include <LiquidCrystal.h>
#include <Servo.h>
String keys="123A456B789C*0#D";
int key;
boolean key_lockout=false;
int button1 = 7;
int press1 = 0;
int pos = 90;
int led = 8;
int led2 = 9;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
Servo servo1;
void setup()
{
Serial.begin(9600);
lcd.begin(16,2);//hjhjkhhkjhkjhjhkhkjhjhjjkhjkhjhjhkhjjhkjhj
lcd.print("Insert Passkey"); //0ohiuihkj
pinMode(button1, INPUT);
pinMode(led, OUTPUT);
pinMode(led, OUTPUT);
servo1.attach(13);
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
}
char password[]={"1234"};
char enteredString[5]={""};
int stringPos=0;
void loop(){
key=getKeypad();
if( (key>-1) && (keys[key]!='*') && (keys[key]!='#') )
{
//save current char
enteredString[stringPos++]=keys[key];
//terminate string
enteredString[stringPos]=0;
//prevent writing past end of string
stringPos -= (stringPos > 3);
Serial.print(keys[key]);
lcd.print(keys[key]); //gyghgjgjhghjhhjgjhghgjhhjhjhhhhhhhh
delay(10);
}
if (keys[key] =='#')
{//reset ready for next attempt
Serial.println("");
stringPos=0;
if ( strcmp(enteredString, password)==0)
{digitalWrite(led, HIGH);
Serial.println("Quick, it's open");
servo1.write(0);
delay(5000);
servo1.write(90);
digitalWrite(led, LOW);
digitalWrite(led2, HIGH);
delay(1000);
digitalWrite(led2, LOW);
}
else
digitalWrite(led2, HIGH);
Serial.println("GO AWAY!");
delay(1000);
digitalWrite(led2, LOW);
}
press1 = digitalRead(button1);
if (press1==LOW)
{
digitalWrite(led, HIGH);
servo1.write(0);
delay(5000);
servo1.write(90);
digitalWrite(led, LOW);
digitalWrite(led2, HIGH);
delay(1000);
digitalWrite(led2, LOW);
}
}
int getKeypad(){
int ret=-1;
boolean reset_lockout=false;
if(analogRead(A0)==0)
key_lockout=false;
else if(!key_lockout){
delay(20);
ret=15-(log((analogRead(A0)-183.9)/58.24)/0.1623)+0.5;
key_lockout=true;
}
return ret;
}
Thanks again.