Greetings from Kazakhstan.
I've received my Arduino Starter Kit about a week ago, and after making all projects in the book i've decided to make something on my on.
The decision as to make a simple combination lock, using 10k potentiometer and LCD. The result is in attached file. The principle is simple - until you wont enter the correct first digit and hold it for 3 seconds, you wont be able to enter the second digit and etc.
The problem that i've encountered is that when i adjust potentiometer to number 9, LCD somehow shows 9 as 90 and accepts it as correct digit. But after switch to third digit, it's shown as 9. After spinning a potentiometer, it once again show 9 as 90. The same goes to all one-digit numbers.
What could be the possible problem and it's solution?
Some additional info:
- Potentiometer value is mapped as (potVal, 0, 1023, 0, 99);
- Serial monitor shows 9 as 9
- Potentiometers included in starter kit are horrible. Their pins are bigger than breadboard holes, had to use pliers to adjust them =/
- It's 5:25 in the morning here, and i have only one solutions i came up to, whih is not using one-digit numbers. But it sucks, one-digit numbers are cool.
Also, here's the code (pretty bulky, Im a complete noob in programming).
#include <LiquidCrystal.h>;
LiquidCrystal lcd(12,11,5,4,3,2);
const int code1 = 23;
const int code2 = 9;
const int code3 = 88;
int Position = 0;
int potVal;
int currCode;
int val = 0;
int currPosition;
long prevMillis = 0;
byte p2 [8] = {
B00000,
B00000,
B00000,
B11111,
B00000,
B00000,
B00000,
};
void setup (){
lcd.begin(16,2);
lcd.print ("Enter code");
lcd.createChar (0, p2);
lcd.setCursor (2,1);
lcd.write ((byte)0);
lcd.setCursor (5,1);
lcd.write ((byte)0);
}
void loop (){
if (currPosition != 3){
lcd.setCursor (10,1);
lcd.print ("Locked");
}
potVal = analogRead (A0);
currCode = map (potVal, 0, 1023, 0, 99);
if (currPosition == Position){
lcd.setCursor (0,1);
lcd.print (currCode);
if (currCode == code1){
if(millis() - prevMillis > 1000){
prevMillis = millis();
val++;
}
}
else { val = 0;
}
if (val>=3){
lcd.setCursor (0,1);
lcd.print (code1);
currPosition = 1;
val = 0;
}
}
if (currPosition == 1){
lcd.setCursor (3,1);
lcd.print (currCode);
if (currCode == code2){
if (millis() - prevMillis > 1000){
prevMillis = millis();
val++;
}
}
else { val = 0;
}
if (val>=3){
lcd.setCursor (3,1);
lcd.print (code2);
currPosition = 2;
val = 0;
}
}
if (currPosition == 2){
lcd.setCursor (6,1);
lcd.print (currCode);
if (currCode == code3){
if(millis() - prevMillis > 1000){
prevMillis = millis();
val++;
}
}
else { val = 0;
}
if (val>=3){
lcd.setCursor (6,1);
lcd.print (code3);
val = 0;
currPosition = 3;
}
}
if (currPosition == 3){
lcd.setCursor (10,1);
lcd.print ("Opened");
}
}
Thank you in advance, community!