Hello
i need help whit conditional buttons
[code= "It Is"
Button 1 (UP) Out 1
Button 2 (DOWN) Out 2
Button 3 (RIGTH) Out 3
Button 4 (LEFT) Out 4
Button 5 (ON PWM OFF) Out 5
Button 6 (2 Automatic Movements 12 seg) Out 2 y Out 3
it is my code for the button 6, i need help beacause I need after pressing the
button to activate, can disable the command (cancel) with any of the 6 buttons
Thanks
const int buttonPin = 8; // número del pin para el botón
const int ledPin1= 4; // número del pin del LED
const int ledPin2 = 5; // número del pin del LED
int buttonState = 0; // estado del botón (0 ó LOW es apagado y 1 ó HIGH es encendido)
void setup() {
pinMode(ledPin1, OUTPUT); // Se identifica el pin 4 como salida
pinMode(ledPin2, OUTPUT); // Se identifica el pin 5 como salida
pinMode(buttonPin, INPUT); // Se identifica el pin 8 como entrada
}
void loop(){
buttonState = digitalRead(buttonPin); // Leemos si el botón en pin2 está abierto o cerrado
if (buttonState == HIGH) { // Si está siendo pulsado es HIGH
digitalWrite(ledPin1, HIGH); // Y el LED se enciende
digitalWrite(ledPin2, HIGH); // Y el LED se enciende
delay(12000); //Tiempo de espera 12000 milisegundos
}
else {
digitalWrite(ledPin1, LOW); // Si no es asi, se apaga
digitalWrite(ledPin2, LOW); // Si no es asi, se apaga
}
}
[/code]
[/code]
Please post code in code tags </>.
Did you see the Spanish forum section (Español)?
delay(12000);
The delay() function prevents the Arduino from doing everything. It can't read other buttons or respond in any way until that delay has finished.
boolean delayWithCancel(unsigned long duration) {
unsigned long start = millis();
while(millis()-start < duration) {
if(digitalRead(Button1)==LOW) return true;
if(digitalRead(Button2)==LOW) return true;
if(digitalRead(Button3)==LOW) return true;
if(digitalRead(Button4)==LOW) return true;
}
return false; //action wasn't cancelled
}
void loop() {
if(delayWithCancel(12000)) Serial.println("Cancel button pressed!");
}
DrDiettrich:
Please post code in code tags </>.
Did you see the Spanish forum section (Español)?
Im new ghanés for the help
MorganS:
delay(12000);
The delay() function prevents the Arduino from doing everything. It can't read other buttons or respond in any way until that delay has finished.
boolean delayWithCancel(unsigned long duration) {
unsigned long start = millis();
while(millis()-start < duration) {
if(digitalRead(Button1)==LOW) return true;
if(digitalRead(Button2)==LOW) return true;
if(digitalRead(Button3)==LOW) return true;
if(digitalRead(Button4)==LOW) return true;
}
return false; //action wasn't cancelled
}
void loop() {
if(delayWithCancel(12000)) Serial.println("Cancel button pressed!");
}
Morgan, I am very new to arduino (Programming).
I understand half of what you have explained, thank you.
could you tell me how then modify my code.