Go Down

Topic: Need the void loop to run just once... (Read 2816 times) previous topic - next topic

jompaohh

Where in the sketch should i place

set case1Run = false
set case2Run = false

and how?

wildbill

Quote
// want the loop to end here and go back to listening for commands from the phone


It does.

Humour me and put this in as the first line in loop:
Code: [Select]
serialA =0;

jompaohh

in this? if (Serial.available() > 0) {serialA = Serial.read();Serial.println(serialA);}


UKHeliBob

Or even better above
Code: [Select]
if (Serial.available() > 0)
{
  serialA = Serial.read();
  Serial.println(serialA);
}
to make it easier to read
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

jompaohh

like this?

void loop() {
if (Serial.available() > 0)
{
  serialA = 0();
  Serial.println(serialA);
}
  switch (serialA) {
    case 1:
      digitalWrite(unlock, HIGH);
      delay(1000);               // wait for a second
      digitalWrite(unlock, LOW);
      digitalWrite(innebelysning, HIGH);
      delay(10000);               
      digitalWrite(innebelysning, LOW);

PaulS

Look at the code you had, and the code in UKHeliBob's last reply. Then get a clue-by-four and give yourself a good whack. As a newbie, you should get into the habit of putting each { on a line BY ITSELF and of putting each } on a line BY ITSELF.

You should also get into the habit of using Tools + Auto Format to fix your indenting.

Finally, while you have the clue-by-four handy. go read the sticky (again, if needed) at the top of the forum, and learn to post your code properly.

Go Up