Ledger Nano X - The secure hardware wallet
SHARE
TWEET

4Tronix IP Display Board Code

AverageMan Nov 5th, 2015 136 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /usr/bin/python
  2.  
  3. # GNU GPL V3
  4.  
  5. import smbus, time, subprocess, RPi.GPIO as GPIO
  6.  
  7. # Define list for digits 0..9, space, dash and DP in 7-segment (active High)
  8. digits = [0b00111111, 0b00000110, 0b01011011, 0b01001111, 0b01100110, 0b01101101, 0b01111101, 0b00000111, 0b01111111, 0b01101111, 0b00000000, 0b01000000, 0b10000000]
  9.  
  10. if GPIO.RPI_REVISION > 1:
  11.    bus = smbus.SMBus(1) # For revision 1 Raspberry Pi, change to bus = smbus.SMBus(1) for revision 2.
  12. else:
  13.    bus = smbus.SMBus(0) # For revision 1 Raspberry Pi, change to bus = smbus.SMBus(1) for revision 2.
  14.    
  15.  
  16. addr = 0x20 # I2C address of MCP23017
  17. bus.write_byte_data(addr, 0x00, 0x00) # Set all of bank 0 to outputs
  18. bus.write_byte_data(addr, 0x01, 0x00) # Set all of bank 1 to outputs
  19. bus.write_byte_data(addr, 0x13, 0xff) # Set all of bank 1 to High (Off)
  20.  
  21. def sendDigit(digit, pos):
  22.    t = (1<<pos) ^ 255
  23.    bus.write_byte_data(addr, 0x13, t) # Set bank 1 Pos to Low
  24.    bus.write_byte_data(addr, 0x12, digit) # Set bank 0 to digit
  25.  
  26. speed = 0.005
  27.  
  28. def iDisplay(val):
  29.    val1 = val/10
  30.    val2 = val1/10
  31.    count1 = 0
  32.    while count1 < 5:
  33.       count2 = 0
  34.       while count2 < 20:
  35.          sendDigit(digits[val - val1*10], 0) # '1'
  36.          time.sleep(speed)
  37.          sendDigit(0, 0)
  38.          sendDigit(digits[val1 - val2*10], 1) # '2'
  39.          time.sleep(speed)
  40.          sendDigit(0, 1)
  41.          sendDigit(digits[val2], 2) # '3'
  42.          time.sleep(speed)
  43.          sendDigit(0, 2)
  44.          sendDigit(digits[0], 3) # '0'
  45.          time.sleep(speed)
  46.          sendDigit(0, 3)
  47.          count2 += 1
  48.       time.sleep(0.5)
  49.       count1 += 1
  50.  
  51. def scroll(str1, count):
  52.    string = '   ' + str1 + '   '
  53.    for j in range(count):
  54.       for i in range(len(string)-3):
  55.          str2 = string[i:(i+4)]
  56.          sDisplay2(str2, count)
  57.      
  58. def sDisplay2(safeStr, count):
  59.    d1 = val(safeStr[3])
  60.    d2 = val(safeStr[2])
  61.    d3 = val(safeStr[1])
  62.    d4 = val(safeStr[0])
  63.    count2 = 0
  64.    while count2 < 10:
  65.       sendDigit(digits[d1], 0) # '1'
  66.       time.sleep(speed)
  67.       sendDigit(0, 0)
  68.       sendDigit(digits[d2], 1) # '2'
  69.       time.sleep(speed)
  70.       sendDigit(0, 1)
  71.       sendDigit(digits[d3], 2) # '3'
  72.       time.sleep(speed)
  73.       sendDigit(0, 2)
  74.       sendDigit(digits[d4], 3) # '0'
  75.       time.sleep(speed)
  76.       sendDigit(0, 3)
  77.       count2 += 1
  78.  
  79. def sDisplay(string):
  80.    safeStr = '    ' + string
  81.    l = len(safeStr)
  82.    d1 = val(safeStr[l-1])
  83.    d2 = val(safeStr[l-2])
  84.    d3 = val(safeStr[l-3])
  85.    d4 = val(safeStr[l-4])
  86.    count1 = 0
  87.    while count1 < 5:
  88.       count2 = 0
  89.       while count2 < 20:
  90.          sendDigit(digits[d1], 0) # '1'
  91.          time.sleep(speed)
  92.          sendDigit(0, 0)
  93.          sendDigit(digits[d2], 1) # '2'
  94.          time.sleep(speed)
  95.          sendDigit(0, 1)
  96.          sendDigit(digits[d3], 2) # '3'
  97.          time.sleep(speed)
  98.          sendDigit(0, 2)
  99.          sendDigit(digits[d4], 3) # '0'
  100.          time.sleep(speed)
  101.          sendDigit(0, 3)
  102.          count2 += 1
  103.       time.sleep(0.5)
  104.       count1 += 1
  105.  
  106. def val(digit):
  107.    if (ord(digit) >= 48 and ord(digit) <= 57):
  108.       return ord(digit) - 48
  109.    elif ord(digit) == 32: #space
  110.       return 10  # 10 is a blank
  111.    elif ord(digit) == 46: #period
  112.       return 11  # 11 is a dash
  113.  
  114.    
  115. arg = 'ip route list'
  116. waiting = True
  117. while waiting:
  118.    p = subprocess.Popen(arg, shell = True, stdout = subprocess.PIPE)
  119.    data = p.communicate()
  120.    split_data = data[0].split()
  121.    length = len(split_data)
  122.    print 'Length', length
  123.    if length > 8:
  124.       waiting = False
  125.    else:
  126.       scroll("0.0.0.0", 2)
  127. ipaddr = split_data[split_data.index('src')+1]
  128. print ipaddr
  129. #parts = ipaddr.split('.')
  130. #print parts[0]
  131. #print parts[1]
  132. #print parts[2]
  133. #print parts[3]
  134. #print int(parts[3])
  135. #iDisplay(int(parts[3]))
  136. #sDisplay(parts[3])
  137. scroll(ipaddr, 5)
  138. bus.write_byte_data(addr, 0x13, 0xff) # Set all of bank 1 to High (Off)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top