-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added functionalities: extended strings, custom characters, some demos
- Loading branch information
Showing
12 changed files
with
441 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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,121 @@ | ||
#! /usr/bin/env python | ||
|
||
# Custom characters string program. Writes strings with custom characters, that can't | ||
# be found in the characters table. It is possible to use a custom characters by definig | ||
# it's code on paseholder whyle useng and extended string. | ||
# Appearance of the custom characters can be defined by redifenition of the fields of | ||
# CustomCaracters class instance. | ||
# Codes of the custom characters, that can be used in placeholders are the following: | ||
# 1st - {0x00}, 2nd - {0x01}, 3rd - {0x02}, 4th - {0x03}, 5th - {0x04}, | ||
# 6th - {0x05}, 7th - {0x06} and 8th - {0x07} | ||
# Remember to use method load_custom_characters_data() to load the custom characters | ||
# data into the CG RAM. | ||
# Demo program for the I2C 16x2 Display from Ryanteck.uk | ||
# Created by Dmitry Safonov | ||
|
||
# Import necessary libraries for communication and display use | ||
import drivers | ||
from time import sleep | ||
|
||
# Load the driver and set it to "display" | ||
# If you use something from the driver library use the "display." prefix first | ||
display = drivers.Lcd() | ||
|
||
# Create object with custom characters data | ||
cc = drivers.CustomCharacters(display) | ||
|
||
# Redefine the default characters: | ||
# Custom caracter #1. Code {0x00}. | ||
cc.char_1_data = ["01110", | ||
"01010", | ||
"01110", | ||
"00100", | ||
"11111", | ||
"11111", | ||
"11111", | ||
"11111"] | ||
|
||
# Custom caracter #2. Code {0x01}. | ||
cc.char_2_data = ["11111", | ||
"10101", | ||
"10101", | ||
"11111", | ||
"11111", | ||
"10101", | ||
"10101", | ||
"11111"] | ||
|
||
# Custom caracter #3. Code {0x02}. | ||
cc.char_3_data = ["10001", | ||
"10001", | ||
"10001", | ||
"11111", | ||
"11111", | ||
"11111", | ||
"11111", | ||
"11111"] | ||
|
||
# Custom caracter #4. Code {0x03}. | ||
cc.char_4_data = ["11111", | ||
"11011", | ||
"10001", | ||
"10001", | ||
"10001", | ||
"10001", | ||
"11011", | ||
"11111"] | ||
|
||
# Custom caracter #5. Code {0x04}. | ||
cc.char_5_data = ["00000", | ||
"00000", | ||
"11011", | ||
"11011", | ||
"00000", | ||
"10001", | ||
"01110", | ||
"00000"] | ||
|
||
# Custom caracter #6. Code {0x05}. | ||
cc.char_6_data = ["01010", | ||
"11111", | ||
"11111", | ||
"01110", | ||
"00100", | ||
"00000", | ||
"00000", | ||
"00000"] | ||
|
||
# Custom caracter #7. Code {0x06}. | ||
cc.char_7_data = ["11111", | ||
"11011", | ||
"10001", | ||
"10101", | ||
"10101", | ||
"10101", | ||
"11011", | ||
"11111"] | ||
|
||
# Custom caracter #8. Code {0x07}. | ||
cc.char_8_data = ["11111", | ||
"10001", | ||
"11111", | ||
"00000", | ||
"00000", | ||
"11111", | ||
"10001", | ||
"11111"] | ||
# Load custom characters data to CG RAM: | ||
cc.load_custom_characters_data() | ||
|
||
# Main body of code | ||
try: | ||
while True: | ||
# Remember that your sentences can only be 16 characters long! | ||
print("Printing custom characters:") | ||
display.lcd_display_string("Custom caracters:", 1) # Write line of text to first line of display | ||
display.lcd_display_extended_string("{0x00}{0x01}{0x02}{0x03}{0x04}{0x05}{0x06}{0x07}", 2) # Write line of text to second line of display | ||
sleep(2) # Give time for the message to be read | ||
except KeyboardInterrupt: | ||
# If there is a KeyboardInterrupt (when you press ctrl+c), exit the program and cleanup | ||
print("Cleaning up!") | ||
display.lcd_clear() |
This file contains 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,28 @@ | ||
#! /usr/bin/env python | ||
|
||
# Extended strings program. Writes and updates special (extended) strings | ||
# with placeholders "{}" so, that it is possible to draw any character from the | ||
# characters table using a caharcter code. | ||
# Demo program for the I2C 16x2 Display from Ryanteck.uk | ||
# Created by Matthew Timmons-Brown for The Raspberry Pi Guy YouTube channel | ||
|
||
# Import necessary libraries for communication and display use | ||
import drivers | ||
from time import sleep | ||
|
||
# Load the driver and set it to "display" | ||
# If you use something from the driver library use the "display." prefix first | ||
display = drivers.Lcd() | ||
|
||
# Main body of code | ||
try: | ||
while True: | ||
# Remember that your sentences can only be 16 characters long! | ||
print("Writing simple string") | ||
display.lcd_display_string("Simple string", 1) # Write line of text to first line of display | ||
display.lcd_display_extended_string("Ext. str:{0xEF}{0xF6}{0xA5}{0xDF}{0xA3}", 2) # Write line of text to second line of display | ||
sleep(2) # Give time for the message to be read | ||
except KeyboardInterrupt: | ||
# If there is a KeyboardInterrupt (when you press ctrl+c), exit the program and cleanup | ||
print("Cleaning up!") | ||
display.lcd_clear() |
This file contains 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,143 @@ | ||
#! /usr/bin/env python | ||
|
||
# Programm showing anumated progress bar using custom characters. | ||
# Demo program for the I2C 16x2 Display | ||
# Created by Dmitry Safonov | ||
|
||
# Import necessary libraries for communication and display use | ||
import drivers | ||
from time import sleep | ||
|
||
# Load the driver and set it to "display" | ||
# If you use something from the driver library use the "display." prefix first | ||
display = drivers.Lcd() | ||
|
||
# Create object with custom characters data | ||
cc = drivers.CustomCharacters(display) | ||
|
||
# Redefine the default characters that will be used to create process bar: | ||
# Left full character. Code {0x00}. | ||
cc.char_1_data = ["01111", | ||
"11000", | ||
"10011", | ||
"10111", | ||
"10111", | ||
"10011", | ||
"11000", | ||
"01111"] | ||
|
||
# Left empty character. Code {0x01}. | ||
cc.char_2_data = ["01111", | ||
"11000", | ||
"10000", | ||
"10000", | ||
"10000", | ||
"10000", | ||
"11000", | ||
"01111"] | ||
|
||
# Central full character. Code {0x02}. | ||
cc.char_3_data = ["11111", | ||
"00000", | ||
"11011", | ||
"11011", | ||
"11011", | ||
"11011", | ||
"00000", | ||
"11111"] | ||
|
||
# Central empty character. Code {0x03}. | ||
cc.char_4_data = ["11111", | ||
"00000", | ||
"00000", | ||
"00000", | ||
"00000", | ||
"00000", | ||
"00000", | ||
"11111"] | ||
|
||
# Right full character. Code {0x04}. | ||
cc.char_5_data = ["11110", | ||
"00011", | ||
"11001", | ||
"11101", | ||
"11101", | ||
"11001", | ||
"00011", | ||
"11110"] | ||
|
||
# Right empty character. Code {0x05}. | ||
cc.char_6_data = ["11110", | ||
"00011", | ||
"00001", | ||
"00001", | ||
"00001", | ||
"00001", | ||
"00011", | ||
"11110"] | ||
|
||
# Load custom characters data to CG RAM: | ||
cc.load_custom_characters_data() | ||
|
||
MIN_CHARGE = 0 | ||
MAX_CHARGE = 100 | ||
|
||
# Main body of code | ||
charge = 0 | ||
charge_delta = 5 | ||
bar_repr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] | ||
|
||
try: | ||
while True: | ||
# Remember that your sentences can only be 16 characters long! | ||
display.lcd_display_string("Battery charge:", 1) | ||
|
||
# Render charge bar: | ||
bar_string = "" | ||
for i in range(10): | ||
if i == 0: | ||
# Left character | ||
if bar_repr[i] == 0: | ||
# Left empty character | ||
bar_string = bar_string + "{0x01}" | ||
else: | ||
# Left full character | ||
bar_string = bar_string + "{0x00}" | ||
elif i == 9: | ||
# Right character | ||
if bar_repr[i] == 0: | ||
# Right empty character | ||
bar_string = bar_string + "{0x05}" | ||
else: | ||
# Right full character | ||
bar_string = bar_string + "{0x04}" | ||
else: | ||
# Central character | ||
if bar_repr[i] == 0: | ||
# Central empty character | ||
bar_string = bar_string + "{0x03}" | ||
else: | ||
# Central full character | ||
bar_string = bar_string + "{0x02}" | ||
|
||
# Print the string to display: | ||
display.lcd_display_extended_string(bar_string + " {0}% ".format(charge), 2) | ||
|
||
# Update the charge and recalculate bar_repr | ||
charge += charge_delta | ||
if (charge >= MAX_CHARGE) or (charge <= MIN_CHARGE): | ||
charge_delta = -1 * charge_delta | ||
|
||
for i in range(10): | ||
if charge >= ((i + 1) * 10): | ||
bar_repr[i] = 1 | ||
else: | ||
bar_repr[i] = 0 | ||
|
||
# Wait for some time | ||
sleep(1) | ||
|
||
except KeyboardInterrupt: | ||
# If there is a KeyboardInterrupt (when you press ctrl+c), exit the program and cleanup | ||
print("Cleaning up!") | ||
display.lcd_clear() |
0
demo_lcd.py → demo_lcd_simple_strings.py
100755 → 100644
File renamed without changes.
This file contains 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 |
---|---|---|
@@ -1 +1 @@ | ||
from .i2c_dev import Lcd | ||
from .i2c_dev import Lcd, CustomCharacters |
Oops, something went wrong.