Skip to content

Updated examples reformatted with Black #20

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 1 commit into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/example10_turn_off_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
"""
from time import sleep
import board
from sparkfun_serlcd import Sparkfun_SerLCD_I2C
from sparkfun_serlcd import Sparkfun_SerLCD_I2C

i2c = board.I2C()
serlcd = Sparkfun_SerLCD_I2C(i2c)

print('Example 10: Turn Off Display')
print('Press Ctrl-C to end program.')
print("Example 10: Turn Off Display")
print("Press Ctrl-C to end program.")

serlcd.clear()

Expand Down
16 changes: 8 additions & 8 deletions examples/example11_text_direction.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@
"""
from time import sleep
import board
from sparkfun_serlcd import Sparkfun_SerLCD_I2C
from sparkfun_serlcd import Sparkfun_SerLCD_I2C

i2c = board.I2C()
serlcd = Sparkfun_SerLCD_I2C(i2c)

print('Example 11: Text Direction')
print('Press Ctrl-C to end program.')
print("Example 11: Text Direction")
print("Press Ctrl-C to end program.")

serlcd.write("Hello, world!")

letter_a = ord('a')
letter_j = ord('j')
letter_q = ord('q')
letter_z = ord('z')
letter_a = ord("a")
letter_j = ord("j")
letter_q = ord("q")
letter_z = ord("z")

# Start with letter 'a'
letter = letter_a
Expand Down Expand Up @@ -64,7 +64,7 @@
sleep(0.5)

serlcd.write(chr(letter))
sleep(1) # wait a second
sleep(1) # wait a second
letter += 1

except KeyboardInterrupt:
Expand Down
6 changes: 3 additions & 3 deletions examples/example12_display_input_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
"""
from time import sleep
import board
from sparkfun_serlcd import Sparkfun_SerLCD_I2C
from sparkfun_serlcd import Sparkfun_SerLCD_I2C

i2c = board.I2C()
serlcd = Sparkfun_SerLCD_I2C(i2c)

print('Example 12: Display Input Text')
print('Press Ctrl-C to end program.')
print("Example 12: Display Input Text")
print("Press Ctrl-C to end program.")


try:
Expand Down
26 changes: 13 additions & 13 deletions examples/example13_fast_backlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,62 +23,62 @@
"""
from time import sleep
import board
from sparkfun_serlcd import Sparkfun_SerLCD_I2C
from sparkfun_serlcd import Sparkfun_SerLCD_I2C

i2c = board.I2C()
serlcd = Sparkfun_SerLCD_I2C(i2c)

print('Example 13: Fast Backlight')
print('Press Ctrl-C to end program.')
print("Example 13: Fast Backlight")
print("Press Ctrl-C to end program.")

try:
while True:
serlcd.set_fast_backlight_rgb(0, 0, 0) # black is off
serlcd.set_fast_backlight_rgb(0, 0, 0) # black is off
serlcd.clear()
serlcd.write("Black (off)")
sleep(3)

serlcd.set_fast_backlight_rgb(255, 0, 0) #bright red
serlcd.set_fast_backlight_rgb(255, 0, 0) # bright red
serlcd.clear()
serlcd.write("Red")
sleep(3)

serlcd.set_fast_backlight(0xFF8C00) #orange
serlcd.set_fast_backlight(0xFF8C00) # orange
serlcd.clear()
serlcd.write("Orange")
sleep(3)

serlcd.set_fast_backlight_rgb(255, 255, 0) #bright yellow
serlcd.set_fast_backlight_rgb(255, 255, 0) # bright yellow
serlcd.clear()
serlcd.write("Yellow")
sleep(3)

serlcd.set_fast_backlight_rgb(0, 255, 0) #bright green
serlcd.set_fast_backlight_rgb(0, 255, 0) # bright green
serlcd.clear()
serlcd.write("Green")
sleep(3)

serlcd.set_fast_backlight_rgb(0, 0, 255) #bright blue
serlcd.set_fast_backlight_rgb(0, 0, 255) # bright blue
serlcd.clear()
serlcd.write("Blue")
sleep(3)

serlcd.set_fast_backlight(0x4B0082) #indigo, a kind of dark purplish blue
serlcd.set_fast_backlight(0x4B0082) # indigo, a kind of dark purplish blue
serlcd.clear()
serlcd.write("Indigo")
sleep(3)

serlcd.set_fast_backlight(0xA020F0) #violet
serlcd.set_fast_backlight(0xA020F0) # violet
serlcd.clear()
serlcd.write("Violet")
sleep(3)

serlcd.set_fast_backlight(0x808080) #grey
serlcd.set_fast_backlight(0x808080) # grey
serlcd.clear()
serlcd.write("Grey")
sleep(3)

serlcd.set_fast_backlight_rgb(255, 255, 255) #bright white
serlcd.set_fast_backlight_rgb(255, 255, 255) # bright white
serlcd.clear()
serlcd.write("White")
sleep(3)
Expand Down
4 changes: 2 additions & 2 deletions examples/example14_show_firmware_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
i2c = board.I2C()
serlcd = Sparkfun_SerLCD_I2C(i2c)

print('Example 12: Show Firmware Version')
print('Press Ctrl-C to end program.')
print("Example 12: Show Firmware Version")
print("Press Ctrl-C to end program.")

serlcd.clear()

Expand Down
6 changes: 3 additions & 3 deletions examples/example15_system_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
i2c = board.I2C()
serlcd = Sparkfun_SerLCD_I2C(i2c)

print('Press Ctrl-C to end program.')
print("Press Ctrl-C to end program.")


try:
Expand All @@ -46,7 +46,7 @@
serlcd.command(187)
serlcd.command(217)
serlcd.write("Messages on")
serlcd.set_cursor(0,1)
serlcd.set_cursor(0, 1)
serlcd.write("White")
sleep(3)

Expand All @@ -57,7 +57,7 @@
serlcd.command(162)
serlcd.command(202)
serlcd.write("Messages off")
serlcd.set_cursor(0,1)
serlcd.set_cursor(0, 1)
serlcd.write("Purple")
sleep(2)

Expand Down
8 changes: 4 additions & 4 deletions examples/example16_splash_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
i2c = board.I2C()
serlcd = Sparkfun_SerLCD_I2C(i2c)

print('Example 16: Splash Screen')
print("Example 16: Splash Screen")

# Set backlight to bright white
serlcd.set_backlight_rgb(255, 255, 255)
Expand All @@ -47,12 +47,12 @@
serlcd.save_splash_screen()

# Uncomment this line to set splash screen back to default
#serlcd.default_splash_screen()
# serlcd.default_splash_screen()

# This will cause the splash to be displayed at power on
serlcd.splash_screen(True)

# Uncomment the next line to supress any splash display at power on
#serlcd.splash_screen(False)
# serlcd.splash_screen(False)

print('Power off dislpay. Then Power back on to see Splash Screen changes.')
print("Power off dislpay. Then Power back on to see Splash Screen changes.")
26 changes: 13 additions & 13 deletions examples/example1_hello_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,42 +31,42 @@
serlcd = Sparkfun_SerLCD_I2C(i2c)

# Enable SPI communication
#import digitalio
#from sparkfun_serlcd import Sparkfun_SerLCD_SPI
#spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
# import digitalio
# from sparkfun_serlcd import Sparkfun_SerLCD_SPI
# spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
#
# Set up chip select, CE0 or D8 is labeled CS on Sparkfun Pi Hat
#cs = digitalio.DigitalInOut(board.CE0)
#cs.direction = digitalio.Direction.OUTPUT
# cs = digitalio.DigitalInOut(board.CE0)
# cs.direction = digitalio.Direction.OUTPUT
#
#serlcd = Sparkfun_SerLCD_SPI(spi, cs)
# serlcd = Sparkfun_SerLCD_SPI(spi, cs)

# Enable UART Serial communication
# SerLCD is connected to the RPi via a USB to TTL 3.3v Serial Cable:
# https://www.sparkfun.com/products/12977
# https://www.adafruit.com/product/954

#import serial
#from sparkfun_serlcd import Sparkfun_SerLCD_UART
#usb0 = serial.Serial(
# import serial
# from sparkfun_serlcd import Sparkfun_SerLCD_UART
# usb0 = serial.Serial(
# port='/dev/ttyUSB0',
# baudrate = 9600,
# parity=serial.PARITY_NONE,
# stopbits=serial.STOPBITS_ONE,
# bytesize=serial.EIGHTBITS,
# timeout=1)
#
#serlcd = Sparkfun_SerLCD_UART(usb0)
# serlcd = Sparkfun_SerLCD_UART(usb0)

print('Example 1: Hello World')
print('Press Ctrl-C to end program.')
print("Example 1: Hello World")
print("Press Ctrl-C to end program.")

serlcd.write("Hello, world!")

i = 0
try:
while True:
serlcd.set_cursor(0,1)
serlcd.set_cursor(0, 1)
serlcd.write(i)
i += 1
sleep(1)
Expand Down
22 changes: 11 additions & 11 deletions examples/example2_backlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"""
from time import sleep
import board
from sparkfun_serlcd import Sparkfun_SerLCD_I2C
from sparkfun_serlcd import Sparkfun_SerLCD_I2C

i2c = board.I2C()
serlcd = Sparkfun_SerLCD_I2C(i2c)
Expand All @@ -35,52 +35,52 @@

try:
while True:
serlcd.set_backlight_rgb(0, 0, 0) # black is off
serlcd.set_backlight_rgb(0, 0, 0) # black is off
serlcd.clear()
serlcd.write("Black (off)")
sleep(3)

serlcd.set_backlight_rgb(255, 0, 0) #bright red
serlcd.set_backlight_rgb(255, 0, 0) # bright red
serlcd.clear()
serlcd.write("Red")
sleep(3)

serlcd.set_backlight(0xFF8C00) #orange
serlcd.set_backlight(0xFF8C00) # orange
serlcd.clear()
serlcd.write("Orange")
sleep(3)

serlcd.set_backlight_rgb(255, 255, 0) #bright yellow
serlcd.set_backlight_rgb(255, 255, 0) # bright yellow
serlcd.clear()
serlcd.write("Yellow")
sleep(3)

serlcd.set_backlight_rgb(0, 255, 0) #bright green
serlcd.set_backlight_rgb(0, 255, 0) # bright green
serlcd.clear()
serlcd.write("Green")
sleep(3)

serlcd.set_backlight_rgb(0, 0, 255) #bright blue
serlcd.set_backlight_rgb(0, 0, 255) # bright blue
serlcd.clear()
serlcd.write("Blue")
sleep(3)

serlcd.set_backlight(0x4B0082) #indigo, a kind of dark purplish blue
serlcd.set_backlight(0x4B0082) # indigo, a kind of dark purplish blue
serlcd.clear()
serlcd.write("Indigo")
sleep(3)

serlcd.set_backlight(0xA020F0) #violet
serlcd.set_backlight(0xA020F0) # violet
serlcd.clear()
serlcd.write("Violet")
sleep(3)

serlcd.set_backlight(0x808080) #grey
serlcd.set_backlight(0x808080) # grey
serlcd.clear()
serlcd.write("Grey")
sleep(3)

serlcd.set_backlight_rgb(255, 255, 255) #bright white
serlcd.set_backlight_rgb(255, 255, 255) # bright white
serlcd.clear()
serlcd.write("White")
sleep(3)
Expand Down
18 changes: 9 additions & 9 deletions examples/example3_cursor_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import time
import random
import board
from sparkfun_serlcd import Sparkfun_SerLCD_I2C
from sparkfun_serlcd import Sparkfun_SerLCD_I2C

i2c = board.I2C()
serlcd = Sparkfun_SerLCD_I2C(i2c)
Expand All @@ -37,29 +37,29 @@
# num_rows = 4

# Starting character value
letter = ord('a')
letter = ord("a")

print('Example 3: Cursor Position')
print('Press Ctrl-C to end program.')
print("Example 3: Cursor Position")
print("Press Ctrl-C to end program.")

# Clear the display before writing random letters
serlcd.clear()

try:
while True:
# pick a random column 0 to 15 (or 19)
col = random.randint(0, num_cols-1)
col = random.randint(0, num_cols - 1)
# pick a random row 0 to 1 (or 3)
row = random.randint(0, num_rows-1)
row = random.randint(0, num_rows - 1)

# Move to random location and write the next letter
serlcd.set_cursor(col,row)
serlcd.set_cursor(col, row)
serlcd.write(chr(letter))

# Get the next letter wrapping around after z
letter += 1
if letter > ord('z'):
letter = ord('a')
if letter > ord("z"):
letter = ord("a")

time.sleep(0.5)

Expand Down
Loading