Need help with my user function DRP

I do not understand why I have to digitalRead(pause) -- a grounded pin => 0
versus int x = 0
for the DRP function to work properly......
What am I missing????

calling routine    EXECTM( int row, int col, String cmd, int utime)


call
   DRP  0, time, cmd   [up/dn/hold/wait]   1st 1/4 sec displayed on LCD
   DRP  1, time, cmd   [up/dn/hold/wait]   2nd 1/4 sec
   DRP  2, time, cmd   [up/dn/hold/wait]   3rd 1/4 sec
   DRP  3, time, cmd   [up/dn/hold/wait]   4th 1/4 sec

process time & disp on LCD
---------- LCD DISPLAY --------------------
[UPDN   xx     xx  {UP* or DN#} {0/1/2/3} ]
[HOLD   xx     xx                  {HOLD} ]
[WAIT   xx     xx                  {WAIT} ]
[TIME   xxM    rmM            {total sec} ]
-------------------------------------------
//================================================================================
//   Routine keeps table and weight close to gather to decrease up/dn travel
//   Routine also adjusts while in down/wait periods
//   Note could not get Routine  to work without digitalRead grnd pin 4 [Feature enb]
//   Don't understand difference between digitalRead = 0 vs interger = 0
//   I must be missing something 
//---------------------------------------------------------------------------------
void DRP( int x,int utime , String cmd)                                 // x = 3,2,1,0  contact =  z = 0 = dn/wait ,7= other
  {   Feature1 = 0;                                                     // feature inst = 0 OR pause [pin 4 grounded]                               
      if((cmd == " DN#  ") || (cmd == " WAIT ")) { goto DnWait; }       //  tray down or waiting [ floating weight ]
      goto nock;                                                        //
 DnWait:                                 // cannot set an integer =0 as feature.. need grnd actual pin  ?? DON'T UNDERSTAND      
      //---------------------------------------------------------------------------                            
      if(digitalRead(Feature) != 0) { goto nock;  }  // table stops using this for some reason ????  Feature is Pin D4 grounded   
      //if(Feature1 != 0) { goto nock;  }            // table continues to limit
      //---------------------------------------------------------------------------
      if(digitalRead(pause) == 1) { digitalWrite(DN,LOW); goto nock; }  // pause is switches removing  ground [weight clears tray]                                           digitalWrite(DN,HIGH);                                           // weight sw contacts tray start DN  when Weight is Contacting                                       lcd.setCursor(19,0); lcd.print(x);                               //             
       delay(250);                                                      //   
       digitalWrite(DN,LOW);                                            // STOP DN after 250 ms hopefully Weight !Contacting 
       goto nock1;                                                      //
 nock:                                                                  //
       lcd.setCursor(19,0); lcd.print(x);                               //  update LCd display               
       delay(250);                                                      //  
 nock1:                                                                 //
       BrkKey = kpd.getKey();                                           // 1/4 sec interval BREAK/ABORT KEY check                                         
    }                                                                   //
//=========================================================================

Read the pinned post re 'How to get the most from the forum'

Please correct your post and add code tags around your code.

There is a small pencil image below your existing posts.

  • click on this pencil ➜ that will let you edit your post.
  • Select the part of the text that corresponds to the code
  • Click on the <code/> icon in the toolbar to indicate that it is code
  • click image Save Edit

(Also make sure to properly indent the code in the IDE before copying and pasting it here. This can be done by pressing ctrlT on a PC or cmdT on a Mac)


Side note: who wrote the ugly goto-s ??


To your question my bet is that whoever created that crappy code wanted to be able to modify the behavior by setting some pins high or low physically.

you're going to have to explain what you expect your code to do
why are you using gotos?

void
DRP (
    int x,
    int utime,
    String cmd) // x = 3,2,1,0 contact = z = 0 = dn/wait ,7= other
{
    Feature1 = 0; // feature inst = 0 OR pause [pin 4 grounded]
    if((cmd == " DN# ") || (cmd == " WAIT ")) { 
        goto DnWait;
    } // tray down or waiting [ floating weight ]
    goto nock;

    // cannot set an integer =0 as feature..
    // need grnd actual pin ?? DON'T UNDERSTAND
DnWait:
    //--------------------------------------------------------------------------
    if(digitalRead(Feature) != 0) {
        goto nock;
    }
    // table stops using this for some reason ???? Feature is Pin D4 grounded
    //if(Feature1 != 0) { goto nock; } // table continues to limit
    //--------------------------------------------------------------------------
    if(digitalRead(pause) == 1) {
        digitalWrite(DN,LOW);
        goto nock;
    }
    // pause is switches removing ground [weight clears tray]
    // digitalWrite(DN,HIGH);
    // weight sw contacts tray start DN when Weight is Contacting
    // lcd.setCursor(19,0); lcd.print(x);

    delay(250);
    digitalWrite(DN,LOW); // STOP DN after 250 ms hopefully Weight !Contacting
    goto nock1;

nock:
    lcd.setCursor(19,0); lcd.print(x); // update LCd display
    delay(250);

nock1:
    BrkKey = kpd.getKey(); // 1/4 sec interval BREAK/ABORT KEY check
}


a up/dn table on a actuator supporting a 35 lb weight that has a switch that indicates the weight is in contact with the table..... when table goes down, the switch tells when the weight is floating , then the table stops for a weight period, if for some reason the weight slowly slides down and trips the switch the table lowers for 250 ms approx 1" this continues until weight period is over.
The code works great , but only if I digitalRead(Feature) and get 0; if I try integer Feature=0 , the table will not stop until limit is reach, What am I missing ?

I use gotos because the are simple, and grew I up using machine code , then ASM , then dabble with others, for 62 years. I've never had a problem with gotos,.
As for the above code if I use if(Feature1) != 0 { goto nock; } the table goes to the limit
if I use if(digitalRead(Feature) != 0) { goto nock; } code works fine. I don't know why!!!

You lived in a different world than I then, I too have been coding for 66 yrs and made a ton of money sorting out other programmers' messes who used goto. I led and won the battle at IBM Canada to eliminate gotos. Seeing several helpers admonish you for using them warms my heart. However, your reluctance to acknowledge how bad they are prompts me to write this. I therefore have no choice but to turn a blind eye to your problem, and I urge all other go-to less coders to do the same. He made the mess, let him fix it.

BTW, I too started with machine code then assembler, but I didn't need a rock to fall on my head to realize how bad goto was. I can see your error. I can also see how ugly your code is with goto, get rid of them and use proper if else and I bet you find it as well.
I won't mute this thread as I normally would as I expect it is about to get very entertaining.

I also used goto statements when programming using assembly language, Fortran, etc
however, when programming in Algol, Pascal, C, C++, java, etc where improved conditional and control structures were available I would use them
occasionally in C it may necessary to use a goto to breakout of a nested control structure on an error condition - in C++, Java, etc one would throw an Exception

  • “I would not use them” ?

what does the Feature pin indicate?

Do you understand we have no clue what feature and feature1 are ?
Pins numbers maybe ? Then digitalRead makes sense to know the status…

I’m out anyway as you did not care to add the code tags in your first post.

I had hope folks with a few decades under their belt would have some attention for our best practices… This shows very little care for our forum so my time will be better spent else

Feature means installed = 0 not installed = 1 pin 5 is feature pin connected to ground
pause is pin 4 and connected to switch 0 = table contact 1 = floating
... as for adding tags is was not obvious to me as to what to do... I did see add tic's
' single line ' or ''' multi lines '''

Sonofcy
As for gotos I'll always use them , after all BREAK is a goto to the end of what ever that block of code is....
Its only a 12 lines of code , and to anybody that really looks at it's code and comments it is straight forward.

I just want to know why I have to use if(digitalRead(Feature) != 0) { goto nock; }
and cannot use if(Feature1 != 0) { goto nock; }
and don't blame it on gotos. Once I find the solution maybe I try to create it without
gotos, but I doubt it. Programming was only a hobby not a profession.

thanks J-M-L for the edit info

code ??

//================================================================================
//   Routine keeps table and weight close to gather to decrease up/dn travel
//   Routine also adjusts while in down/wait periods
//   Note could not get Routine  to work without digitalRead grnd pin 5 [Feature enb]
//   Don't understand difference between digitalRead = 0 vs interger = 0
//   I must be missing something 
//---------------------------------------------------------------------------------
//---------------------------------------------------------------------------------
void DRP( int x,int utime , String cmd)                                 // x = 3,2,1,0  contact =  z = 0 = dn/wait ,7= other
  {   Feature1 = 0;    // installed                                                                  //
      if((cmd == " DN#  ") || (cmd == " WAIT ")) { goto DnWait; }       //  tray down or waiting [ floating weight ]
      goto nock;                                                        //
 DnWait:                                 // cannot set an integer =0 as feature.. need grnd actual pin  ?? DON'T UNDERSTAND                                        
      if(digitalRead(Feature) != 0) { goto nock;  }                     // must have this for some reason ????  Feature is Pin D4 grounded   
      //if(Feature1 != 0) { goto nock;  }  // NOT WORK
      if(digitalRead(pause) == 1) { digitalWrite(DN,LOW); goto nock; }  // pause is switches removing  ground [weight clears tray]                                                                                             
       digitalWrite(DN,HIGH);                                           // weight sw contacts tray start DN  when Weight is Contacting                                    
       lcd.setCursor(19,0); lcd.print(x);                               //             
       delay(250);                                                      //   
       digitalWrite(DN,LOW);                                            // STOP DN after 250 ms hopefully Weight !Contacting 
       goto nock1;                                                      //
 nock:                                                                  //
       lcd.setCursor(19,0); lcd.print(x);                               //  update LCd display               
       delay(250);                                                      //  
 nock1:                                                                 //
       BrkKey = kpd.getKey();                                           // 1/4 sec interval BREAK KEY check                                         
    }                                                                   //
//=========================================================================

curious, are you expecting a goto nock;??
Feature1 is set to 0 at start of the function..
if you digitalRead a pin that is grounded, you get LOW or 0..
Would be easier to help if you could produce a complete small example..
Some strategically placed serial prints might help shed some light..
what board you using??

good luck.. ~q

yes-- I want to be able to raise table up to limit supporting weight and if contact switch is = LOW
then feature is installed therefor I set Feature1 = 0 = LOW , then I do not have to ground pin 5 [Featured installed] and should be able to use /if(Feature1 != 0) { goto nock; } ,, but I can not get this to work, but using if(digitalRead(Feature) != 0) { goto nock; } with Feature pin 5 grounded...does work table will stop when weight floats , and table will move for 250ms each time switch is triggered until cmd is complete. [DN=7s WAIT=39s]
Feature1=0; at start of function is for testing. using if(Feature1 != 0) { goto nock; } weight floats, table does not stop untill actuator reaches travel limit. The code I think is as simple as I can get it,,,,I just can not see why it works diferently

no if you set Feature1 to 1 then the != (not equal too) will be true but it is 0 as you set it to 0..

your code simmed..

~q

It shows. If there was a way to mute a user I would be using it.
YES, I found it. Goodbye!