4017 Decade Counter

Counter_4017.h

/* Project: 4017 Decade Counter Interfacing.
 * File: Counter_4017.h
 * Description: Interface with a 4017 decade counter.
 *     Uses the DirectIO library.
 *
 * Copyright (C) 2014 Marc Symonds
 * All rights reserved.
 *
 * This software may be used and redistributed, with or without
 * modification, as long as it is understood that this software
 * is provided as-is without any explicit or implied warranties
 * of merchantablity or fitness of purpose.
 */

#ifndef Counter_4017_h
#define Counter_4017_h

#include "Arduino.h"
#include "DirectIO.h"

class Counter_4017
{
  public:
    Counter_4017(byte clockPin, byte lastElementDetectPin);

    void clock();
    void clockPrime();
    void clockTrigger();
    void clear();
    boolean onLastElement();

  private:
    DIO_SetPinFPtr _clockPin;
    byte _lastElementDetectPin;
};

#endif

Counter_4017.cpp

/* Project: 4017 Decade Counter Interfacing.
 * File: Counter_4017.cpp
 * Description: Interface with a 4017 decade counter.
 *     Uses the DirectIO library.
 *
 * Copyright (C) 2014 Marc Symonds
 * All rights reserved.
 *
 * This software may be used and redistributed, with or without
 * modification, as long as it is understood that this software
 * is provided as-is without any explicit or implied warranties
 * of merchantability or fitness of purpose.
 */

#include "Arduino.h"
#include "Counter_4017.h"

Counter_4017::Counter_4017(byte clockPin, byte lastElementDetectPin)
{
  pinMode(clockPin, OUTPUT);
  pinMode(lastElementDetectPin, INPUT);

  _clockPin = DIO_GetSetPinFunction(clockPin);
  _lastElementDetectPin = lastElementDetectPin;

  clear();
}

void Counter_4017::clock()
{
  _clockPin(false);
  _clockPin(true);
}

void Counter_4017::clockTrigger()
{
  _clockPin(true);
}

void Counter_4017::clockPrime()
{
  _clockPin(false);
}

void Counter_4017::clear()
{
  while (!onLastElement())
    clock();

  while (onLastElement())
    clock();
}

boolean Counter_4017::onLastElement()
{
  return (digitalRead(_lastElementDetectPin) == HIGH ? true : false);
}

keywords.txt

Counter_4017	KEYWORD1

clock	KEYWORD2
clear	KEYWORD2
onLastElement	KEYWORD2

1 Comment

  1. ramasubramanian says:

    int pin = 13;
    volatile int state = LOW;

    void setup()
    {
    pinMode(pin, OUTPUT);
    attachInterrupt(0, blink, CHANGE);
    }

    void loop()
    {
    digitalWrite(pin, state);
    }

    void blink()
    {
    state = !state;
    }

    /* G.RAMASUBRAMANIAN PH:9042816495 */

Leave a Reply

Your email address will not be published. Required fields are marked *

Comments Protected by WP-SpamShield Spam Blocker