From 75ebfe5579ee2ebb9054fb6e89920fa53aae96f8 Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 14 Feb 2013 03:12:31 +0100 Subject: [PATCH] added libraries and clean up --- source/libraries/INPUT_74HC4051/INPUT_74HC4051.cpp | 11 ++++++++++- source/libraries/INPUT_74HC4051/INPUT_74HC4051.h | 5 ++++- source/libraries/INPUT_MCP23017/INPUT_MCP23017.cpp | 6 ++++-- source/libraries/INPUT_MCP23017/INPUT_MCP23017.h | 6 +++++- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/source/libraries/INPUT_74HC4051/INPUT_74HC4051.cpp b/source/libraries/INPUT_74HC4051/INPUT_74HC4051.cpp index 06aacc2..edb090b 100644 --- a/source/libraries/INPUT_74HC4051/INPUT_74HC4051.cpp +++ b/source/libraries/INPUT_74HC4051/INPUT_74HC4051.cpp @@ -1,13 +1,18 @@ #include "Arduino.h" #include "INPUT_74HC4051.h" +//should be called in setup() void INPUT_74HC4051::begin(uint8_t analog, uint8_t s0, uint8_t s1, uint8_t s2,CallbackFunction cbF) { + + //analog pin which output Z is connected to _analog = analog; + //3 digital pins where S0,S1,S2 are connected to _s0 = s0; _s1 = s1; _s2 = s2; + pinMode(_analog,INPUT); pinMode(_s0,OUTPUT); @@ -16,8 +21,9 @@ void INPUT_74HC4051::begin(uint8_t analog, uint8_t s0, uint8_t s1, uint8_t s2,Ca _callbackFunction = cbF; - //init start values + //initalize start values uint8_t pin,r0,r1,r2; + //run through the 8 I/O pins for (pin=0; pin<8; pin++) { r0 = bitRead(pin,0); r1 = bitRead(pin,1); @@ -30,6 +36,7 @@ void INPUT_74HC4051::begin(uint8_t analog, uint8_t s0, uint8_t s1, uint8_t s2,Ca } } +//should be called in loop(), read values and call callback function on change void INPUT_74HC4051::loop() { uint8_t pin,r0,r1,r2; int value; @@ -40,6 +47,7 @@ void INPUT_74HC4051::loop() { digitalWrite(_s0, r0); digitalWrite(_s1, r1); digitalWrite(_s2, r2); + //not sure if nessesary //delayMicroseconds(10); value = analogRead(_analog); if (_value[pin] < value - INPUT_74HC4051_TOLERANCE || _value[pin] > value + INPUT_74HC4051_TOLERANCE) { @@ -49,6 +57,7 @@ void INPUT_74HC4051::loop() { } } +//maybe useful later int INPUT_74HC4051::getSpecificValue(uint8_t pin) { if (pin >= 8) return -1; diff --git a/source/libraries/INPUT_74HC4051/INPUT_74HC4051.h b/source/libraries/INPUT_74HC4051/INPUT_74HC4051.h index c4523fa..a9f311c 100644 --- a/source/libraries/INPUT_74HC4051/INPUT_74HC4051.h +++ b/source/libraries/INPUT_74HC4051/INPUT_74HC4051.h @@ -1,5 +1,8 @@ /* - INPUT_4051.h - Library for reading inputs from 4051 multiplexer + INPUT_72HC4051.h - 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 + */ #ifndef INPUT_74HC4051_h #define INPUT_74HC4051_h diff --git a/source/libraries/INPUT_MCP23017/INPUT_MCP23017.cpp b/source/libraries/INPUT_MCP23017/INPUT_MCP23017.cpp index 23fc90b..264e6c8 100644 --- a/source/libraries/INPUT_MCP23017/INPUT_MCP23017.cpp +++ b/source/libraries/INPUT_MCP23017/INPUT_MCP23017.cpp @@ -12,7 +12,7 @@ void INPUT_MCP23017::begin(uint8_t addr,CallbackFunction cbF) { _callbackFunction = cbF; - // set defaults! + //set all ports as inputs Wire.beginTransmission(MCP23017_ADDRESS | _addr); Wire.write((byte)MCP23017_IODIRA); Wire.write(0xFF); // all inputs on port A @@ -23,7 +23,7 @@ void INPUT_MCP23017::begin(uint8_t addr,CallbackFunction cbF) { Wire.write(0xFF); // all inputs on port B Wire.endTransmission(); - + //activate pullup resistors Wire.beginTransmission(MCP23017_ADDRESS | _addr); Wire.write(MCP23017_GPPUA); Wire.write(0xFF); // all pullup resistors on port A @@ -34,6 +34,7 @@ void INPUT_MCP23017::begin(uint8_t addr,CallbackFunction cbF) { Wire.write(0xFF); // all pullup resistors on port B Wire.endTransmission(); + //inverse all inputs Wire.beginTransmission(MCP23017_ADDRESS | _addr); Wire.write((byte)MCP23017_IPOLA); Wire.write(0xFF); // inverse all inputs @@ -95,6 +96,7 @@ void INPUT_MCP23017::loop() { } } +//maybe useful later int INPUT_MCP23017::getSpecificValue(uint8_t pin) { if (pin > 16) return LOW; diff --git a/source/libraries/INPUT_MCP23017/INPUT_MCP23017.h b/source/libraries/INPUT_MCP23017/INPUT_MCP23017.h index caf10d8..a45b5e6 100644 --- a/source/libraries/INPUT_MCP23017/INPUT_MCP23017.h +++ b/source/libraries/INPUT_MCP23017/INPUT_MCP23017.h @@ -1,5 +1,9 @@ /* - INPUT_MCP23017.h - Library for reading inputs from MCP23017 port Expander + INPUT_MCP23017.h - Library for reading inputs from MCP23017 port Expander + + library is for specialiced use: all I/O ports are used as digital inputs with internal pullup resistor active, values are stored and a callback function is called, when a value changes + +*/ */ #ifndef INPUT_MCP23017_h #define INPUT_MCP23017_h