Need the void loop to run just once...

really appreciate your´re trying to help UKHeliBob but i have no idea how global variables works and where to put it:-( like i said i´m a noob. want to help me with this one please

i´m not trying to be rude lloyddean... just posting after the answers... have patience with me...

// global constants exist for all other functions to acces
const int unlock = 2; 
const int innebelysning = 13;
const int lock = 3;
const int varmare = 4;
const int bagage = 5;


// globals variables exist for all other functions to acces

byte serialA;

void setup()
{
    // local variables only exist with in the '{}'
    int count = 0;
}

void loop()
{
    // local variables only exist with in the '{}'
    // this is NOT the same 'count' as specifide in 'setup'
    int count = 0;
}

@jompaohh
The important thing is that you need to know a bit to understand any answer.

but i have no idea how global variables works

That is not very encouraging as it suggests that you do not understand the code you posted one little bit.

All these variables you have declared as global

const int unlock = 2;
const int innebelysning = 13;
const int lock = 3;
const int varmare = 4;
const int bagage = 5;

Because they are declared out side of any function it means that they can be accessed by ALL functions.

You probably need to do a few tutorials to get the hang of things first.

What Part.png

Grumpy_Mike:
All these variables you have declared as global

const int unlock = 2;

const int innebelysning = 13;
const int lock = 3;
const int varmare = 4;
const int bagage = 5;

Actually these are constants and thus not variables ..., just saying.

jompaohh:
really appreciate your´re trying to help UKHeliBob but i have no idea how global variables works and where to put it:-( like i said i´m a noob. want to help me with this one please

When I wrote

Declare them as global variables at the top of the program

it was meant to be a clue

Actually these are constants and thus not variables ..., just saying.

No variable is the name of the thing they are. A constant is a type of variable, it is one that doesn't change its value. It is subject to all the naming restrictions as any variable that changes.

Note that it is not a literal constant which is just a number.
Just saying :wink:

thanx a bunch lloyddean!

have´nt got this all figured out all yet but...

so what exactly should i change in the sketch?

jompaohh:
so what exactly should i change in the sketch?

Declare the new variables at the top of the program before anything else then turn my psuedo-code into real code.

Did you write the code that you posted ? If so, then you will know how to write an if statement to test whether a variable is true or false to determine whether a section of code should be run or not because it has ifs in it already.

One thing to look out for is if case 2 is true before case 1 and the case 2 code runs then it will not run again even after case 1 has been subsequently run when using the logic in my code. After each case has run you will need to make sure that the next case can run by setting its 'flag' variable to false.

Grumpy_Mike:

Actually these are constants and thus not variables ..., just saying.

No variable is the name of the thing they are. A constant is a type of variable, it is one that doesn't change its value. It is subject to all the naming restrictions as any variable that changes.

Note that it is not a literal constant which is just a number.
Just saying :wink:

I know this is rapidly getting way out of scope for the question of the OP, but what a constant is and what a variable is really depends on the compiler. I don't know how this compiler works, but if I were designing one (not that I ever have, but I have coded directly in opcodes...) when translating down to opcodes, a variable could be translated to a memory pointer and a constant could be translated as a literal value. (Using the compiler to put that literal value everywhere the constant name is referenced.) Thus in this case you literally can't change the constant's value during execution without doing dangerous self-modifying code tricks, but the value at the memory location the variable pointer references can change. Two advantages to using constants are: any good compiler will yell at you if you try to change a constant, and usually at the opcode level it takes less clock cycles to act on a literal than a memory pointer because of the extra clock cycles it takes to actually look at some place other than the next location in the program counter.
Just saying :wink:

i´m getting nowhere with this :frowning: i´m stuck.

i know i´m asking alot here but can anyone please correct the sketch and explain please.. coffee´s on me :wink:

Apart from your original code have you got any where you have tried to do what has been suggested ? Even if it does not work post it here and we will help you some more.

I have tried to laborate with the code you gave me and i´m not sure where to put it and gets all these error codes.

Use the juche idea.

jompaohh:
I have tried to laborate with the code you gave me and i´m not sure where to put it and gets all these error codes.

What is your code? What are the error codes?

How to use this forum

Grumpy_Mike:
A constant is a type of variable, it is one that doesn't change its value. It is subject to all the naming restrictions as any variable that changes.

It is subject to naming restrictions, but a variable that is constant is like a moving thing that is fixed.

jompaohh:
for example..
i vant to run pinMode(unlock, OUTPUT);
pinMode(innebelysning, OUTPUT);
only once when i controlling it from the phone but the errors in my code makes it loop until end the northkoreans... hrrmf sorry.. end of time

What errors in your code? If you aren't prepared to read the "sticky" about how to post questions, I'm afraid we can't help you.

I´m sorry for being a bit of an handful but i´m not very good at programing yet and yeah i know this is way over my head but here is the idea

const int unlock = 2;
const int innebelysning = 13;
const int lock = 3;
const int varmare = 4;
const int bagage = 5;

byte serialA;
void setup()
{
// initialize the serial communication:
Serial.begin(9600); //baud rate - make sure it matches that of the module you got:

pinMode(unlock, OUTPUT);
pinMode(innebelysning, OUTPUT);
pinMode(lock, OUTPUT);
pinMode(varmare, OUTPUT);
pinMode(bagage, OUTPUT);

}

void loop() {

if (Serial.available() > 0) {serialA = Serial.read();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);
// want the loop to end here and go back to listening for commands from the phone
break;
case 2:
digitalWrite(lock, HIGH);
delay(1000); // wait for a second
digitalWrite(lock, LOW);
digitalWrite(innebelysning, HIGH);
delay(10000);
digitalWrite(innebelysning, LOW);
break;
// want the loop to end here and go back to listening for commands from the phone
case 4:
digitalWrite(varmare, HIGH);
break;
case 5:
digitalWrite(bagage, LOW);
break;
}

}

Where in the sketch should i place

set case1Run = false
set case2Run = false

and how?