push button + serial = LED

My arduino is a hobby. and I have a doubt: I need to control an LED by serial sending "A" lights up LED and sending "a" turns off LED, but also need to control by a push button with retention push once turns on the LED press again turns off the LED. but I can't make the LED work both ways at once.

Code? Hardware connections?
Please read the "How to use this forum" post at the top.

If you have written some code trying to do that then post it here and we can help with it. No code, nothing to help with.

Steve

If you are able to get both methods working separately, it should be almost as simple as “if method1 on OR method2 on” then turn it on. But hard to say for certain without you posting code and giving more info on your setup.

#define pinBotao1 30
#define pinLED1 24

bool pinBotao1Retencao();
int PortaSerial;

void setup() {

Serial.begin(9600);
pinMode(pinBotao1, INPUT_PULLUP);
pinMode(pinLED1, OUTPUT);

}

void loop() {
//-------------------controlar via retenção-----------------

if (pinBotao1Retencao() == HIGH) {
digitalWrite(pinLED1, HIGH);
}
if (pinBotao1Retencao() == LOW) {
digitalWrite(pinLED1, LOW);
}
//--------------------controlar via serial------------------

if (Serial.available()) {
PortaSerial = Serial.read();

if(PortaSerial == 'A'){ //Letra "A" liga
digitalWrite(pinLED1, HIGH);

}
if(PortaSerial == 'a'){ //Letra "a" desliga
digitalWrite(pinLED1, LOW);

}

}
}

bool pinBotao1Retencao() {
#define tempoDebounce 900 //(tempo para eliminar o efeito Bounce EM MILISEGUNDOS)

bool estadoBotao;
static bool estadoBotaoAnt;
static bool estadoRet = true;
static unsigned long delayBotao = 0;

if ( (millis() - delayBotao) > tempoDebounce ) {
estadoBotao = digitalRead(pinBotao1);
if ( estadoBotao && (estadoBotao != estadoBotaoAnt) ) {
estadoRet = !estadoRet;
delayBotao = millis();
}
estadoBotaoAnt = estadoBotao;
}

return estadoRet;
}

SteveMann:
Please read the "How to use this forum" post at the top.

How is the button wired? It looks odd that you're using INPUT_PULLUP and then checking for HIGH to switch the LED on.

So tell us what that code does and why it isn't what you wanted it to do.

Steve

the button is on GND and pin30

Please read the forum rules as requested already by two other members, and add code tags to your previous reply. While you're at it, please also fix the formatting and indentation of your sketch by using CTRL+T in the Arduino IDE.

Pieter