Last active
April 24, 2019 21:02
-
-
Save trwatson/fd5f8b2b7eac0e459432499d515db5e2 to your computer and use it in GitHub Desktop.
adafruit lcd testing with ip for raspberry pi
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
#apt-get install -y i2c-tools python-smbus vim | |
#pip3 install --upgrade setuptools | |
#pip3 install RPI.GPIO adafruit-blinka adafruit-circuitpython-charlcd netifaces | |
import board | |
import digitalio | |
import busio | |
import os | |
import socket | |
import adafruit_character_lcd.character_lcd_rgb_i2c as character_lcd | |
import netifaces as ni | |
import time | |
lcd_columns = 16 | |
lcd_rows = 2 | |
i2c = busio.I2C(board.SCL, board.SDA) | |
lcd = character_lcd.Character_LCD_RGB_I2C(i2c, lcd_columns, lcd_rows) | |
i2c = busio.I2C(board.SCL, board.SDA) | |
host_name = socket.gethostname() | |
host_ip = ni.ifaddresses('wlan0')[ni.AF_INET][0]['addr'] | |
def lcd_color(color): | |
switcher = { | |
"blue": [0,0,100], | |
"red": [100,0,0], | |
"green": [0,100,0], | |
"purple": [70,0,30], | |
} | |
return switcher.get(color, "nothing") | |
def print_lcd(color,message): | |
lcd.color = lcd_color(color) | |
lcd.message = str(message) | |
print_lcd("blue","Up: Host\nDown: IP") | |
try: | |
while True: | |
if lcd.left_button: | |
lcd.clear() | |
lcd.message = "Left!" | |
time.sleep(0.5) | |
lcd.clear() | |
time.sleep(0.5) | |
print_lcd("red",host_name+"\n"+host_ip) | |
if lcd.up_button: | |
lcd.clear() | |
lcd.message = "Up!" | |
time.sleep(0.5) | |
lcd.clear() | |
time.sleep(0.5) | |
print_lcd("blue",host_name) | |
if lcd.down_button: | |
lcd.clear() | |
lcd.message = "Down!" | |
time.sleep(0.5) | |
lcd.clear() | |
time.sleep(0.5) | |
print_lcd("green",host_ip) | |
if lcd.right_button: | |
lcd.clear() | |
lcd.message = "Right!" | |
time.sleep(0.5) | |
lcd.clear() | |
time.sleep(0.5) | |
print_lcd("purple",host_name+"\n"+host_ip) | |
if lcd.select_button: | |
lcd.clear() | |
time.sleep(0.5) | |
print_lcd("blue","Up: Host\nDown: IP") | |
except KeyboardInterrupt as e: | |
print("Stopping...") | |
quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment