2013-02-14 12:23:57 +01:00
|
|
|
/**
|
2013-03-12 14:53:27 +01:00
|
|
|
* @file bombatuino_INPUT_74HC4051.h
|
2013-02-14 12:23:57 +01:00
|
|
|
*
|
|
|
|
* @author Lukas Haubaum (lukas@haubaum.de)
|
|
|
|
*
|
|
|
|
* @date February, 2013
|
|
|
|
*
|
|
|
|
* @brief arduino library for reading inputs from 74HC4051 multiplexer
|
|
|
|
*
|
|
|
|
* library is for specialiced use: all I/O ports are used as analog inputs, values are stored and a callback function is called, when a value changes
|
|
|
|
*
|
|
|
|
* */
|
2013-03-12 14:53:27 +01:00
|
|
|
#ifndef bombatuino_INPUT_74HC4051_h
|
|
|
|
#define bombatuino_INPUT_74HC4051_h
|
2013-02-14 12:23:57 +01:00
|
|
|
|
2013-05-14 08:28:05 +02:00
|
|
|
#define INPUT_74HC4051_TOLERANCE 0 /**< I/O DIRECTION REGISTER PORT A - Controls the direction of the data I/O. */
|
2013-02-14 02:59:15 +01:00
|
|
|
|
|
|
|
#if !defined(CallbackFunction)
|
2013-02-14 12:23:57 +01:00
|
|
|
/**
|
|
|
|
* callback function
|
|
|
|
*
|
|
|
|
* @param address
|
|
|
|
* @param pin
|
|
|
|
* @param value
|
|
|
|
*/
|
2013-02-14 02:59:15 +01:00
|
|
|
typedef void (*CallbackFunction)(int,int,int);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class INPUT_74HC4051
|
|
|
|
{
|
2013-02-14 12:23:57 +01:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* initalize the class, should be called in setup() function
|
|
|
|
*
|
|
|
|
* @param analog input pin on arduino, connected Z pin here
|
|
|
|
* @param digital output pin for S0
|
|
|
|
* @param digital output pin for S0
|
|
|
|
* @param digital output pin for S0
|
|
|
|
* @param callback function
|
|
|
|
*/
|
|
|
|
void begin(uint8_t analog, uint8_t s0, uint8_t s1, uint8_t s2,CallbackFunction cbF);
|
|
|
|
/**
|
|
|
|
* read values and call callback function on change, should be called in loop()
|
|
|
|
*/
|
|
|
|
void loop(void);
|
|
|
|
/**
|
|
|
|
* get value of specific pin (0-7)
|
|
|
|
*
|
|
|
|
* @param pin
|
|
|
|
* @return value of pin
|
|
|
|
*/
|
2013-02-14 02:59:15 +01:00
|
|
|
int getSpecificValue(uint8_t pin);
|
|
|
|
private:
|
2013-02-14 12:23:57 +01:00
|
|
|
uint8_t _analog; /**< analog input pin on arduino, connected Z pin here */
|
|
|
|
uint8_t _s0; /**< digital output pin for S0 */
|
|
|
|
uint8_t _s1; /**< digital output pin for S0 */
|
|
|
|
uint8_t _s2; /**< digital output pin for S0 */
|
|
|
|
int _value[8]; /**< read values */
|
|
|
|
CallbackFunction _callbackFunction; /**< callback function */
|
2013-02-14 02:59:15 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|