SHARE
TWEET

Led Strip

a guest Sep 26th, 2017 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const int LED = 9;      //Pino da Fita de LED
  2. const int button = 2;   //Pino do Botao
  3. int leitura_anterior = 0;   //Gurda o valor da leitura anterior
  4. int estado = 0;       //Le o valor do botao
  5.  
  6. int fadein(){     //Efeito fade-in
  7.   for (int i = 0;i <= 255; i++){
  8.     analogWrite(LED, i);
  9.     delay(15);
  10.   }
  11. }
  12.  
  13. int fadeout(){      //Efeito fade-out
  14.   for (int i = 255;i >= i; i--){
  15.     analogWrite(LED, i);
  16.     delay(15);
  17.   }
  18. }
  19.  
  20. int button_pressed(){  
  21.  
  22.   int leitura_atual = digitalRead(button);
  23.  
  24.   if(leitura_atual == LOW && leitura_anterior == HIGH){
  25.     estado = 1 -estado;
  26.     delay(50);
  27. }
  28.  
  29. leitura_anterior = leitura_atual;
  30.  
  31.   if(estado == 1){
  32.     analogWrite(LED, fadeout());
  33.     } else {
  34.     analogWrite(LED, fadein());
  35.   }
  36. }
  37.  
  38. void setup() {
  39.   pinMode(LED, OUTPUT);
  40.   pinMode(button, INPUT_PULLUP);
  41. }
  42.  
  43. void loop() {
  44.   button_pressed();
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top