java.lang.Object
com.pi4j.crowpi.components.Component
com.pi4j.crowpi.components.internal.HT16K33
com.pi4j.crowpi.components.SevenSegmentComponent
Implementation of the CrowPi seven-segment display using I2C with Pi4J
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Mapping of segments to their respective bit according to the HT16K33. -
Field Summary
Modifier and TypeFieldDescriptionMapping of characters to their respective byte representation.protected static final int
Default I2C bus address for the seven-segment display on the CrowPiprotected static final int
Default I2C device address for the seven-segment display on the CrowPi -
Constructor Summary
ConstructorDescriptionSevenSegmentComponent
(com.pi4j.context.Context pi4j) Creates a new seven-segment display component with the default bus and device address.SevenSegmentComponent
(com.pi4j.context.Context pi4j, int bus, int device) Creates a new seven-segment display component with a custom bus and device address. -
Method Summary
Modifier and TypeMethodDescriptionprotected static byte
fromSegments
(SevenSegmentComponent.Segment... segments) Helper method for creating a raw digit value (byte) from 0-n segments.protected com.pi4j.io.i2c.I2C
getI2C()
Returns the created I2C instance for the seven-segment displayprotected byte
getRawDigit
(int position) Gets the raw digit at the specified position.void
print
(double d) Prints the given double value to the seven-segment display, automatically setting the decimal point if applicable.void
print
(int i) Prints the given integer value to the seven-segment display.void
Prints the first four letters (or less if applicable) of the given string to the display.void
Prints the hours and minutes of the givenLocalTime
instance to the seven-segment display.void
setColon
(boolean enabled) Enables or disables the colon symbol of the seven-segment display.void
setDecimalPoint
(int position, boolean enabled) Enables or disables the decimal point at the given digit position.void
setDigit
(int position, char c) Sets the digit at the specified position to the given character.void
setDigit
(int position, int i) Sets the digit at the specified position to the given integer.void
setDigit
(int position, SevenSegmentComponent.Segment... segments) Sets the digit at the specified position to match the given segments.protected void
setRawDigit
(int position, byte value) Sets the raw digit at the specified position.Methods inherited from class com.pi4j.crowpi.components.internal.HT16K33
clear, refresh, setBlinkRate, setBrightness, setEnabled
Methods inherited from class com.pi4j.crowpi.components.Component
sleep, triggerSimpleEvent
-
Field Details
-
DEFAULT_BUS
protected static final int DEFAULT_BUSDefault I2C bus address for the seven-segment display on the CrowPi- See Also:
-
DEFAULT_DEVICE
protected static final int DEFAULT_DEVICEDefault I2C device address for the seven-segment display on the CrowPi- See Also:
-
CHAR_BITSETS
Mapping of characters to their respective byte representation. Each byte is a bitset where each bit specifies if a specific segment should be enabled (1) or disabled (0).
-
-
Constructor Details
-
SevenSegmentComponent
public SevenSegmentComponent(com.pi4j.context.Context pi4j) Creates a new seven-segment display component with the default bus and device address.- Parameters:
pi4j
- Pi4J context
-
SevenSegmentComponent
public SevenSegmentComponent(com.pi4j.context.Context pi4j, int bus, int device) Creates a new seven-segment display component with a custom bus and device address.- Parameters:
pi4j
- Pi4J contextbus
- Bus addressdevice
- Device address
-
-
Method Details
-
print
public void print(int i) Prints the given integer value to the seven-segment display. This works by converting the integer into a string and passing it toprint(String)
. Please note that due to the limitations of the display only the first four digits will be displayed. This will clear the buffer and automatically callHT16K33.refresh()
afterwards to immediately display the number.- Parameters:
i
- Integer to display
-
print
public void print(double d) Prints the given double value to the seven-segment display, automatically setting the decimal point if applicable. This works by converting the double into a string and passing it toprint(String)
. Please note that due to the limitations of the display only the first four digits will be displayed. This will clear the buffer and automatically callHT16K33.refresh()
afterwards to immediately display the number.- Parameters:
d
- Double to display
-
print
Prints the hours and minutes of the givenLocalTime
instance to the seven-segment display. The time will be displayed in 24 hours format as HH:MM with the colon being active for every odd second. This will clear the buffer and automatically callHT16K33.refresh()
afterwards to immediately display the time.- Parameters:
time
- Time to display
-
print
Prints the first four letters (or less if applicable) of the given string to the display. Additional letters are ignored. Adding a dot after a digit or putting a colon after two digits causes the respective symbols to be displayed too. This will clear the buffer and automatically callHT16K33.refresh()
afterwards to immediately display the text.Example: "1.2:34." will print the string "1234" to the display, with decimal point #1 and #4 as well as the colon symbol being set
- Parameters:
s
- String which should be printed
-
setColon
public void setColon(boolean enabled) Enables or disables the colon symbol of the seven-segment display. This will only affect the internal buffer and does not get displayed untilHT16K33.refresh()
gets called.- Parameters:
enabled
- Specify if colon should be enabled or disabled.
-
setDecimalPoint
public void setDecimalPoint(int position, boolean enabled) Enables or disables the decimal point at the given digit position. Please note that the decimal point is just an additional belonging to the same digit. This means that overriding the specific digit (e.g. usingsetRawDigit(int, byte)
will reset the decimal point. This will only affect the internal buffer and does not get displayed untilHT16K33.refresh()
gets called.- Parameters:
position
- Desired position of digit from 0-3.enabled
- Specify if decimal point should be enabled or disabled.
-
setDigit
public void setDigit(int position, int i) Sets the digit at the specified position to the given integer. The integer must not contain more than one number, in other words it has to be in the range 0-9. This will only affect the internal buffer and does not get displayed untilHT16K33.refresh()
gets called.- Parameters:
position
- Desired position of digit from 0-3.i
- Single digit number which should be displayed.
-
setDigit
public void setDigit(int position, char c) Sets the digit at the specified position to the given character. The character must be representable by the seven-segment display, so only a subset of chars is supported. This will only affect the internal buffer and does not get displayed untilHT16K33.refresh()
gets called.- Parameters:
position
- Desired position of digit from 0-3.c
- Character which should be displayed.
-
setDigit
Sets the digit at the specified position to match the given segments. This will only affect the internal buffer and does not get displayed untilHT16K33.refresh()
gets called.- Parameters:
position
- Desired position of digit from 0-3.segments
- Segments which should be displayed.
-
setRawDigit
protected void setRawDigit(int position, byte value) Sets the raw digit at the specified position. This method will take a byte value which gets processed by the underlying chip. The byte represents a bitset where each bit belongs to a specific segment and decides if its enabled (1) or disabled (0). Valid values can be crafted using thefromSegments(Segment...)
method. This will only affect the internal buffer and does not get displayed untilHT16K33.refresh()
gets called.- Parameters:
position
- Desired position of digit from 0-3.value
- Raw byte value to be displayed.
-
getRawDigit
protected byte getRawDigit(int position) Gets the raw digit at the specified position. This method will return the internal byte value of the underlying chip. The byte represents a bitset where each bit belongs to a specific segment and decides if its enabled (1) or disabled (0).- Parameters:
position
- Desired position of digit from 0-3.- Returns:
- Raw byte value at specified position.
-
getI2C
protected com.pi4j.io.i2c.I2C getI2C()Returns the created I2C instance for the seven-segment display- Returns:
- I2C instance
-
fromSegments
Helper method for creating a raw digit value (byte) from 0-n segments. This can be used together with theSevenSegmentComponent.Segment
enumeration to create and display your own digits. All segments passed to this method will be flagged as active and enabled when passed tosetRawDigit(int, byte)
- Parameters:
segments
- Segments which should be enabled to together- Returns:
- Raw digit value as byte
-