Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. import RPi.GPIO as GPIO
  2. import time
  3.  
  4. delay = 0.000001
  5.  
  6. GPIO.setmode(GPIO.BCM)
  7. red1_pin = 17
  8. green1_pin = 18
  9. blue1_pin = 22
  10. red2_pin = 23
  11. green2_pin = 24
  12. blue2_pin = 25
  13. clock_pin = 3
  14. a_pin = 7
  15. b_pin = 8
  16. c_pin = 9
  17. latch_pin = 4
  18. oe_pin = 2
  19.  
  20. GPIO.setup(red1_pin, GPIO.OUT)
  21. GPIO.setup(green1_pin, GPIO.OUT)
  22. GPIO.setup(blue1_pin, GPIO.OUT)
  23. GPIO.setup(red2_pin, GPIO.OUT)
  24. GPIO.setup(green2_pin, GPIO.OUT)
  25. GPIO.setup(blue2_pin, GPIO.OUT)
  26. GPIO.setup(clock_pin, GPIO.OUT)
  27. GPIO.setup(a_pin, GPIO.OUT)
  28. GPIO.setup(b_pin, GPIO.OUT)
  29. GPIO.setup(c_pin, GPIO.OUT)
  30. GPIO.setup(latch_pin, GPIO.OUT)
  31. GPIO.setup(oe_pin, GPIO.OUT)
  32.  
  33. screen = [[0 for x in xrange(32)] for x in xrange(16)]
  34.  
  35. def clock():
  36. GPIO.output(clock_pin, 1)
  37. GPIO.output(clock_pin, 0)
  38.  
  39. def latch():
  40. GPIO.output(latch_pin, 1)
  41. GPIO.output(latch_pin, 0)
  42.  
  43. def bits_from_int(x):
  44. a_bit = x & 1
  45. b_bit = x & 2
  46. c_bit = x & 4
  47. return (a_bit, b_bit, c_bit)
  48.  
  49. def set_row(row):
  50. #time.sleep(delay)
  51. a_bit, b_bit, c_bit = bits_from_int(row)
  52. GPIO.output(a_pin, a_bit)
  53. GPIO.output(b_pin, b_bit)
  54. GPIO.output(c_pin, c_bit)
  55. #time.sleep(delay)
  56.  
  57. def set_color_top(color):
  58. #time.sleep(delay)
  59. red, green, blue = bits_from_int(color)
  60. GPIO.output(red1_pin, red)
  61. GPIO.output(green1_pin, green)
  62. GPIO.output(blue1_pin, blue)
  63. #time.sleep(delay)
  64.  
  65. def set_color_bottom(color):
  66. #time.sleep(delay)
  67. red, green, blue = bits_from_int(color)
  68. GPIO.output(red2_pin, red)
  69. GPIO.output(green2_pin, green)
  70. GPIO.output(blue2_pin, blue)
  71. #time.sleep(delay)
  72.  
  73. def refresh():
  74. for row in range(8):
  75. GPIO.output(oe_pin, 1)
  76. set_color_top(0)
  77. set_row(row)
  78. #time.sleep(delay)
  79. for col in range(32):
  80. set_color_top(screen[row][col])
  81. set_color_bottom(screen[row+8][col])
  82. clock()
  83. #GPIO.output(oe_pin, 0)
  84. latch()
  85. GPIO.output(oe_pin, 0)
  86. time.sleep(delay)
  87.  
  88. def fill_rectangle(x1, y1, x2, y2, color):
  89. for x in range(x1, x2):
  90. for y in range(y1, y2):
  91. screen[y][x] = color
  92.  
  93.  
  94. def set_pixel(x, y, color):
  95. screen[y][x] = color
  96.  
  97. fill_rectangle(0, 0, 12, 12, 1)
  98. fill_rectangle(20, 4, 30, 15, 2)
  99. fill_rectangle(15, 0, 19, 7, 7)
  100.  
  101. while True:
  102. refresh()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement