One of the code group is disabling the other code group

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("       ");}}

Put each } on its own line. Post your code correctly, AFTER you read the how to post in this forum thread.

I see nothing in you first sketch that does anything to ts.

I see nothing in your description that tells me that your switches are wired correctly. Do you have external pullup or pulldown resistors? If not, since you are not using the internal pullup resistors, you can forget about reliably reading switch pins.

Of course I connected pull up/down resistors properly. So I am using Analog Input I cant read anything without pull up/down resistors, I connected it. And I think there are no problem about my hardware. Because I am making test without any changes about connections. When I add the faulty code group, my up and down buttons not working and when I delete the faulty code group up/down buttons is working.

And when I add the faulty code group there are no problem about the working of this code's algoryhtm. Just this codes is disabling my up and down buttons or something like that.

And you can found the ts counter algorythm under all codes.

I am sorry about my faults about forum rules I am gonna read the rules.

Tahnk You.

Here is a ts value counter codes and algorythm about up and 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);}

Of course I connected pull up/down resistors properly.

That may be obvious to you.

So I am using Analog Input

To read digital switches?

And you can found the ts counter algorythm under all codes.

Really?

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

Please tell me which lines increment or decrement ANY variable.

Ok thats my fault, I edit my first post. You can look the second code, which codes is under "And here is a all codes.".

Thank you so much for your helps and thank you because all of you is spending time to help us.

I edit my first post.

Good thing I copied the code before you did that. Now, don't do that again.

If you change code, post it in a reply. Don't (try to) make us look like fools, commenting on (corrected) code.

I just trying to get help. And my english is not good. I am sorry about it
And If I did any wrong thing I am sorry about it...

I didn't change any code. I just add [ code.] to my post.

So when I add this code;

//////////////////////////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

this codes is not working;

  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);}

I connected pull up/down resistors.

Is it possible the source of the problem is about analog inputs. So I am using analog inputs as an digital inputs. When I use analog Inputs as an Digital Inputs my real Digital Inputs can be disabled? Or where can be a problem. What should I check. Is there an any problem about my codes?

So when I add this code; ... this codes is not working;

http://snippets-r-us.com is down the road a ways. Maybe they can help you.

Here, we need to SEE all of your code, and we need to have some basic explanation of what the code actually does, and how that differs from what you want.

I didn't change any code. I just add [ code.] to my post.

Oh. Well, then. I apologize for over-reacting.

I connected pull up/down resistors.

Which is it?

Is it possible the source of the problem is about analog inputs. So I am using analog inputs as an digital inputs.

No. If you are using the analog pins as digital pins, with pinMode() and digitalRead() statements, they work the same as digital-only pins.

What should I check. Is there an any problem about my codes?

I suggest that you:

  1. put every { on a new line.
  2. put every } on a new line.
  3. use Tools + Auto Format to fix your terrible indenting.
  4. post ALL of your code.

Which is it?

I am using pull up resistors. So I am connecting the Inputs 5v with a resistor, when I press the button 0V is coming and making my input LOW. I hope thats right way.

  1. put every { on a new line.
  2. put every } on a new line.
  3. use Tools + Auto Format to fix your terrible indenting.

I tried to use Auto Format to fix but I took "Auto Format Canceled: Too many left curly braces." error. Lol maybe computers cant smart enough to fix my terrible indenting or I am making wrong again :slight_smile:

  1. post ALL of your code.

Here is all of my code.

#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("       ");}}

I tried to use Auto Format to fix but I took "Auto Format Canceled: Too many left curly braces." error. Lol maybe computers cant smart enough to fix my terrible indenting

The IDE is smart enough to fix your terrible indenting IF you are smart enough to use the correct } for every {.

Since you weren't, YOU need to properly indent the code until you find where you have a } that is not a match for a {. I've done that, but I don't know that what I ended up with is what you meant.

Ok, problem is solved.

PaulS thank you! I couldnt see. And as I said my english is not good enough. Thank you for your patience!

I can't believing I did a stupid mistake like this. Thank you again! :slight_smile: