Logikproblem

Originalsketch mit dem Fehler...damit der Thread vollständig ist :slight_smile:

int Pulse=1100; //minimum pulse for arming ESC
int wait=0; // delay time to wait human to acknowledge the press

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

pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(6, OUTPUT);


} // end of setup

void loop ()
{
//The function that control the speed of the motor
Speedy();

//This is the sketch that generate PWM
digitalWrite(6, HIGH);
delayMicroseconds(Pulse);
digitalWrite(6, LOW);
delayMicroseconds(10000-Pulse);
delayMicroseconds(10000);

Serial.println(Pulse); //So you can view Pulse on serial window
} // end of loop


void Speedy()
{digitalWrite(6, LOW);

//Scan for button switch starts here:
if (digitalRead(2&&3)==HIGH) //emergency cut-off if both switches pulled
{Pulse=1100;digitalWrite(6,HIGH);}

else if(digitalRead(2)==HIGH)//Start Speedup button at Pin 2
{wait=wait+1;
if (wait>10) {Pulse=Pulse+50; wait=0;digitalWrite(6, HIGH);}
if (Pulse>2000) {Pulse=2000;}
}//End speedup button at Pin 2

else if (digitalRead(3)==HIGH)//Start slow down button at Pin 3
{wait=wait+1;
if (wait>10) {Pulse=Pulse-50; wait=0; digitalWrite(6, HIGH);}
if (Pulse<1100) {Pulse=1100;}//In any case the ESC will remain Arm
}//End slow down button at Pin 3

else if (digitalRead(4)==HIGH) //Cut-off button at Pin 4
{Pulse=1100; digitalWrite(6, HIGH);}

else {Pulse=Pulse;digitalWrite(6, LOW);}//If no button press, pulse remains as last pulse
}