button procedure library

Dependents:   MIDI_CW Gemphet8

button.h

Committer:
ChuckTimber
Date:
2014-08-07
Revision:
3:1c47d318e457
Parent:
2:df827b705b98
Child:
6:b6a97933b3d5

File content as of revision 3:1c47d318e457:

#ifndef MBED_BUTTON_H
#define MBED_BUTTON_H

#include "mbed.h"

/**
 *  @file       button.h
 *  Project     button handling Library
 *  @brief      button handling library for mbed
 *  @version    1.0
 *  @author     Chuck Timber
 *  @date       07/08/2014
 */

/** class to handle button input 
 *   The class use DigitalIn and Ticker
 *
 * Refered to: http://elm-chan.org/docs/tec/te03.html
 *
 * Example:
 * @code
 * // Button sample
 * #include "mbed.h"
 * #include "button.h"
 * 
 * BTN btn(dp13);
 * 
 * int main()
 * {
 *     int mode = 0;
 *     int value;
 * 
 *     btn.CMD = 0;
 *     while(1) {
 *         if(btn.CMD) {
 *             mode++;
 *             btn.CMD = 0;
 *             srand( time(NULL) );
 *         }
 *         if (mode % 2) value = rand();
 *     }
 * }
 * @endcode
 */

#define BTN_SAMPLING_PERIOD 0.01

namespace mbed {

/** Class: BTN
 *  A class handles button input procedure, which uses DigitalIn and Ticker
 */
class BTN {

public:
    BTN(PinName pin);
    unsigned char CMD;
    unsigned char STAT;

private:
    /** sample_btn input and process */
    void sample_btn(void);
    unsigned char FIL;
    DigitalIn _Pin;
    Ticker _Tick;

};

}
#endif