From 9ec4dcd28844154341de9eb91f6f84cac442b566 Mon Sep 17 00:00:00 2001 From: stylesuxx Date: Tue, 10 Feb 2015 21:44:31 +0100 Subject: [PATCH 1/8] Classified the module, so we can have multiple instances of the shifter on different pins. --- shiftpi.py | 203 ++++++++++++++++++++++++++--------------------------- 1 file changed, 101 insertions(+), 102 deletions(-) diff --git a/shiftpi.py b/shiftpi.py index 074b453..c0fc38c 100644 --- a/shiftpi.py +++ b/shiftpi.py @@ -16,122 +16,121 @@ HIGH = 1 LOW = 0 -# Define pins -_SER_pin = 25 #pin 14 on the 75HC595 -_RCLK_pin = 24 #pin 12 on the 75HC595 -_SRCLK_pin = 23 #pin 11 on the 75HC595 - -# is used to store states of all pins -_registers = list() - -#How many of the shift registers - you can change them with shiftRegisters method -_number_of_shiftregisters = 1 - -def pinsSetup(**kwargs): - ''' - Allows the user to define custom pins - ''' - global _SER_pin, _RCLK_pin, _SRCLK_pin - - custompins = 0 - serpin = _SER_pin - rclkpin = _RCLK_pin - srclkpin = _SRCLK_pin - - if len(kwargs) > 0: - custompins = 1 - - _SER_pin = kwargs.get('ser', _SER_pin) - _RCLK_pin = kwargs.get('rclk', _RCLK_pin) - _SRCLK_pin = kwargs.get('srclk', _SRCLK_pin) - - if custompins: - if _SER_pin != serpin or _RCLK_pin != rclkpin or _SRCLK_pin != srclkpin: - GPIO.setwarnings(True) - else: - GPIO.setwarnings(False) - - GPIO.setup(_SER_pin, GPIO.OUT) - GPIO.setup(_RCLK_pin, GPIO.OUT) - GPIO.setup(_SRCLK_pin, GPIO.OUT) - -def startupMode(mode, execute = False): - ''' - Allows the user to change the default state of the shift registers outputs - ''' - if isinstance(mode, int): - if mode is HIGH or mode is LOW: - _all(mode, execute) +class Shiftpi: + def __init__(self): + # Define pins + self._SER_pin = 25 #pin 14 on the 75HC595 + self._RCLK_pin = 24 #pin 12 on the 75HC595 + self._SRCLK_pin = 23 #pin 11 on the 75HC595 + + # is used to store states of all pins + self._registers = list() + + #How many of the shift registers - you can change them with shiftRegisters method + self._number_of_shiftregisters = 1 + self.pinsSetup() + + def pinsSetup(self, **kwargs): + ''' + Allows the user to define custom pins + ''' + + custompins = 0 + serpin = self._SER_pin + rclkpin = self._RCLK_pin + srclkpin = self._SRCLK_pin + + if len(kwargs) > 0: + custompins = 1 + + self._SER_pin = kwargs.get('ser', self._SER_pin) + self._RCLK_pin = kwargs.get('rclk', self._RCLK_pin) + self._SRCLK_pin = kwargs.get('srclk', self._SRCLK_pin) + + if custompins: + if self._SER_pin != serpin or self._RCLK_pin != rclkpin or self._SRCLK_pin != srclkpin: + GPIO.setwarnings(True) + else: + GPIO.setwarnings(False) + + GPIO.setup(self._SER_pin, GPIO.OUT) + GPIO.setup(self._RCLK_pin, GPIO.OUT) + GPIO.setup(self._SRCLK_pin, GPIO.OUT) + + def startupMode(self, mode, execute = False): + ''' + Allows the user to change the default state of the shift registers outputs + ''' + if isinstance(mode, int): + if mode is HIGH or mode is LOW: + self._all(mode, execute) + else: + raise ValueError("The mode can be only HIGH or LOW or Dictionary with specific pins and modes") + elif isinstance(mode, dict): + for pin, mode in mode.iteritems(): + self._setPin(pin, mode) + if execute: + self._execute() else: raise ValueError("The mode can be only HIGH or LOW or Dictionary with specific pins and modes") - elif isinstance(mode, dict): - for pin, mode in mode.iteritems(): - _setPin(pin, mode) - if execute: - _execute() - else: - raise ValueError("The mode can be only HIGH or LOW or Dictionary with specific pins and modes") - -def shiftRegisters(num): - ''' - Allows the user to define the number of shift registers are connected - ''' - global _number_of_shiftregisters - _number_of_shiftregisters = num - _all(LOW) -def digitalWrite(pin, mode): - ''' - Allows the user to set the state of a pin on the shift register - ''' - if pin == ALL: - _all(mode) - else: - if len(_registers) == 0: - _all(LOW) + def shiftRegisters(self, num): + ''' + Allows the user to define the number of shift registers are connected + ''' + self._number_of_shiftregisters = num + self._all(LOW) - _setPin(pin, mode) - _execute() + def digitalWrite(self, pin, mode): + ''' + Allows the user to set the state of a pin on the shift register + ''' + if pin == ALL: + self._all(mode) + else: + if len(self._registers) == 0: + self._all(LOW) -def delay(millis): - ''' - Used for creating a delay between commands - ''' - millis_to_seconds = float(millis)/1000 - return sleep(millis_to_seconds) + self._setPin(pin, mode) + self._execute() -def _all_pins(): - return _number_of_shiftregisters * 8 + def delay(self, millis): + ''' + Used for creating a delay between commands + ''' + millis_to_seconds = float(millis)/1000 + return sleep(millis_to_seconds) -def _all(mode, execute = True): - all_shr = _all_pins() + def _all_pins(self): + return self._number_of_shiftregisters * 8 - for pin in range(0, all_shr): - _setPin(pin, mode) - if execute: - _execute() + def _all(self, mode, execute = True): + all_shr = self._all_pins() - return _registers + for pin in range(0, all_shr): + self._setPin(pin, mode) + if execute: + self._execute() -def _setPin(pin, mode): - try: - _registers[pin] = mode - except IndexError: - _registers.insert(pin, mode) + return self._registers -def _execute(): - all_pins = _all_pins() - GPIO.output(_RCLK_pin, GPIO.LOW) + def _setPin(self, pin, mode): + try: + self._registers[pin] = mode + except IndexError: + self._registers.insert(pin, mode) - for pin in range(all_pins -1, -1, -1): - GPIO.output(_SRCLK_pin, GPIO.LOW) + def _execute(self): + all_pins = self._all_pins() + GPIO.output(self._RCLK_pin, GPIO.LOW) - pin_mode = _registers[pin] + for pin in range(all_pins -1, -1, -1): + GPIO.output(self._SRCLK_pin, GPIO.LOW) - GPIO.output(_SER_pin, pin_mode) - GPIO.output(_SRCLK_pin, GPIO.HIGH) + pin_mode = self._registers[pin] - GPIO.output(_RCLK_pin, GPIO.HIGH) + GPIO.output(self._SER_pin, pin_mode) + GPIO.output(self._SRCLK_pin, GPIO.HIGH) -pinsSetup() + GPIO.output(self._RCLK_pin, GPIO.HIGH) From de41621f7a627486abf4b89b0deaa964ba6b467f Mon Sep 17 00:00:00 2001 From: stylesuxx Date: Tue, 10 Feb 2015 22:05:52 +0100 Subject: [PATCH 2/8] Fixed module to be PEP8 conform --- shiftpi.py | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/shiftpi.py b/shiftpi.py index c0fc38c..a1eec13 100644 --- a/shiftpi.py +++ b/shiftpi.py @@ -1,8 +1,8 @@ ''' -A library that allows simple access to 74HC595 shift registers on a Raspberry Pi using any digital I/O pins. +A library that allows simple access to 74HC595 shift registers on a Raspberry +Pi using any digital I/O pins. ''' - import RPi.GPIO as GPIO from time import sleep @@ -12,21 +12,25 @@ version_info = (0, 2) # Define MODES -ALL = -1 +ALL = -1 HIGH = 1 -LOW = 0 +LOW = 0 + class Shiftpi: def __init__(self): # Define pins - self._SER_pin = 25 #pin 14 on the 75HC595 - self._RCLK_pin = 24 #pin 12 on the 75HC595 - self._SRCLK_pin = 23 #pin 11 on the 75HC595 + self._SER_pin = 25 # pin 14 on the 75HC595 + self._RCLK_pin = 24 # pin 12 on the 75HC595 + self._SRCLK_pin = 23 # pin 11 on the 75HC595 # is used to store states of all pins self._registers = list() - #How many of the shift registers - you can change them with shiftRegisters method + ''' + How many of the shift registers - you can change them with + shiftRegisters method + ''' self._number_of_shiftregisters = 1 self.pinsSetup() @@ -34,7 +38,6 @@ def pinsSetup(self, **kwargs): ''' Allows the user to define custom pins ''' - custompins = 0 serpin = self._SER_pin rclkpin = self._RCLK_pin @@ -48,7 +51,9 @@ def pinsSetup(self, **kwargs): self._SRCLK_pin = kwargs.get('srclk', self._SRCLK_pin) if custompins: - if self._SER_pin != serpin or self._RCLK_pin != rclkpin or self._SRCLK_pin != srclkpin: + if ((self._SER_pin != serpin or + self._RCLK_pin != rclkpin or + self._SRCLK_pin != srclkpin)): GPIO.setwarnings(True) else: GPIO.setwarnings(False) @@ -57,23 +62,25 @@ def pinsSetup(self, **kwargs): GPIO.setup(self._RCLK_pin, GPIO.OUT) GPIO.setup(self._SRCLK_pin, GPIO.OUT) - def startupMode(self, mode, execute = False): + def startupMode(self, mode, execute=False): ''' - Allows the user to change the default state of the shift registers outputs + Allows the user to change the default state of the shift registers + outputs ''' if isinstance(mode, int): if mode is HIGH or mode is LOW: self._all(mode, execute) else: - raise ValueError("The mode can be only HIGH or LOW or Dictionary with specific pins and modes") + raise ValueError('''The mode can be only HIGH or LOW or + Dictionary with specific pins and modes''') elif isinstance(mode, dict): for pin, mode in mode.iteritems(): self._setPin(pin, mode) if execute: self._execute() else: - raise ValueError("The mode can be only HIGH or LOW or Dictionary with specific pins and modes") - + raise ValueError('''The mode can be only HIGH or LOW or Dictionary + with specific pins and modes''') def shiftRegisters(self, num): ''' @@ -105,7 +112,7 @@ def delay(self, millis): def _all_pins(self): return self._number_of_shiftregisters * 8 - def _all(self, mode, execute = True): + def _all(self, mode, execute=True): all_shr = self._all_pins() for pin in range(0, all_shr): @@ -125,7 +132,7 @@ def _execute(self): all_pins = self._all_pins() GPIO.output(self._RCLK_pin, GPIO.LOW) - for pin in range(all_pins -1, -1, -1): + for pin in range(all_pins - 1, -1, -1): GPIO.output(self._SRCLK_pin, GPIO.LOW) pin_mode = self._registers[pin] From 9a295a2db721e680576f609278bb8640584e5a50 Mon Sep 17 00:00:00 2001 From: Janek Thomaschewski Date: Fri, 4 Dec 2015 01:21:46 +0000 Subject: [PATCH 3/8] allow passing GPIO to init --- shiftpi.py | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/shiftpi.py b/shiftpi.py index a1eec13..4828dd6 100644 --- a/shiftpi.py +++ b/shiftpi.py @@ -3,10 +3,9 @@ Pi using any digital I/O pins. ''' -import RPi.GPIO as GPIO +#import RPi.GPIO as GPIO from time import sleep -GPIO.setmode(GPIO.BCM) version = "0.2" version_info = (0, 2) @@ -16,9 +15,15 @@ HIGH = 1 LOW = 0 - class Shiftpi: - def __init__(self): + def __init__(self, GPIO=None): + + if GPIO is None: + import RPi.GPIO as GPIO + self.GPIO = GPIO + + self.GPIO.setmode(self.GPIO.BCM) + # Define pins self._SER_pin = 25 # pin 14 on the 75HC595 self._RCLK_pin = 24 # pin 12 on the 75HC595 @@ -54,13 +59,13 @@ def pinsSetup(self, **kwargs): if ((self._SER_pin != serpin or self._RCLK_pin != rclkpin or self._SRCLK_pin != srclkpin)): - GPIO.setwarnings(True) + self.GPIO.setwarnings(True) else: - GPIO.setwarnings(False) + self.GPIO.setwarnings(False) - GPIO.setup(self._SER_pin, GPIO.OUT) - GPIO.setup(self._RCLK_pin, GPIO.OUT) - GPIO.setup(self._SRCLK_pin, GPIO.OUT) + self.GPIO.setup(self._SER_pin, self.GPIO.OUT) + self.GPIO.setup(self._RCLK_pin, self.GPIO.OUT) + self.GPIO.setup(self._SRCLK_pin, self.GPIO.OUT) def startupMode(self, mode, execute=False): ''' @@ -130,14 +135,14 @@ def _setPin(self, pin, mode): def _execute(self): all_pins = self._all_pins() - GPIO.output(self._RCLK_pin, GPIO.LOW) + self.GPIO.output(self._RCLK_pin, self.GPIO.LOW) for pin in range(all_pins - 1, -1, -1): - GPIO.output(self._SRCLK_pin, GPIO.LOW) + self.GPIO.output(self._SRCLK_pin, self.GPIO.LOW) pin_mode = self._registers[pin] - GPIO.output(self._SER_pin, pin_mode) - GPIO.output(self._SRCLK_pin, GPIO.HIGH) + self.GPIO.output(self._SER_pin, pin_mode) + self.GPIO.output(self._SRCLK_pin, self.GPIO.HIGH) - GPIO.output(self._RCLK_pin, GPIO.HIGH) + self.GPIO.output(self._RCLK_pin, self.GPIO.HIGH) From 72939b30df112219d1a1525edf2d5a70dc614a2a Mon Sep 17 00:00:00 2001 From: jayho Date: Thu, 30 Jun 2016 00:48:33 -0500 Subject: [PATCH 4/8] Created some test files --- binCount.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ shiftTest.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ testonepin.py | 7 +++++++ 3 files changed, 105 insertions(+) create mode 100644 binCount.py create mode 100644 shiftTest.py create mode 100644 testonepin.py diff --git a/binCount.py b/binCount.py new file mode 100644 index 0000000..ad91b8b --- /dev/null +++ b/binCount.py @@ -0,0 +1,47 @@ +from shiftpi import HIGH, LOW, digitalWrite, delay + +for x in range(0, 256): + y = x + print 'setting binary ' + str(y) + if y >= 128: + y -= 128 + digitalWrite(0, HIGH) + else: + digitalWrite(0, LOW) + if y >= 64: + y -= 64 + digitalWrite(1, HIGH) + else: + digitalWrite(1, LOW) + if y >= 32: + y -= 32 + digitalWrite(2, HIGH) + else: + digitalWrite(2, LOW) + if y >= 16: + y -= 16 + digitalWrite(3, HIGH) + else: + digitalWrite(3, LOW) + if y >= 8: + y -= 8 + digitalWrite(4, HIGH) + else: + digitalWrite(4, LOW) + if y >= 4: + y -= 4 + digitalWrite(5, HIGH) + else: + digitalWrite(5, LOW) + if y >= 2: + y -= 2 + digitalWrite(6, HIGH) + else: + digitalWrite(6, LOW) + if y >= 1: + y -= 1 + digitalWrite(7, HIGH) + else: + digitalWrite(7, LOW) + delay(250) + \ No newline at end of file diff --git a/shiftTest.py b/shiftTest.py new file mode 100644 index 0000000..30c19de --- /dev/null +++ b/shiftTest.py @@ -0,0 +1,51 @@ + +import shiftpi + +#shiftpi.pinsSetup({"ser": 16, "rclk": 20, "srclk": 21}) +#shiftpi.startupMode({1: shiftpi.HIGH, 4: shiftpi.HIGH, 6: shiftpi.HIGH}, True) +shiftpi.delay(1000) +shiftpi.digitalWrite(shiftpi.ALL, shiftpi.LOW) +shiftpi.delay(1000) +for x in range(0, 9): + shiftpi.digitalWrite(0, shiftpi.HIGH) + shiftpi.delay(500) + # turns shift register's pin 1 to LOW + shiftpi.digitalWrite(0, shiftpi.LOW) + shiftpi.delay(500) + shiftpi.digitalWrite(1, shiftpi.HIGH) + shiftpi.delay(500) + # turns shift register's pin 1 to LOW + shiftpi.digitalWrite(1, shiftpi.LOW) + shiftpi.delay(500) + shiftpi.digitalWrite(2, shiftpi.HIGH) + shiftpi.delay(500) + # turns shift register's pin 1 to LOW + shiftpi.digitalWrite(2, shiftpi.LOW) + shiftpi.delay(500) + shiftpi.digitalWrite(3, shiftpi.HIGH) + shiftpi.delay(500) + # turns shift register's pin 1 to LOW + shiftpi.digitalWrite(3, shiftpi.LOW) + shiftpi.delay(500) + shiftpi.digitalWrite(4, shiftpi.HIGH) + shiftpi.delay(500) + # turns shift register's pin 1 to LOW + shiftpi.digitalWrite(4, shiftpi.LOW) + shiftpi.delay(500) + shiftpi.digitalWrite(5, shiftpi.HIGH) + shiftpi.delay(500) + # turns shift register's pin 1 to LOW + shiftpi.digitalWrite(5, shiftpi.LOW) + shiftpi.delay(500) + shiftpi.digitalWrite(6, shiftpi.HIGH) + shiftpi.delay(500) + # turns shift register's pin 1 to LOW + shiftpi.digitalWrite(6, shiftpi.LOW) + shiftpi.delay(500) + shiftpi.digitalWrite(7, shiftpi.HIGH) + shiftpi.delay(500) + # turns shift register's pin 1 to LOW + shiftpi.digitalWrite(7, shiftpi.LOW) + shiftpi.delay(500) + + diff --git a/testonepin.py b/testonepin.py new file mode 100644 index 0000000..cc4eed3 --- /dev/null +++ b/testonepin.py @@ -0,0 +1,7 @@ +from shiftpi import HIGH, LOW, digitalWrite, delay + +while True: + digitalWrite(1, HIGH) + delay(1000) + digitalWrite(1, LOW) + delay(1000) \ No newline at end of file From 2f2476cbd8cae2f204d14b840e1521e7a8268f05 Mon Sep 17 00:00:00 2001 From: jayhopeter Date: Thu, 30 Jun 2016 09:48:19 -0500 Subject: [PATCH 5/8] Adding VS project files --- .vs/shiftpi/v14/.suo | Bin 0 -> 22528 bytes shiftpi.pyproj | 33 +++++++++++++++++++++++++++++++++ shiftpi.sln | 20 ++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 .vs/shiftpi/v14/.suo create mode 100644 shiftpi.pyproj create mode 100644 shiftpi.sln diff --git a/.vs/shiftpi/v14/.suo b/.vs/shiftpi/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..3c012bec178f67a83ba9a4c4a2d9b03023716af4 GIT binary patch literal 22528 zcmeHP-ESOM6~CLdkTj*Gq@<+{=@Q%!+RS!$_B(+z`{5;}F>zz(qpGE9y&ulT&aT;A zJBi}ZynzrPR1omO1ETbShe~}a51@v=@j`$~2oOT>7a;M7)P&#f-nrh{$?kZ(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WP2l4U@X%zg&pkq~Od-HeyJV7eSwV(>T{Eq-@CGJ1?dm^r9qu}RhK?PrX z?tj$pTB@tRba9LO*L3OMKM^;RE_cfr)98$AYya$KM(B^C*b_Q-)~}|Hnu-9ogr8r(5Zq i91P + + + Debug + 2.0 + {d9a3d37c-2fa6-4b80-bdbc-587f98c93e5b} + + binCount.py + + . + . + {888888a0-9f3d-457c-b088-3a5042f75d52} + Standard Python launcher + + + + + + + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets + + + + + + + + + + + + \ No newline at end of file diff --git a/shiftpi.sln b/shiftpi.sln new file mode 100644 index 0000000..f1bb5af --- /dev/null +++ b/shiftpi.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "shiftpi", "shiftpi.pyproj", "{D9A3D37C-2FA6-4B80-BDBC-587F98C93E5B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D9A3D37C-2FA6-4B80-BDBC-587F98C93E5B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D9A3D37C-2FA6-4B80-BDBC-587F98C93E5B}.Release|Any CPU.ActiveCfg = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal From f684e31e19bb9ee7686641eb9f49cabf824cb722 Mon Sep 17 00:00:00 2001 From: jayhopeter Date: Thu, 30 Jun 2016 09:49:35 -0500 Subject: [PATCH 6/8] update ignores --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index 0d20b64..5d4f7b4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,6 @@ *.pyc +.svn/entries +.svn/format +*.svn-base +.svn/wc.db +*.db-journal From 20f6920f7cea4a5ab3f6ea19de8a90cfbfcade3b Mon Sep 17 00:00:00 2001 From: jayhopeter Date: Thu, 30 Jun 2016 10:06:56 -0500 Subject: [PATCH 7/8] cleaned up the binary counter sample --- binCount.py | 61 ++++++++++++++--------------------------------------- 1 file changed, 16 insertions(+), 45 deletions(-) diff --git a/binCount.py b/binCount.py index ad91b8b..c4e80ed 100644 --- a/binCount.py +++ b/binCount.py @@ -1,47 +1,18 @@ +#testing shiftpi +#this program uses the outputs to a do a binary counter from 0 to the total number of bits + from shiftpi import HIGH, LOW, digitalWrite, delay -for x in range(0, 256): - y = x - print 'setting binary ' + str(y) - if y >= 128: - y -= 128 - digitalWrite(0, HIGH) - else: - digitalWrite(0, LOW) - if y >= 64: - y -= 64 - digitalWrite(1, HIGH) - else: - digitalWrite(1, LOW) - if y >= 32: - y -= 32 - digitalWrite(2, HIGH) - else: - digitalWrite(2, LOW) - if y >= 16: - y -= 16 - digitalWrite(3, HIGH) - else: - digitalWrite(3, LOW) - if y >= 8: - y -= 8 - digitalWrite(4, HIGH) - else: - digitalWrite(4, LOW) - if y >= 4: - y -= 4 - digitalWrite(5, HIGH) - else: - digitalWrite(5, LOW) - if y >= 2: - y -= 2 - digitalWrite(6, HIGH) - else: - digitalWrite(6, LOW) - if y >= 1: - y -= 1 - digitalWrite(7, HIGH) - else: - digitalWrite(7, LOW) - delay(250) - \ No newline at end of file +bits = 8 #hard coded to 8 (one chip) for now + +#loop from 0 to the max value of the bits available +for x in range(0, 2 ** bits): + temp = x + print 'setting binary ' + str(temp) + for b in range(bits - 1, -1,-1): + if temp >= 2 ** b: + y -= 2 ** b + digitalWrite((bits-1)- b, HIGH) + else: + digitalWrite((bits-1)- b, LOW) + delay(250) \ No newline at end of file From 8adc801eed3df7a42d41478e44bd2a5a9e8168c4 Mon Sep 17 00:00:00 2001 From: Jason Johnson Date: Thu, 30 Jun 2016 10:29:53 -0500 Subject: [PATCH 8/8] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index eb2d849..f98da1c 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,8 @@ or you can use the library methods as shown in the first example, with importing digitalWrite(ALL, HIGH) -That's it! :) + +Check out the binary counter example program (binCount.py) # The API look and feel