Pages: 1 2 [3]   Go Down
Author Topic: Need the void loop to run just once...  (Read 1896 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Where in the sketch should i place

set case1Run = false
set case2Run = false

and how?
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3638
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
serialA =0;
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3638
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No, above it.
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 108
Posts: 4018
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Or even better above
Code:
if (Serial.available() > 0)
{
  serialA = Serial.read();
  Serial.println(serialA);
}
to make it easier to read
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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);
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: 1 2 [3]   Go Up
Jump to: