Set variable and bypass code?

After feedback from Robin2 I restated my question in #2 below.

A couple of things

Line 28 creates another variable with the same name as line 11. If the purpose of line 28 is to set the value to 0 then remove the int from the start of the line. It would probably be easier to delete line 28 and add = 0 to line 11

In lines 58 and 62 you set the value of pause_cf but I see no line that uses that variable in a decision

...R

Robin2:
A couple of things

…R

Thank you. I did some housekeeping to my sketch. I’ll try again.

This is what I am trying to accomplish starting at line 66:

  if (pause_cf == 1) {          // if pause_cf = 1, (set at line 49)
     (cf_lp);                   // then advance to void cf_lp at line 73
     } else {                   // else
     digitalWrite(cf_rl, HIGH); // turn off relay and
     (loop);                    // advance to void loop
  }                             // stay like this until pause_cf = 0, (set at line 54)

This is the full code:

#include <Bounce2.h>
#include <SoftwareSerial.h>
const int  grn_led = 5;   //green led
const int  blu_led = 6;   //blue led
const int  cf_rl = 2;     //relay 1
const int  bf_rl = 3;     //relay 2
const int  cf_low = 7;    //low sensor
const int  cf_up = 8;     //high sensor
SoftwareSerial Genotronex(10,11); //Rx,Tx
int BluetoothData;
int state_cf_rl;
int prevstate_cf_rl;
int pause_cf;
int pause_bf;  
Bounce db1 = Bounce();
Bounce db2 = Bounce();

void setup() {
  pinMode(grn_led, OUTPUT);
  pinMode(blu_led, OUTPUT);
  pinMode(cf_rl, OUTPUT);
  pinMode(bf_rl, OUTPUT);
  pinMode(cf_low, INPUT);
  pinMode(cf_up, INPUT);
  Genotronex.begin(9600);
  Genotronex.println("Bluetooth Connect");
  db1.attach(cf_up);
  db1.interval(500);
  db2.attach(cf_low);
  db2.interval(25);
}

void loop() {
// Bluetooth Input
  if (Genotronex.available()) {
     BluetoothData = Genotronex.read();

    if (BluetoothData == '0') {
       (pause_bf = 0); 
       Genotronex.println("bf_rl On");
    }
    
    if (BluetoothData == '1') {
       (pause_bf = 1);
       Genotronex.println("bf_rl Off");
    }

    if (BluetoothData == '6'){
       (pause_cf = 1);
       Genotronex.println("cf_rl On");
    }

    if (BluetoothData == '7') {
       (pause_cf = 0);
       Genotronex.println("cf_rl Off");
    }
  }
  
// Variables Written by Bluetooth   
  if (pause_bf == 0) {
     digitalWrite(bf_rl, HIGH);
     } else {
     digitalWrite(bf_rl, LOW); 
  }

  if (pause_cf == 1) {          // if pause_cf = 1, (set at line 49)
     (cf_lp);                   // then advance to void cf_lp at line 73
     } else {                   // else
     digitalWrite(cf_rl, HIGH); // turn off relay and
     (loop);                    // advance to void loop
  }                             // stay like this until pause_cf = 0, (set at line 54)
}

void cf_lp(){
// CF Behavior
  db1.update();
  db2.update();
  int value1 = db1.read();
  int value2 = db2.read();
    
  if ( value1 != LOW ) {
     digitalWrite(cf_rl, HIGH);
  }
  else if  (value2 != HIGH ){
     digitalWrite(cf_rl, LOW);
  }
    
  state_cf_rl = digitalRead(cf_rl);
  if (prevstate_cf_rl != state_cf_rl) {
  if (state_cf_rl == HIGH) {
     Genotronex.println("cf_rl Off");
  } else {
     Genotronex.println("cf_rl On");
  };
     prevstate_cf_rl = state_cf_rl;
  };
}

Don't use goto's... That's a relic of ancient times. Now we have functions! (Or even methods f we're getting into OOP.) Way easier to follow, easier to write and less pitfalls.

septillion:
Don't use goto's... That's a relic of ancient times. Now we have functions! (Or even methods f we're getting into OOP.) Way easier to follow, easier to write and less pitfalls.

Perhaps goto was a poor choice of words on my part. I don't think I'm asking to literally use an actual goto.

Or do I misunderstand entirely and my if/then/else construction == a goto?

In any case I edited post #2 for clarity, I think.

I indeed think it’s just a poor choice of words. :slight_smile:

You want to run a function :slight_smile: No, it’s not called a void. Void is just a placeholder to tell it does not return anything. So the function is just called cf_lp.

And cf_lp is indeed a function. A terrible terrible terrible terrible named function but it is a function. By calling it what it actually does you really simplify it for yourself. Short names seem because they are quick to type but they are hard to remember and impossible to tell what the function does. And this applies to variable names as well. For example lfrp may seem like a nice and short name for a variable but it tells nothing. Where as LedFlasherRightPin tells us exactly what it holds and is easy to remember.

Especially if you stick to the same way of writing it. Now you mix and match styleLikeThis with the_style_like_this. The first is kind of the Arduino preferred way.

And to run a function you simply do cf_lp(), just like you do with digitalWrite() etc.

But you should NEVER call/run loop() yourself. This is already done for you.

And some tips:

  • Press Ctrl+T in the IDE, looks better doesn’t it?

  • A closing bracket } from an if/else does not need a ;

  • Don’t point to line numbers in the comments. This is only going to confuse the crap out of you if you change the code which shifts the lines.

  • And once you start numbering variables or you have multiple times the same thing, arrays will make life more simple :wink:

warnmar10:
After feedback from Robin2 I restated my question in #2 below.

WTF did you do with the code I commented on?

Now my Reply #1 is nonsense.

Please reinstate your Original Post so that other people can make sense of it and learn along with you. This is a Forum for sharing experience.

...R

Robin2:
WTF did you do with the code I commented on?

Now my Reply #1 is nonsense.

Please reinstate your Original Post so that other people can make sense of it and learn along with you. This is a Forum for sharing experience.

...R

I apologize for the major faux pas on my part. I thought I was doing a good thing, it won't happen again.

septillion:
...

And to run a function you simply do cf_lp(), just like you do with digitalWrite() etc.

But you should NEVER call/run loop() yourself. This is already done for you.

Thank you, this is what is what had me stuck.

septillion:
And some tips:

  • Press Ctrl+T in the IDE, looks better doesn't it?

I am frankly stunned at how little difference it made to what I had written but I will use it going forward for sure!

septillion:
...

  • Don't point to line numbers in the comments. This is only going to confuse the crap out of you if you change the code which shifts the lines.

I added line numbers to my post to help describe what I was attempting and why I thought it should work. There are no line number references in my actual sketch.

septillion:

  • And once you start numbering variables or you have multiple times the same thing, arrays will make life more simple :wink:

I'm not there yet but I see where this is headed.

Thanks again for showing me the way.