|
60 | 60 | __repo__ = "https://github.com/fourstix/Sparkfun_CircuitPython_SerLCD.git"
|
61 | 61 |
|
62 | 62 | # imports
|
63 |
| -# from abc import ABC, abstractmethod // Please no abstractmethods, CircuitPython is not Python 3 |
| 63 | +from abc import ABC, abstractmethod |
64 | 64 | from time import sleep
|
65 | 65 | from micropython import const
|
66 | 66 |
|
@@ -139,8 +139,8 @@ def _map_range(value, in_min, in_max, out_min, out_max):
|
139 | 139 |
|
140 | 140 | return int(result)
|
141 | 141 |
|
142 |
| -# base class |
143 |
| -class Sparkfun_SerLCD: |
| 142 | +# abstract base class |
| 143 | +class Sparkfun_SerLCD(ABC): |
144 | 144 | """Abstract base class for Sparkfun AVR-Based Serial LCD display.
|
145 | 145 | Use the appropriate driver communcation subclass Sprarkfun_SerLCD_I2C()
|
146 | 146 | for I2C, Sparkfun_SerLCD_SPI() for SPI or Sparkfun_SerLCD_UART for UART.
|
@@ -382,6 +382,27 @@ def set_contrast(self, value):
|
382 | 382 | self._write_bytes(data)
|
383 | 383 | sleep(0.010)
|
384 | 384 |
|
| 385 | + def set_i2c_address(self, new_address): |
| 386 | + """Change the I2C Address. 0x72 is the default. |
| 387 | + Note that this change is persistent. If anything goes wrong |
| 388 | + you may need to do a hardware reset to unbrick the display. |
| 389 | +
|
| 390 | + byte new_addr - new i2c address""" |
| 391 | + # Mask new address to byte |
| 392 | + new_address &= 0x00FF |
| 393 | + # Transmit to device on old address |
| 394 | + data = bytearray() |
| 395 | + # Send contrast command |
| 396 | + data.append(_SETTING_COMMAND) |
| 397 | + data.append(_ADDRESS_COMMAND) # 0x19 |
| 398 | + data.append(new_address) |
| 399 | + self._write_bytes(data) |
| 400 | + # Update our own address so we can still talk to the display |
| 401 | + self._change_i2c_address(new_address) |
| 402 | + |
| 403 | + # This may take awhile |
| 404 | + sleep(0.050) |
| 405 | + |
385 | 406 | def scroll_display_left(self, count=1):
|
386 | 407 | """Scroll the display to the left"""
|
387 | 408 | self._special_command(_LCD_CURSORSHIFT | _LCD_DISPLAYMOVE | _LCD_MOVELEFT, count)
|
@@ -442,11 +463,11 @@ def default_splash_screen(self):
|
442 | 463 |
|
443 | 464 | # abstract methods
|
444 | 465 |
|
445 |
| - # @abstractmethod |
| 466 | + @abstractmethod |
446 | 467 | def _write_bytes(self, data):
|
447 | 468 | pass
|
448 | 469 |
|
449 |
| - # @abstractmethod |
| 470 | + @abstractmethod |
450 | 471 | def _change_i2c_address(self, addr):
|
451 | 472 | pass
|
452 | 473 |
|
|
0 commit comments