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