Use of '//' to disable via Pins and not IDE

With this kind of a very general program below

if (digitalRead(22) == LOW)

	{
	  digitalWrite(LedPin01,HIGH);
	  delay(100);
	  while(digitalRead(22) == LOW);
	}

If I want to disable the part

while(digitalRead(22) == LOW);

I ll simply place a // before it to make this like

//while(digitalRead(22) == LOW);

To do this process I need to open IDE and need to open the program and need to make changes and then need to upload

Suppose I want to do it with any other GPIO Pin like PIn 48 or Pin 49 or any with a one press on Push button

Is this kind of rare stuff possible ???

Of course. Once you learn how to program stuff like that is simple.

  bool someVariable = false;
.
.
.
  if (someVariable == true) {
       doWhatever();
  }

Then collect the pushbutton event to set someVariabke true or false.

HTH

a7

Ya Sir Learning is IMP to really program those stuff and I am on basics

OK I ll try with this

Any Reference page to Learn this ??

I am sure you have some learning style, and that there must be teachers on the internet who will speak to that.

A good way to improve is to read these fora, especially read the code carefully to see how it does whatever it is doing. Or why it does not.Does not compile, or perhaps does not yet function correctly.

There are many simple examples available in the IDE. Start wherever you feel uncomfortable, get out examples and read them, run them and ask questions here or google for things you don't understand yet.

Surely you know what you need to about if statements…

a7

On this basis I prepared this

const int IN2 = 2;
const int IN3 = 3;
boolean readValue2 ;
boolean readValue3 ;
const byte LedPin12 = 12;
bool pause = false;
void setup() {
  // put your setup code here, to run once:
pinMode (IN2, INPUT_PULLUP);
pinMode (IN3, INPUT_PULLUP);
pinMode (LedPin12, OUTPUT);
      digitalWrite(LedPin12, LOW);
}

void loop()

{
  if (digitalRead(IN2)==0)
  {
    digitalWrite(LedPin12,1);
    delay(400);
    digitalWrite(LedPin12,0);
    delay(400);
    if (digitalRead(IN3)==0)
    {
      while(digitalRead(IN2)==0);
      delay(100);
    }
    else
    {
      //while(digitalRead(IN2)==0);
      //delay(100);
    }
  }
}

But here PIN 3 just cancels the while part permanently even after releasing the button

What would be the inverse of while part !!

can you explain the application for this

along these lines, but needing changes for this application, consider
i usually have a function like this in any code i write to help debug/test

// pcRead - debugging using serial monitor

const char version [] = "PcRead 201114a";

int debug = 0;

// ---------------------------------------------------------
// toggle output bit
int
readString (
    char *s,
    int   maxChar )
{
    int  n = 0;

    Serial.print ("> ");
    do {
        if (Serial.available()) {
            int c    = Serial.read ();

            if ('\n' == c)
                break;

            s [n++] = c;
            if (maxChar == n)
                break;
        }
    } while (true);

    return n;
}

// -----------------------------------------------------------------------------
// process single character commands from the PC
#define MAX_CHAR  10
char s [MAX_CHAR] = {};

int  analogPin = 0;

void
pcRead (void)
{

    static int  val = 0;

    if (Serial.available()) {
        int c = Serial.read ();

        switch (c)  {
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
            val = c - '0' + (10 * val);
            break;

        case 'A':
            analogPin = val;
            Serial.print   ("analogPin = ");
            Serial.println (val);
            val = 0;
            break;

        case 'D':
            debug ^= 1;
            break;

        case 'I':
            pinMode (val, INPUT);
            Serial.print   ("pinMode ");
            Serial.print   (val);
            Serial.println (" INPUT");
            val = 0;
            break;

        case 'O':
            pinMode (val, OUTPUT);
            Serial.print   ("pinMode ");
            Serial.print   (val);
            Serial.println (" OUTPUT");
            val = 0;
            break;

        case 'P':
            pinMode (val, INPUT_PULLUP);
            Serial.print   ("pinMode ");
            Serial.print   (val);
            Serial.println (" INPUT_PULLUP");
            val = 0;
            break;


        case 'a':
            Serial.print   ("analogRead: ");
            Serial.println (analogRead (val));
            val = 0;
            break;

        case 'c':
            digitalWrite (val, LOW);
            Serial.print   ("digitalWrite: LOW  ");
            Serial.println (val);
            val = 0;
            break;

        case 'p':
#if !defined(ARDUINO_ARCH_ESP32)
            analogWrite (analogPin, val);
            Serial.print   ("analogWrite: pin ");
            Serial.print   (analogPin);
            Serial.print   (", ");
            Serial.println (val);
            val = 0;
#endif
            break;

        case 'r':
            Serial.print   ("digitalRead: pin ");
            Serial.print   (val);
            Serial.print   (", ");
            Serial.println (digitalRead (val));
            val = 0;
            break;

        case 's':
            digitalWrite (val, HIGH);
            Serial.print   ("digitalWrite: HIGH ");
            Serial.println (val);
            val = 0;
            break;

        case 't':
            Serial.print   ("pinToggle ");
            Serial.println (val);
            digitalWrite (val, ! digitalRead (val));
            val = 0;
            break;

        case 'v':
            Serial.print ("\nversion: ");
            Serial.println (version);
            break;

        case '\n':          // ignore
            break;

        case '"':
            while ('\n' != Serial.read ())     // discard linefeed
                ;

            readString (s, MAX_CHAR-1);
            Serial.println (s);
            break;

        case '?':
            Serial.println ("\npcRead:\n");
            Serial.println ("    [0-9] append to #");
            Serial.println ("    A # - set analog pin #");
            Serial.println ("    D # - set debug to #");
            Serial.println ("    I # - set pin # to INPUT");
            Serial.println ("    O # - set pin # to OUTPUT");
            Serial.println ("    P # - set pin # to INPUT_PULLUP");
            Serial.println ("    a # - analogRead (pin #)");
            Serial.println ("    c # - digitalWrite (pin #, LOW)");
            Serial.println ("    p # -- analogWrite (analogPin, #)");
            Serial.println ("    r # - digitalRead (pin #)");
            Serial.println ("    s   - digitalWrite (pin #, HIGH)");
            Serial.println ("    t   -- toggle pin # output");
            Serial.println ("    v   - print version");
            Serial.println ("    \"   - read string");
            Serial.println ("    ?   - list of commands");
            break;

        default:
            Serial.print ("unknown char ");
            Serial.println (c,HEX);
            break;
        }
    }
}

// -----------------------------------------------------------------------------
void
loop (void)
{
    pcRead ();
}

// -----------------------------------------------------------------------------
void
setup (void)
{
    Serial.begin(115200);

    Serial.println (version);
#if defined(ARDUINO_ARCH_ESP32)
    Serial.println ("esp32");
#endif
}

@Raj_enters_learning_programming,

I looked up your statistics
112 days visited
45 topics created
472 posts created

You are asking pretty basic questions. I assume you jumped from project to project always just learning enough to make it work somehow. Without really understanding.

You have done this now for 45 topics.
I want to suggest a more efficient way of learning.
Take a look into this tutorial:

Arduino Programming Course

It is easy to understand and has a good mixture between explaining important concepts and example-codes to get you going. So give it a try and report your opinion about this tutorial.

Learning with such a tutorial is like building a racecar from a Kit.
Imagine a race between a jogger and you over 500 miles
Day one jogger starts running you start studying the building-plans for the racecar
Day 2,3,4,5,6,7,8,9,10,11,12,13,14, jogger is at 420 miles
day 15 8 am you finish building the race-car start the motor and wroom
day 15 1 pm you pass the jogger and win the race

That is the difference between stumpbling along the path with a lot of programming hints from the forum (the jogger) compared to learning to programm - which of course takes time and then progressing very fast.

About your question I haven't understood what you want to do with this code.
Youhave to use more and more detailed words to epxlain.
and use plain simple normal words. It will be easier to understand

best regards Stefan

2 Likes

But did you mean this

which I point out is a complete while statement that does... absolutely nothing. Probably guessing that's not what you intended.

What would be the inverse of while part !!

What are you trying to do? How can you tell if it is doing what you want or not?

Create a simpler example. It's just an if statement letting or not letting a while loop run. Reread the responses above.

    if (digitalRead(controlPin) == LOW) 
        while ( <whatver> ) {
                // code in here will execute only if the *controlPin* is reading LOW.
        }

HTH

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.