blinker.cpp 819 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
/*-----------------------------------------------------------------------------
 *  Author: Nelso G. Jost (nelsojost@gmail.com)
 *  License: GPLv2
 *  Purpose: Provide the Blinker class for scheduling a blink process.
 *---------------------------------------------------------------------------*/
#include <Arduino.h>
#include "blinker.h"

Blinker::Blinker(int pin)
{
    this->_pin = pin;
    pinMode(pin, OUTPUT);
    digitalWrite(pin, HIGH);
}

void Blinker::_update(Blinker *b)
{
    b->_state = !b->_state;
    digitalWrite(b->_pin, b->_state);
}

void Blinker::activate(float interval)
{
    this->_interval = interval;
    digitalWrite(this->_pin, LOW);
    this->ticker.attach(interval, this->_update, this);
}

void Blinker::deactivate(void)
{
    this->ticker.detach();
    digitalWrite(this->_pin, HIGH);
}