Browse Source

add LED_PortOpenDrain

tags/v0.6.4
wolfv6 7 years ago
parent
commit
6a787b4155

+ 2
- 2
examples/keybrd_MCP23018/keybrd_MCP23018.ino View File

//right matrix //right matrix
#include <Port_MCP23018.h> #include <Port_MCP23018.h>
#include <Scanner_IOE.h> #include <Scanner_IOE.h>
#include <LED_Port.h>
#include <LED_PortOpenDrain.h>


// ============ SPEED CONFIGURATION ============ // ============ SPEED CONFIGURATION ============
ScanDelay scanDelay(9000); ScanDelay scanDelay(9000);
Scanner_IOE scanner_R(LOW, portB, portA); Scanner_IOE scanner_R(LOW, portB, portA);


// ================= RIGHT LED ================= // ================= RIGHT LED =================
LED_Port LED_capsLck(portA, 1<<7);
LED_PortOpenDrain LED_capsLck(portA, 1<<7);


// =================== CODES =================== // =================== CODES ===================
Code_Sc s_a(KEY_A); Code_Sc s_a(KEY_A);

+ 4
- 1
src/LED_Port.h View File

#include <LEDInterface.h> #include <LEDInterface.h>
#include <PortWriteInterface.h> #include <PortWriteInterface.h>
/* An LED_Port object is an I/O expander pin that is connected to an LED indicator light.
/* An LED_Port object is an I/O expander output pin that is connected to an LED indicator light.
LED_Port functions turn LED on and off. LED_Port functions turn LED on and off.
This is for push-pull ouput pins.
For LEDs connected to open drain output types, use LED_Port class.
Example initialization: Example initialization:
const uint8_t IOE_ADDR = 0x20; const uint8_t IOE_ADDR = 0x20;
Port_MCP23S17 portA(IOE_ADDR, 0, 1<<0 | 1<<1 ); Port_MCP23S17 portA(IOE_ADDR, 0, 1<<0 | 1<<1 );

+ 12
- 0
src/LED_PortOpenDrain.cpp View File

#include "LED_PortOpenDrain.h"
/* functions are like LED_Port, but writeLow() writeHigh() are swapped.
*/
void LED_PortOpenDrain::on()
{
refPort.writeLow(pin);
}

void LED_PortOpenDrain::off()
{
refPort.writeHigh(pin);
}

+ 36
- 0
src/LED_PortOpenDrain.h View File

#ifndef LED_PORT_H
#define LED_PORT_H
#include <Arduino.h>
#include <inttypes.h>
#include <LEDInterface.h>
#include <PortWriteInterface.h>
/* An LED_PortOpenDrain object is an I/O expander ouput pin that is connected to an LED.
LED_PortOpenDrain functions turn LED on and off.
This is for open drain ouput pins.
For LEDs connected to push-pull output types, use LED_Port class.
Example initialization:
const uint8_t IOE_ADDR = 0x20;
Port_MCP23S17 portA(IOE_ADDR, 0, 1<<0 | 1<<1 );
LED_PortOpenDrain LED_fn(portA, 1<<5);
Example initialization:
Port_ShiftRegs shiftRegs(8);
LED_PortOpenDrain LED_fn(shiftRegs, 1<<6);
*/
class LED_PortOpenDrain : public LEDInterface
{
private:
PortWriteInterface& refPort;
const uint8_t pin; //bit pattern, 1 is pin connected to LED
public:
LED_PortOpenDrain(PortWriteInterface& refPort, const uint8_t pin)
: refPort(refPort), pin(pin) {}
virtual void on();
virtual void off();
};
#endif