-
Notifications
You must be signed in to change notification settings - Fork 6
Updated MAX7219 to be compatible with CircuitPython #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
be5d2d1
Update examples.rst
mrmcwethy 57c7177
update example with rst directives
mrmcwethy e38a3fb
fixed typo
mrmcwethy 8b7bf1f
initial checkin of base class
mrmcwethy f3052a0
adding support for MAX7219 compatible with CircuitPython
mrmcwethy 0c88ced
fixed to work with udpated class definitions
mrmcwethy a548bd7
change api to use digitalio; updated documentation
mrmcwethy 9b83091
Changed api to use digitalio;
mrmcwethy cc5d6dd
updated api to use digitalio; fixed comments
mrmcwethy f53df62
added back missing """
mrmcwethy 6bf0961
updated examples; fixed docu control strings
mrmcwethy 17af93a
remove adafruit_max7219; replaced with folder adafruit_max7219
mrmcwethy c1937bc
changed method names to use "_" no camelcase. updated examples. upd…
mrmcwethy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
# The MIT License (MIT) | ||
# | ||
# Copyright (c) 2017 Dan Halbert | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
# THE SOFTWARE. | ||
# | ||
|
||
""" | ||
:mod:`adafruit_max7219.bcddigits.BCDDigits` | ||
==================================================== | ||
""" | ||
from adafruit_max7219 import max7219 | ||
|
||
_DECODEMODE = const(9) | ||
_SCANLIMIT = const(11) | ||
_SHUTDOWN = const(12) | ||
_DISPLAYTEST = const(15) | ||
|
||
class BCDDigits(max7219.MAX7219): | ||
""" | ||
Basic support for display on a 7-Segment BCD display controlled | ||
by a Max7219 chip using SPI. | ||
""" | ||
def __init__(self, spi, csPin, nDigits=1): | ||
""" | ||
param: spi - an spi busio or spi bitbangio object | ||
param: csPin - board pin to use as chip select signal | ||
param: nDigits number of led 7-segment digits; default 1; max 8 | ||
""" | ||
self.nD = nDigits | ||
super().__init__(self.nD, 8 ,spi ,csPin) | ||
|
||
def init_display(self): | ||
|
||
for cmd, data in ( | ||
(_SHUTDOWN, 0), | ||
(_DISPLAYTEST, 0), | ||
(_SCANLIMIT, 7), | ||
(_DECODEMODE, (2**self.nD)-1), | ||
(_SHUTDOWN, 1), | ||
): | ||
self.write_cmd(cmd, data) | ||
|
||
self.clearAll() | ||
self.show() | ||
|
||
def setDigit(self, d, v): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please change function name style to set_digit. Its a common Python style thing. |
||
""" | ||
set one digit in the display | ||
param: d - the digit position; zero-based | ||
param: v - integer ranging from 0->15 | ||
""" | ||
d = self.nD - d - 1 | ||
for i in range(4): | ||
#print('digit {} pixel {} value {}'.format(d,i+4,v & 0x01)) | ||
self.pixel(d,i,v & 0x01) | ||
v >>= 1 | ||
|
||
def setDigits(self, s, ds): | ||
""" | ||
set the display from a list | ||
param: s - digit to start display zero-based | ||
param: ds - list of integer values ranging from 0->15 | ||
""" | ||
for d in ds: | ||
#print('set digit {} start {}'.format(d,start)) | ||
self.setDigit(s,d) | ||
s += 1 | ||
|
||
def setDot(self,d, col=None): | ||
""" | ||
set the decimal point for a digit | ||
param: d - the digit to set the decimal point zero-based | ||
param: col - value > zero lights the decimal point, else unlights the point | ||
""" | ||
if d < self.nD and d >= 0: | ||
#print('set dot {} = {}'.format((self.nD - d -1),col)) | ||
self.pixel(self.nD-d-1, 7,col) | ||
|
||
def clearAll(self): | ||
""" | ||
clear all digits and decimal points | ||
""" | ||
self.fill(1) | ||
for i in range(self.nD): | ||
self.setDot(i) | ||
|
||
def showStr(self,s,str): | ||
""" | ||
displays a numeric str in the display. shows digits 0-9, -, and . | ||
param: s - start position to show the numeric string | ||
param: str - the numeric string | ||
""" | ||
ci = s | ||
for i in range (len(str)): | ||
c = str[i] | ||
# print('c {}'.format(c)) | ||
v = 0x0f # assume blank | ||
if c >= '0' and c<='9': | ||
v = int(c) | ||
elif c == '-': | ||
v = 10 | ||
elif c == '.': | ||
self.setDot(ci-1,1) | ||
continue | ||
self.setDigit(ci,v) | ||
ci += 1 | ||
|
||
def showHelp(self, s): | ||
""" | ||
display the word HELP in the display | ||
param: s - start position to show HELP | ||
""" | ||
digits = [12,11,13,14] | ||
self.setDigits(s,digits) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the sphinx format for this is
:param <type> spi:
such as:param ~busio.SPI spi:
.