Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int LED = 9; //Pino da Fita de LED
- const int button = 2; //Pino do Botao
- int leitura_anterior = 0; //Gurda o valor da leitura anterior
- int estado = 0; //Le o valor do botao
- int fadein(){ //Efeito fade-in
- for (int i = 0;i <= 255; i++){
- analogWrite(LED, i);
- delay(15);
- }
- }
- int fadeout(){ //Efeito fade-out
- for (int i = 255;i >= i; i--){
- analogWrite(LED, i);
- delay(15);
- }
- }
- int button_pressed(){
- int leitura_atual = digitalRead(button);
- if(leitura_atual == LOW && leitura_anterior == HIGH){
- estado = 1 -estado;
- delay(50);
- }
- leitura_anterior = leitura_atual;
- if(estado == 1){
- analogWrite(LED, fadeout());
- } else {
- analogWrite(LED, fadein());
- }
- }
- void setup() {
- pinMode(LED, OUTPUT);
- pinMode(button, INPUT_PULLUP);
- }
- void loop() {
- button_pressed();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement