Hi all
I have problem about my arduino codes. I have three button three LED and few analog inputs. Button1 is up buton to make higher my ts value. Button2 is down buton to make lower my ts value. Button 3 is for choose the which value I want to see on my LCD, so TRR or TOR values.
But when I add the Button3’s algorythm my up and down buttons isnt working. I tried to delete Button3’s algorythm and the problem is solved so up and down buttons was changing my value. But when I add the Button3’s code group again my up down buttons didn’t work again.
Button 3 is connected to analog input. And I am calling analog inputs as an digital input like 14-19. So for A0 I am using 14 as a pin number.
How can I solve the problem? Where should I look for the problem?
I hope there is a right place to ask. And I am sorry about my bad english...
Here is a Button3’s algorythm.
//////////////////////////FAULTY CODES
bt3s = digitalRead(bt3);
if (bt3s != lbt3s){
if (bt3s == HIGH){
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("TOR:");
lcd.setCursor(4,1);
lcd.print(tor);
lcd.setCursor(6,1);
lcd.print(" ");}
else{
lcd.setCursor(0,1);
lcd.print("TRRV:");
lcd.setCursor(5,1);
lcd.print(trr);}
lbt3s = bt3s;
///////////////////////////////FAULTY CODES
And here is a all codes.
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int rov = 0;
int tr = A0;
int trr = 0;
int to = A1;
int tor = 0;
int ts = 0;
int tm = A2;
int tmr = 0;
int po = A3;
int pos = 0;
int up = 7;
int buttonstate = 0;
int lastbuttonstate = 0;
int buttonstate1 = 0;
int lastbuttonstate1 = 0;
int down = 6;
int bt3 = 19;
int bt3s = 0;
int lbt3s = 0;
int LED3 = 8;
int LED2 = 9;
int LED1 = 10;
int x1 = 40;
int x2 = 40;
int x3 = 40;
int x4 = 35;
void setup() {
lcd.begin(16,2);
pinMode(up, INPUT);
pinMode(down, INPUT);
pinMode(po, INPUT);
pinMode(LED3, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED1, OUTPUT);
lcd.setCursor(0,0);
lcd.print("OPENING");
delay(3000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("LED1");
lcd.setCursor(0,1);
lcd.print("TOR:00 TSR:00");
}
void loop(){
digitalWrite(LED3, HIGH);
digitalWrite(LED1, HIGH);
tor = analogRead(to)/x1;
trr = analogRead(tr)/x2;
tmr = analogRead(tm)/x3;
lcd.setCursor(5,0);
lcd.print("ON");
lcd.setCursor(14,1);
lcd.print(trr+ts);
//////////////////////////FAULTY CODES
bt3s = digitalRead(bt3);
if (bt3s != lbt3s){
if (bt3s == HIGH){
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("TOR:");
lcd.setCursor(4,1);
lcd.print(tor);
lcd.setCursor(6,1);
lcd.print(" ");}
else{
lcd.setCursor(0,1);
lcd.print("TRRV:");
lcd.setCursor(5,1);
lcd.print(trr);}
lbt3s = bt3s;
///////////////////////////////FAULTY CODES
/////////////////////////////////////////////////value setting with up down buttons
buttonstate = digitalRead(up);
if (buttonstate != lastbuttonstate){
if (buttonstate == LOW){
ts++;}}
lastbuttonstate = buttonstate;
//////////
buttonstate1 = digitalRead(down);
if (ts > -10){
if (buttonstate1 != lastbuttonstate1){
if (buttonstate1 == LOW){
ts--;}}
lastbuttonstate1 = buttonstate1;
delay(10);}
//////////////////////////////////////////////////////////////////comparator algorythm
if (tor > trr+ts) {
digitalWrite(LED2, HIGH);
lcd.setCursor(9,0);
lcd.print("LED2ON");
}
if (tor < trr+ts) {
digitalWrite(LED2, LOW);
lcd.setCursor(9,0);
lcd.print(" ");}}