void loop () decleration problem

Hi guys,

  1. if I define digitalWrite(IN1,HIGH) and want to make it low in the loop. Is this possible?

  2. if possible whenever void loop() function executes once lets say I have set digitalWrite(IN1,LOW), what will happen if the loop starts again will it set the IN1 HIGH as defined in the setup or writes LOW because it is declared LOW in first execution?

  3. or simply does the program only executes void setup() function once while loop is executed continiosly? It may also be impossible to set a pin a different state if it is declared in the setup function :~

1: Yes
2: It will remain low
3: Yes.

Take a look at "main.cpp" in the Arduino's IDE files - you'll soon see how it all works:

    setup();

    for (;;) {
        loop();
        if (serialEventRun) serialEventRun();
    }

majenko:
1: Yes
2: It will remain low
3: Yes.

Take a look at "main.cpp" in the Arduino's IDE files - you'll soon see how it all works:

    setup();

for (;:wink: {
        loop();
        if (serialEventRun) serialEventRun();
    }

Thank you very much

@hydrv, the greatest feature of the Arduino system is that it would take only a few minutes to write a sketch to learn what you wanted to know.

This is not meant as a criticism, but rather as advice to use this technique to study things you don't know or new stuff that you want to try with the Arduino.

char testChar = 'S';

void setup() {
  Serial.begin(9600);
  Serial.print("This is in setup() ");
  Serial.println(testChar);
  delay(1000);
}

void loop() {
  testChar = 'L';
  Serial.print("This is in loop() ");
  Serial.println(testChar);
  delay(1000);
}

(I have not tested this).

...R