Advertisement
ace_ventura

led_button

Aug 31st, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <wiringPi.h>
  3.  
  4. //LED Pin - wiringPi pin 0 is BCM_GPIO 17.
  5.  
  6. #define LED     0   //Configura o pino 0 do wiringPi como LED
  7. #define button  2   //Configura o pino 2 do wiringPi como button
  8.  
  9. int main(void){     //Função que implementa a função de acender o LED com o botão
  10.     wiringPiSetup();
  11.     pinMode(button, INPUT); //Configura button como entrada
  12.     pinMode(LED, OUTPUT);   //Configura LED como saída
  13.     pullUpDnControl(button, PUD_DOWN);  //Define que a porta button vá a 0 quando o botão não estiver pressionado
  14.  
  15.     for(;;){    //Leitura da porta button, que se possui valor alto, joga valor alto na saída LED. Caso contrário, joga valor baixo.
  16.         if(digitalRead(button)){
  17.             digitalWrite(LED, HIGH);
  18.         } else{
  19.             digitalWrite(LED, LOW);
  20.         }
  21.     }
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement