Advertisement
Guest User

Untitled

a guest
Jun 21st, 2022
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #define Def_tempo 5000 // Define o tempo de espera, após pressionar o botão
  2. #define Def_NumBotao 10 // Define o numero do GPIO, para receber o sinal do botão
  3.  
  4. unsigned long botao_millis; // armazenar o millis() no insante.
  5.  
  6. void setup() { // Função de inicialização
  7. Serial.begin(115200); // Inicializa o monitor serial, a 115200
  8. pinMode(Def_NumBotao, INPUT); // Define "Def_NumBotao" como "entrada" (input)
  9. }
  10.  
  11. void loop() {
  12. if (digitalRead(Def_NumBotao) == HIGH) { // Verifica se o botão ESTÁ pressionado
  13. if (millis() - botao_millis >= Def_tempo) { // Verifica se o valor atual do tempo, menos o tempo salvo, é igual a "def_tempo"
  14. Serial.println("Botão Pressionado por 5 segundos ou mais"); // Em caso positivo, imprime.
  15. }
  16. }
  17. else { // Caso o botão não esteja pressionado...
  18. botao_millis = millis(); // Salva o valor atual do tempo
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement