# Tecla Liga/Desliga

Nesse exemplo vamos fazer uma tecla liga/desliga, que pode ser usada para acionamentos diversos.

## Materiais

Placa Franzininho; Protoboard; LED 3mm; 1 Resistor 220; 1 Resistor de 1K; 1 Botão; Jumpers;

## Circuito

No protoboard você deve inserir o LED, resistores e o botão, conforme a imagem abaixo:

![](/files/-ML4x813bBWHvOOPQDYJ)

Sketch

```cpp
/*
  Franzininho
  Exemplo: Tecla liga/desliga

  Esse exemplo exibe como fazer ligar e desligar uma saída através de uma tecla

*/


const int LED = 1; //pino para o LED
const int BOTAO = 2; //pino para o botão

int estadoAnteriorBotao = 0;   // armazena o estado anterior do botão

void setup(){
  pinMode(LED,OUTPUT); //o LED é uma saída
  pinMode(BOTAO,INPUT); //o BOTAO é uma entrada
}

void loop (){
 int estadoAtualBT= digitalRead(BOTAO);      // Lê estado do botão
 delay(10);

  if ((estadoAtualBT != estadoAnteriorBotao)&& (estadoAtualBT == LOW)){       //Se o botão foi pressionado e o seu estado mudou
  digitalWrite(LED,!digitalRead(LED)); //inverte estado do LED
  }

  estadoAnteriorBotao = estadoAtualBT;  //salva o estado do botão para comparar na próxima leitura
}
```

## Video

{% embed url="<https://www.youtube.com/watch?v=Aht0fUuGIjQ>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://franzininho.gitbook.io/franzininho-docs/exemplos/tecla-liga-desliga.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
