Please help why my subroutin program is doesnt work

anyone know why this logic does not work or is there another logic for substitute this logic?

pleasee help,…

int PIN_13 = 13;
int PIN_12 = 12;
int PIN_8 = 8;
int PIN_7 = 7;
int PIN_2= 2;
int PIN_4= 4;
void setup() {
Serial.begin(9600);
pinMode(PIN_12, INPUT);
pinMode(PIN_13, INPUT);
pinMode(PIN_7, INPUT);
pinMode(PIN_8, INPUT);
pinMode(PIN_2, OUTPUT);
pinMode(PIN_4, OUTPUT);
}
void loop () {
digitalWrite (PIN_4, LOW );
int keadaantegangan1 = digitalRead (PIN_13);
int keadaantegangan = digitalRead (PIN_12);
if ( keadaantegangan == HIGH || keadaantegangan1 == HIGH ) {
digitalWrite ( PIN_2, HIGH ) ;
delay (1000);
awal (PIN_8,PIN_7) ; }
}
void awal ( int PIN_8 , int PIN_7) {
int keadaantegangan2 = digitalRead (PIN_8);
int keadaantegangan3 = digitalRead (PIN_7);
if ( keadaantegangan2 == HIGH ||keadaantegangan3 == HIGH )
digitalWrite (PIN_4, HIGH );
delay (1000); }

  1. you never turn your leds off, but since I don't know if they should maybe it's not a problem.
  2. when you define awal() you use parameters with names you already defined as globals.

Really, "does not work" does not begin describe enough. On this forum it's like saying "I am clueless".

What are you trying to do?
How are your inputs wired to the controller?

int PIN_13 = 13;

Why not give these better names
example:
const int startPin =13;

arulhakuto:
anyone know why this logic does not work or is there another logic for substitute this logic?

Why is the Title for this question “Subroutine” ?
If you use a title that describes your problem you may catch the interest of people with useful advice.
If you modify your original post you can edit the title.

…R

anyone know why this logic does not work or is there another logic for substitute this logic?

pleasee help,…

int PIN_13 = 13;
int PIN_12 = 12;
int PIN_8 = 8;
int PIN_7 = 7;
int PIN_2= 2;
int PIN_4= 4;
void setup() {
Serial.begin(9600);
pinMode(PIN_12, INPUT);
pinMode(PIN_13, INPUT);
pinMode(PIN_7, INPUT);
pinMode(PIN_8, INPUT);
pinMode(PIN_2, OUTPUT);
pinMode(PIN_4, OUTPUT);
}
void loop () {
digitalWrite (PIN_4, LOW );
int keadaantegangan1 = digitalRead (PIN_13);
int keadaantegangan = digitalRead (PIN_12);
if ( keadaantegangan == HIGH || keadaantegangan1 == HIGH ) {
digitalWrite ( PIN_2, HIGH ) ;
delay (1000);
awal (PIN_8,PIN_7) ; }
}
void awal ( int PIN_8 , int PIN_7) {
int keadaantegangan2 = digitalRead (PIN_8);
int keadaantegangan3 = digitalRead (PIN_7);
if ( keadaantegangan2 == HIGH ||keadaantegangan3 == HIGH )
digitalWrite (PIN_4, HIGH );
delay (1000); }

moderator: merged crossposting question into single thread

PIN_2 is NEVER sent LOW. So once it gets sent high, it stays that way for ever. Is that what you wanted?

void awal ( int PIN_8 , int PIN_7) {

This is not a very sensible way to name your variables.

You already have global variables called PIN_8 and PIN_7 but the compiler will use this code to create local variables of the same name within your function. It will work fine - the compiler won't care. But it will be confusing for you.

To add to the confusion you refer to the global variable PIN_4 in the same function.

...R

In void awal " if ( keadaantegangan2 == HIGH ||keadaantegangan3 == HIGH )
digitalWrite (PIN_4, HIGH );
delay (1000); } " this comand is not executed in my arduino…
i dont know why ?

i dont know why ?

Is that a question or a statement?

Aside from the issues with useless names for variables, passing global values to functions, etc. that have been pointed out, but not addressed, there is a serious lack of debug code. What is being read from the pins? How are the switches actually wired?

Debug-by-guess takes FAR long then debug-with-facts. Get some facts!

Perhaps your PIN_8 and PIN_7 are not high when you read them.

You realise you’ve got a delay of 1 second towards the end of your loop function. (yes the delay executes EVERY time, even though you’ve indented it). Also you’ve got another delay of 1 second at the end of your awal function.

So you’re only making your test of PIN_8 and PIN_7 for a fleeting moment, once every two seconds.

Hi,

Can you please post a copy of your sketch, using code tags?
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png or pdf?

Before you repost your sketch in code tags, in the IDE select TOOLS then AUTO FORMAT to make your sketch easier to read.

At this point please oblige us with the above request.

Tom........ :slight_smile:

arulhakuto:
In

void awal " if ( keadaantegangan2 == HIGH ||keadaantegangan3 == HIGH ) { // <===== You forgot the brace

digitalWrite (PIN_4, HIGH );
 delay (1000); } " this comand is not executed in my arduino…



i dont know why ?

You forgot the brace… SEE IN CODE.

ALSO, please use

[ code ]this is code[ /code ] //<<=====without spaces
[code] //<<===== like this

[/code]

arulhakuto:
In void awal " if ( keadaantegangan2 == HIGH ||keadaantegangan3 == HIGH )
digitalWrite (PIN_4, HIGH );
delay (1000); } " this comand is not executed in my arduino..
i dont know why ?

As a tail part of previous code (SEE FULL CODE ) this is syntactically correct.
However, the logic may be not what you want.
The digitalWrite (PIN_4, HIGH ); will not execute if the If() evaluates to false.
One way to check WHERE your code goes astray would be to temporary add serial

.... previous code
if ( keadaantegangan2 == HIGH ||keadaantegangan3 == HIGH )
Serial.print("HERE if true");
digitalWrite (PIN_4, HIGH ); // here if false
delay (1000);

Serial.print("After delay");
}

.
i dont know why ?

arulhakuto:
In void awal " if ( keadaantegangan2 == HIGH ||keadaantegangan3 == HIGH )
digitalWrite (PIN_4, HIGH );
delay (1000); } " this comand is not executed in my arduino..
i dont know why ?

Both pins never became high?

Interestingly, I tried a google translate for keada antega ngan and it comes back as malay for "close butter only" I don't know if this helps.

int PIN_13  = 13;
int PIN_12  = 12;
int PIN_8  = 8;
int PIN_7  = 7;
int PIN_2= 2;
int PIN_4= 4;

In what way do these variable names help to understand the code?