Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * tutorial_botao.ino - Tutorial da utilização da biblioteca
- * Bounce. Controle do brilho de um LED através de dois botões
- *
- * escrito por SamC
- * Versão 1.0.0
- */
- #include <Bounce.h> // biblioteca utilizada
- // definição dos pinos de ligação
- #define LED_PIN 11
- #define AUMENTAR_PIN 8
- #define DIMINUIR_PIN 7
- byte brilho = 0; // valor do brilho do LED entre 0 e 255
- #define DEBOUNCE_TIME 5 // tempo em ms
- Bounce aumentar = Bounce(AUMENTAR_PIN, DEBOUNCE_TIME);
- Bounce diminuir = Bounce(DIMINUIR_PIN, DEBOUNCE_TIME);
- void setup() {
- pinMode(LED_PIN, OUTPUT);
- pinMode(AUMENTAR_PIN, INPUT_PULLUP);
- pinMode(DIMINUIR_PIN, INPUT_PULLUP);
- Serial.begin(9600);
- Serial.println("Tutorial Botao v.1.0.0");
- }
- void loop() {
- analogWrite(LED_PIN, brilho);
- if (aumentar.update() ) {
- if (aumentar.read() == LOW ) {
- aumentar.rebounce(250);
- if (brilho < 255)
- brilho ++;
- Serial.print("Aumentar o brilho do LED: ");
- Serial.println(brilho);
- }
- }
- if (diminuir.update() ) {
- if (diminuir.read()== LOW ) {
- diminuir.rebounce(250);
- if (brilho > 0)
- brilho --;
- Serial.print("Diminuir o brilho do LED: ");
- Serial.println(brilho);
- }
- }
- }
Add Comment
Please, Sign In to add comment