Buid a TV Lifter

The sKetch don't react on input and automatically starts with fahreRunter(), butb it has to start doin nothing. What am I wrong?

const int Pin1 = 52;// the number of the LED pin
const int Pin2 = 53;
const int Pin3 = 51;
const int Pin4 = 50;

const int Pin10 = A0;
const int Pin11 = A1;
int buttonStateR = 0;
int buttonStateH = 0;
int zahlR = 0;
int zahlH = 0;
void setup() {
Serial.begin(115200);
// set the digital pin as output:
pinMode(Pin1, OUTPUT);
pinMode(Pin2, OUTPUT);
pinMode(Pin3, OUTPUT);
pinMode(Pin4, OUTPUT);
pinMode(Pin10, INPUT);
pinMode(Pin11, INPUT);
}

void loop() {

buttonStateR = analogRead(Pin10);
buttonStateH = analogRead(Pin11);
if(buttonStateR == LOW and buttonStateH == LOW){
}
if(buttonStateR == LOW){

}else{
zahlR=0;
}

if (buttonStateR == HIGH){
if(zahlR<1){
fahreRunter();
zahlR++;
Serial.println("Runter");
Serial.println(zahl);
}

}else{
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, LOW);
digitalWrite(Pin4, LOW);
}

if(buttonStateH == LOW){

}else{
zahlH=0;
}

if (buttonStateH == HIGH){
if(zahH<1){
fahreHoch();
zahlH++;
Serial.println("Hoch");
Serial.println(zahl);
}

}else{
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, LOW);
digitalWrite(Pin4, LOW);
}

}

void fahreRunter(){

digitalWrite(Pin1, HIGH);
Serial.println("Klappe 1 herunter!");
delay(1200);
digitalWrite(Pin1, LOW);
  delay(2000);
    digitalWrite(Pin2, HIGH);
    Serial.println("Klappe 2 herunter!");
    delay(1700);
    digitalWrite(Pin2, LOW);
      delay(2000);    
        digitalWrite(Pin3, HIGH);
        Serial.println("Klappe 3 herunter!");
        delay(1200);
        digitalWrite(Pin3, LOW);
           delay(2000); 
            digitalWrite(Pin4, HIGH);
            Serial.println("Drehe Fernseher!");
            delay(2500);
            digitalWrite(Pin4, LOW);

}

void fahreHoch(){

digitalWrite(Pin4, HIGH);
Serial.println("Drehe Fernseher!");
delay(2500);
digitalWrite(Pin4, LOW);
digitalWrite(Pin3, HIGH);
Serial.println("Klappe 3 hoch!");
delay(1200);
digitalWrite(Pin3, LOW);
delay(2000);
digitalWrite(Pin2, HIGH);
Serial.println("Klappe 2 hoch!");
delay(1700);
digitalWrite(Pin2, LOW);
delay(2000);
digitalWrite(Pin1, HIGH);
Serial.println("Klappe 1 hoch!");
delay(1200);
digitalWrite(Pin1, LOW);
delay(2000);

}

Need immediate help!

Best regards

I would copy your code to my IDE for examination, but improperly posted code is a royal pain to copy.
Read the forum guidelines to see how to properly post code.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Why analog pins for the buttons? How are the buttons wired? Do you have pulldown or pullup resistors installed?

I use an MEGA 2560. I tried also digital ports the same result!

How are the buttons wired? Do you have pulldown or pullup resistors installed on the button inputs?

I changed recently to Pin10 =48 and Pin11=49 that are digital Ports but no result. No resistors just buttons.

This code does not compile.

What is the purpose of this code?

It looks like NOP, No Operation, a time delay.

An input that is connected to a normally open momentary switch that is open is said to be "floating". A floating pin's state is indeterminate. We use resistors tie to Vcc or ground to give the floating input a defined state. See here.

Here is how to properly wire a momentary switch (pushbutton). The input will read LOW when the switch is closed (pressed) and HIGH when the switch is open (not pressed). Adjust your code accordingly.

Wire the switch as shown below and set the pinMode of the input to INPUT_PULLUP.

To do code below if one is HIGH.

The code You posted does not compile!

It will not direct the execution that way. It does nothing. Check Your use of curly brackets.

Please post code that has been running, is tested. This version of the code has not been passing compilation and has not been executed.

Compiler error report here:

sketch_aug16c:63: error: 'zahl' was not declared in this scope

Serial.println(zahl);

            ^

exit status 1
'zahl' was not declared in this scope

Several similar errors follows.

Please post the code being executed. Not compiling code does not execute.

I changed the configuration. In the idle status it should do nothing. If I press Pin10 and Pin12 it should do void fahreRunter(). If I press Pin11 and Pin13 it should do void fahreHoch(). But it do nothing else than sometimes do fahreRunter() without any input. The buttons are make switch and in the idle status they go with a 10k resistor to ground. Here the sketch again

const int Pin1 = 52;// the number of the LED pin
const int Pin2 = 53;
const int Pin3 = 51;
const int Pin4 = 50;

const int Pin10 = 49;
const int Pin11 = 48;
const int Pin12 = 47;
const int Pin13 = 46;

int buttonStateR = 0;
int buttonStateH = 0;
int buttonStateRR = 0;
int buttonStateHH = 0;

int zahlR = 0;
int zahlH = 0;

void setup() {
Serial.begin(115200);

pinMode(Pin1, OUTPUT);
pinMode(Pin2, OUTPUT);
pinMode(Pin3, OUTPUT);
pinMode(Pin4, OUTPUT);
pinMode(Pin10, INPUT);
pinMode(Pin11, INPUT);
pinMode(Pin12, INPUT);
pinMode(Pin13, INPUT);

}

void loop() {

buttonStateR = digitalRead(Pin10);
buttonStateH = digitalRead(Pin11);
buttonStateRR = digitalRead(Pin12);
buttonStateHH = digitalRead(Pin13);

if(buttonStateR == LOW and buttonStateRR == LOW){

}else{
zahlR=0;
}

if (buttonStateR == HIGH and buttonStateRR == HIGH){
if(zahlR<1){
fahreRunter();
zahlR++;
Serial.println("Runter");
Serial.println(zahlR);
}

}else{
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, LOW);
digitalWrite(Pin4, LOW);
}

if(buttonStateH == LOW and buttonStateHH == LOW){

}else{
zahlH=0;
}

if (buttonStateH == HIGH and buttonStateHH == HIGH){
if(zahlH<1){
fahreHoch();
zahlH++;
Serial.println("Hoch");
Serial.println(zahlH);
}

}else{
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, LOW);
digitalWrite(Pin4, LOW);
}

}

void fahreRunter(){

digitalWrite(Pin1, HIGH);
Serial.println("Klappe 1 herunter!");
delay(1200);
digitalWrite(Pin1, LOW);
  delay(2000);
    digitalWrite(Pin2, HIGH);
    Serial.println("Klappe 2 herunter!");
    delay(1700);
    digitalWrite(Pin2, LOW);
      delay(2000);    
        digitalWrite(Pin3, HIGH);
        Serial.println("Klappe 3 herunter!");
        delay(1200);
        digitalWrite(Pin3, LOW);
           delay(2000); 
            digitalWrite(Pin4, HIGH);
            Serial.println("Drehe Fernseher!");
            delay(2500);
            digitalWrite(Pin4, LOW);

}

void fahreHoch(){

digitalWrite(Pin4, HIGH);
Serial.println("Drehe Fernseher!");
delay(2500);
digitalWrite(Pin4, LOW);
digitalWrite(Pin3, HIGH);
Serial.println("Klappe 3 hoch!");
delay(1200);
digitalWrite(Pin3, LOW);
delay(2000);
digitalWrite(Pin2, HIGH);
Serial.println("Klappe 2 hoch!");
delay(1700);
digitalWrite(Pin2, LOW);
delay(2000);
digitalWrite(Pin1, HIGH);
Serial.println("Klappe 1 hoch!");
delay(1200);
digitalWrite(Pin1, LOW);
delay(2000);

}

Maybe an smart solution.

Best regards

This line of code does nothing:

  if (buttonStateR == LOW and buttonStateH == LOW) {
  }

The right curly bracket ends the if-statement.

Have a look at this reference page: && - Arduino Reference
Please use code tags, the symbol </>, when pasting.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.