Skip to content

Instantly share code, notes, and snippets.

@wandrson
Last active May 20, 2017 21:03
Show Gist options
  • Save wandrson/4dff9ffa6b96a200a4941416eafbb1c8 to your computer and use it in GitHub Desktop.
Save wandrson/4dff9ffa6b96a200a4941416eafbb1c8 to your computer and use it in GitHub Desktop.
Simple python script to display raspberry pi ip address using a Pimoroni Blinkt
#!/usr/bin/env python
import socket
from time import sleep
from blinkt import set_clear_on_exit, set_pixel, show
colors = [
[ 0, 0, 0],#0 black
[ 32, 32, 0],#1 brown
[255, 0, 0],#2 red
[255, 69, 0],#3 orange
[255,255, 0],#4 yellow
[ 0,255, 0],#5 green
[ 0, 0,255],#6 blue
[128, 0,118],#7 violet
[ 10, 10, 10],#8 grey
[204,204,204],#9 white
]
set_clear_on_exit()
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('8.8.8.8', 1))
local_ip_address = [int(x) for x in ((s.getsockname()[0]).split('.'))]
B1 = [colors[int(local_ip_address[0]/100)], colors[int(int(local_ip_address[0]%100)/10)], colors[int(int(local_ip_address[0]%100)%10)]]
B2 = [colors[int(local_ip_address[1]/100)], colors[int(int(local_ip_address[1]%100)/10)], colors[int(int(local_ip_address[1]%100)%10)]]
B3 = [colors[int(local_ip_address[2]/100)], colors[int(int(local_ip_address[2]%100)/10)], colors[int(int(local_ip_address[2]%100)%10)]]
B4 = [colors[int(local_ip_address[3]/100)], colors[int(int(local_ip_address[3]%100)/10)], colors[int(int(local_ip_address[3]%100)%10)]]
while True:
# Display first pair of bytes with a 'RED' flag
set_pixel(0, 255, 0, 0)
# Display first byte
set_pixel(2, B1[0][0], B1[0][1], B1[0][2])
set_pixel(3, B1[1][0], B1[1][1], B1[1][2])
set_pixel(4, B1[2][0], B1[2][1], B1[2][2])
# Display second byte
set_pixel(5, B2[0][0], B2[0][1], B2[0][2])
set_pixel(6, B2[1][0], B2[1][1], B2[1][2])
set_pixel(7, B2[2][0], B2[2][1], B2[2][2])
# Now display the first two bytes for five seconds
show()
sleep(5.0)
# Display second pair of bytes with a blue flag
set_pixel(0, 0, 0, 255)
# Display first byte
set_pixel(2, B3[0][0], B3[0][1], B3[0][2])
set_pixel(3, B3[1][0], B3[1][1], B3[1][2])
set_pixel(4, B3[2][0], B3[2][1], B3[2][2])
# Display second byte
set_pixel(5, B4[0][0], B4[0][1], B4[0][2])
set_pixel(6, B4[1][0], B4[1][1], B4[1][2])
set_pixel(7, B4[2][0], B4[2][1], B4[2][2])
# Now display the first two bytes for five seconds
show()
sleep(5.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment