If Bedingung wird nicht abgefragt


ich habe folgendes Problem, ich möchte gerne wenn der "Taster 1 HIGH" ist, dass die Bedingung aus dem Programm ausgeführt werden soll. Das gleich soll auch mit Taster 2 passieren. Leider funktioniert das nicht, da die Bedingungen die zu erst steht nicht berücksichtigt wird und immer nur das zweite if abgerufen wird, auch wenn der Taster 1 gedrückt wird. Eigentlich ist es doch so, dass der Loop Stück für Stück abgearbeitet wird?
Danke schonmal im Voraus für euere Hilfe!

#include <SoftwareSerial.h>

int Poti_Zylinder = A0;
int Poti_Stellung = A1;
int Taster_1 = 13;
int Taster_2 = 6;
int Freigabe_Ansteuereung = 3;
int Ansteuerung_Relai = 4;

int R_Poti1 = 0; // Poti am Zylinder
int R_Poti2 = 0; // Sollwert Poti
int T_1 = 0; // Ein Taster 1
int T_2 = 0; // Ein Taster 2
int Sollwert_1 = 0; // Sollwert Position Zylinder

void setup() {
// put your setup code here, to run once:




void loop() {
// put your main code here, to run repeatedly:

Sollwert_1= map(R_Poti2, 0, 1023, 395, 603);

Serial.print(" ");
Serial.print(" ");

Serial.print(" , ");

if(R_Poti1 < Sollwert_1 && T_1 == HIGH){





if(T_2 == HIGH ){




Ich habe folgendes Problem... Ich spreche kein Deutsch.

But I can use google translate.


Okay, I can try to explain it in English.
I have the following problem, I would like if the "button 1 HIGH" is that the condition should be executed from the program. The same should also happen with button 2. Unfortunately, this does not work, because the first conditions are not taken into account and only the second if is called up, even if button 1 is pressed. Isn't it actually the case that the loop is processed bit by bit? Thank you in advance for your help!

I suspect that your first if may be working, and your relays are activated, but if T2 is not pressed, the second if immediately turns them off again.

You may want to combine the two if clauses into one.

Thank you for your comment.
The second if works only, the first is the problem. My idea was, to change between those "programs". Button one is for the first and button two for the second , they have to be separated.

I don't think so, they both do the same thing, you simply have two different conditions that trigger setting the relays. Put some serial prints in the relay code and see where execution goes.

Thank you for answer and lead :slight_smile:

What do you mean bei 'Stück für Stück'? Every statement is executed in the given order and if the end of loop() is reached it starts at the beginning again.
If only your first button is pressed, the relay will be switched on, but because the second is not pressed, it will be switched off immediately by your second if. The 'on' time is so short, your relay will not recognize it.
Do it with only one if statement and try

if( (R_Poti1 < Sollwert_1 && T_1 == HIGH) || T_2 == HIGH ){

P.S. please use code tags ( the </> button ) when posting code. And if you want to discuss in german use the german part of the forum ( you can ask an admin to move your topic there ).

Sorry, am new here :sweat_smile:.
"Stück für stück" mean step by step. Thank you for helping and solve my coding problems, it finally works! One question, normally it is possible to have more different if condition at one loop?

Yes of course. It's just that in your case, the two ifs were fighting with each other.

Ist das nicht falsch rum?
Also, nicht besser, erst lesen, dann berechnen?

Die beiden sind flüssiger als Wasser.

Wo sind die Pullup/Pulldown?

Und wo wird entprellt?

Und sowieso:
Was soll das Programm überhaupt tun?
Sinn, Zweck, gewünschter Ablauf?