Package com.diozero.devices
Class OutputShiftRegister
- java.lang.Object
-
- com.diozero.internal.spi.AbstractDeviceFactory
-
- com.diozero.devices.OutputShiftRegister
-
- All Implemented Interfaces:
DeviceInterface
,GpioExpander
,DeviceFactoryInterface
,GpioDeviceFactoryInterface
,PwmOutputDeviceFactoryInterface
,AutoCloseable
public class OutputShiftRegister extends AbstractDeviceFactory implements GpioDeviceFactoryInterface, PwmOutputDeviceFactoryInterface, GpioExpander
Digital output device factory using an output shift register, e.g. the 74HC595 8-bit Serial-In, Parallel-Out Shift Register.
Wiring for 74HC595
Q1 1 16 Vcc Q2 2 15 Q0 Q3 3 14 SER (Data Pin) Q4 4 13 ^OE (Output Enable, low == enable) Q5 5 12 RCLK (Storage Register Clock / Latch Pin) Q6 6 11 SRCLK (Shift Register Clock / Clock Pin) Q7 7 10 ^SRCLR (Shift Register Clear, low == clear) GND 8 9 Qh'
Timings for SN74HC595
- Clock Frequency:
- 2V: 5MHz, 4.5V: 25MHz, 6V: 29MHz
- Pulse Duration (SRCLK or RCLK high or low):
- 2V: 100ns, 4.5V: 20ns, 6V: 17ns
- Setup Time (SER before SRCLK high):
- 2V: 125ns, 4.5V: 25ns, 6V: 21ns
- Setup Time (SRCLK high before RCLK high *):
- 2V: 94ns, 4.5V: 19ns, 6V: 16ns
- Hold Time (Hold time, SER after SRCLK high):
- 2V: 0ns, 4.5V: 0ns, 6V: 0ns
* This set-up time allows the storage register to receive stable data from the shift register. The clocks can be tied together, in which case the shift register is one clock pulse ahead of the storage register.
Credit: Seggan
-
-
Field Summary
-
Fields inherited from class com.diozero.internal.spi.AbstractDeviceFactory
closed, deviceStates
-
Fields inherited from interface com.diozero.devices.GpioExpander
ALL_INPUT, ALL_OUTPUT, GPIOS_PER_PORT
-
-
Constructor Summary
Constructors Constructor Description OutputShiftRegister(int dataGpio, int clockGpio, int latchGpio, int numOutputs)
OutputShiftRegister(DigitalOutputDevice dataPin, DigitalOutputDevice clockPin, DigitalOutputDevice latchPin, int numOutputs)
OutputShiftRegister(GpioDeviceFactoryInterface deviceFactory, int dataGpio, int clockGpio, int latchGpio, int numOutputs)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
void
close()
Close this device factory including all devices that have been provisioned by it.GpioDigitalInputDeviceInterface
createDigitalInputDevice(String key, PinInfo pinInfo, GpioPullUpDown pud, GpioEventTrigger trigger)
GpioDigitalInputOutputDeviceInterface
createDigitalInputOutputDevice(String key, PinInfo pinInfo, DeviceMode mode)
GpioDigitalOutputDeviceInterface
createDigitalOutputDevice(String key, PinInfo pinInfo, boolean initialValue)
InternalPwmOutputDeviceInterface
createPwmOutputDevice(String key, PinInfo pinInfo, int pwmFrequency, float initialValue)
void
flush()
BoardPinInfo
getBoardPinInfo()
Get information about pins that can be provisioned by this device factory.int
getBoardPwmFrequency()
String
getName()
Get the name of this device factoryboolean
getValue(int outputPin)
byte
getValues(int port)
void
setBoardPwmFrequency(int pwmFrequency)
void
setBufferedValue(int outputPin, boolean value)
void
setDirections(int port, byte directions)
Set the directions for all pins on this port using the specified directions bit mask.void
setValues(int port, byte newValues)
Set the output value for a pins on this port.-
Methods inherited from class com.diozero.internal.spi.AbstractDeviceFactory
createI2CKey, createPinKey, createPwmPinKey, createSerialKey, createServoPinKey, createSpiKey, deviceClosed, deviceOpened, getDevice, isClosed, isDeviceOpened, reopen
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.diozero.internal.spi.DeviceFactoryInterface
createI2CKey, createPinKey, createPwmPinKey, createSerialKey, createServoPinKey, createSpiKey, deviceClosed, deviceOpened, getDevice, isClosed, isDeviceOpened, reopen, start
-
Methods inherited from interface com.diozero.internal.spi.GpioDeviceFactoryInterface
provisionDigitalInputDevice, provisionDigitalInputOutputDevice, provisionDigitalOutputDevice
-
Methods inherited from interface com.diozero.internal.spi.PwmOutputDeviceFactoryInterface
provisionPwmOutputDevice
-
-
-
-
Constructor Detail
-
OutputShiftRegister
public OutputShiftRegister(int dataGpio, int clockGpio, int latchGpio, int numOutputs)
-
OutputShiftRegister
public OutputShiftRegister(GpioDeviceFactoryInterface deviceFactory, int dataGpio, int clockGpio, int latchGpio, int numOutputs)
-
OutputShiftRegister
public OutputShiftRegister(DigitalOutputDevice dataPin, DigitalOutputDevice clockPin, DigitalOutputDevice latchPin, int numOutputs)
-
-
Method Detail
-
setDirections
public void setDirections(int port, byte directions)
Description copied from interface:GpioExpander
Set the directions for all pins on this port using the specified directions bit mask. 0 = output, 1 = input- Specified by:
setDirections
in interfaceGpioExpander
- Parameters:
port
- the bank of up to 8 GPIOsdirections
- bit mask specifying the directions for up to 8 GPIOs. 0 = output, 1 = input
-
setValues
public void setValues(int port, byte newValues)
Description copied from interface:GpioExpander
Set the output value for a pins on this port.- Specified by:
setValues
in interfaceGpioExpander
- Parameters:
port
- the bank of up to 8 GPIOsnewValues
- bit mask specifying on/off values. 1 = on, 0 = off
-
getValue
public boolean getValue(int outputPin)
-
getValues
public byte getValues(int port)
-
setBufferedValue
public void setBufferedValue(int outputPin, boolean value)
-
flush
public void flush()
-
clear
public void clear()
-
close
public void close() throws RuntimeIOException
Description copied from interface:DeviceFactoryInterface
Close this device factory including all devices that have been provisioned by it.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceDeviceFactoryInterface
- Specified by:
close
in interfaceDeviceInterface
- Overrides:
close
in classAbstractDeviceFactory
- Throws:
RuntimeIOException
-
getName
public String getName()
Description copied from interface:DeviceFactoryInterface
Get the name of this device factory- Specified by:
getName
in interfaceDeviceFactoryInterface
- Returns:
- the name of this device factory
-
getBoardPinInfo
public BoardPinInfo getBoardPinInfo()
Description copied from interface:DeviceFactoryInterface
Get information about pins that can be provisioned by this device factory.- Specified by:
getBoardPinInfo
in interfaceDeviceFactoryInterface
- Returns:
- board pin info instance for this device factory
-
createDigitalInputDevice
public GpioDigitalInputDeviceInterface createDigitalInputDevice(String key, PinInfo pinInfo, GpioPullUpDown pud, GpioEventTrigger trigger)
- Specified by:
createDigitalInputDevice
in interfaceGpioDeviceFactoryInterface
-
createDigitalOutputDevice
public GpioDigitalOutputDeviceInterface createDigitalOutputDevice(String key, PinInfo pinInfo, boolean initialValue)
- Specified by:
createDigitalOutputDevice
in interfaceGpioDeviceFactoryInterface
-
createDigitalInputOutputDevice
public GpioDigitalInputOutputDeviceInterface createDigitalInputOutputDevice(String key, PinInfo pinInfo, DeviceMode mode)
- Specified by:
createDigitalInputOutputDevice
in interfaceGpioDeviceFactoryInterface
-
getBoardPwmFrequency
public int getBoardPwmFrequency()
- Specified by:
getBoardPwmFrequency
in interfacePwmOutputDeviceFactoryInterface
-
setBoardPwmFrequency
public void setBoardPwmFrequency(int pwmFrequency)
- Specified by:
setBoardPwmFrequency
in interfacePwmOutputDeviceFactoryInterface
-
createPwmOutputDevice
public InternalPwmOutputDeviceInterface createPwmOutputDevice(String key, PinInfo pinInfo, int pwmFrequency, float initialValue)
- Specified by:
createPwmOutputDevice
in interfacePwmOutputDeviceFactoryInterface
-
-