code.py
  1  # SPDX-FileCopyrightText: 2020 Limor Fried for Adafruit Industries
  2  # SPDX-FileCopyrightText: 2020 Jeff Epler for Adafruit Industries
  3  #
  4  # SPDX-License-Identifier: MIT
  5  
  6  import random
  7  import time
  8  
  9  import adafruit_display_text.label
 10  from adafruit_bitmap_font import bitmap_font
 11  import board
 12  import displayio
 13  import framebufferio
 14  import sharpdisplay
 15  
 16  ## When making several changes, this ensures they aren't shown partially
 17  ## completed (except for the time to actually update the display)
 18  class BatchDisplayUpdate:
 19      def __init__(self, the_display):
 20          self.the_display = the_display
 21          self.auto_refresh = the_display.auto_refresh
 22  
 23      def __enter__(self):
 24          self.the_display.auto_refresh = False
 25  
 26      def __exit__(self, unused1, unused2, unused3):
 27          self.the_display.refresh()
 28          self.the_display.auto_refresh = self.auto_refresh
 29  
 30  # https://saytheirnames.com/
 31  # real people, not just #hashtags
 32  names = [
 33      "Rodney King",
 34      "Abner Louima",
 35      "Amadou Diallo",
 36      "Sean Bell",
 37      "Oscar Grant",
 38      "Eric Garner",
 39      "Michael Brown",
 40      "Laquan McDonald",
 41      "Freddie Gray",
 42      "Antwon Rose Jr",
 43      "Ahmaud Arbery",
 44      "Breonna Taylor",
 45      "John Crawford III",
 46      "Ezell Ford",
 47      "Dante Parker",
 48      "Michelle Cusseaux",
 49      "Laquan Mcdonald",
 50      "George Mann",
 51      "Tanisha Anderson",
 52      "Akai Gurley",
 53      "Tamir Rice",
 54      "Rumain Brisbon",
 55      "Jerame Reid",
 56      "Matthew Ajibade",
 57      "Frank Smart",
 58      "Nastasha McKenna",
 59      "Tony Robinson",
 60      "Anthony Hill",
 61      "Mya Hall",
 62      "Phillip White",
 63      "Eric Harris",
 64      "Walter Scott",
 65      "William Chapman II",
 66      "Alexia Christian",
 67      "Brendon Glenn",
 68      "Victor Maunel Larosa",
 69      "Jonathan Sanders",
 70      "Freddie Blue",
 71      "Joseph Mann",
 72      "Salvado Ellswood",
 73      "Sanda Bland",
 74      "Albert Joseph Davis",
 75      "Darrius Stewart",
 76      "Billy Ray Davis",
 77      "Samuel Dubose",
 78      "Michael Sabbie",
 79      "Brian Keith Day",
 80      "Christian Taylor",
 81      "Troy Robinson",
 82      "Asshams Pharoah Manley",
 83      "Felix Kumi",
 84      "Keith Harrison Mcleod",
 85      "Junior Prosper",
 86      "Lamontez Jones",
 87      "Paterson Brown",
 88      "Dominic Hutchinson",
 89      "Anthony Ashford",
 90      "Alonzo Smith",
 91      "Tyree Crawford",
 92      "India Kager",
 93      "La'vante Biggs",
 94      "Michael Lee Marshall",
 95      "Jamar Clark",
 96      "Richard Perkins",
 97      "Nathaniel Harris Pickett",
 98      "Benni Lee Tignor",
 99      "Miguel Espinal",
100      "Michael Noel",
101      "Kevin Matthews",
102      "Bettie Jones",
103      "Quintonio Legrier",
104      "Keith Childress Jr",
105      "Janet Wilson",
106      "Randy Nelson",
107      "Antronie Scott",
108      "Wendell Celestine",
109      "David Joseph",
110      "Calin Roquemore",
111      "Dyzhawn Perkins",
112      "Christoper Davis",
113      "Marco Loud",
114      "Peter Gaines",
115      "Torry Robison",
116      "Darius Robinson",
117      "Kevin Hicks",
118      "Mary Truxillo",
119      "Demarcus Semer",
120      "Willie Tillman",
121      "Terrill Thomas",
122      "Sylville Smith",
123      "Sean Reed",
124      "Alton Streling",
125      "Philando Castile",
126      "Terence Crutcher",
127      "Paul O'Neal",
128      "Alteria Woods",
129      "Jordan Edwards",
130      "Aaron Bailey",
131      "Ronell Foster",
132      "Stephon Clark",
133      "Antwon Rose II",
134      "Botham Jean",
135      "Pamela Turner",
136      "Dominique Clayton",
137      "Atatiana Jefferson",
138      "Christopher Whitfield",
139      "Christopher Mccovey",
140      "Eric Reason",
141      "Michael Lorenzo Dean",
142      "Tony McDade",
143      "David McAtee",
144      "George Floyd",
145  ]
146  
147  # A function to choose "k" different items from the "population" list
148  # We'll use it to select the names to display
149  def sample(population, k):
150      population = population[:]
151      for _ in range(k):
152          j = random.randint(0, len(population)-1)
153          yield population[j]
154          population[j] = population[-1]
155          population.pop()
156  
157  # Initialize the display, cleaning up after a display from the previous run
158  # if necessary
159  displayio.release_displays()
160  bus = board.SPI()
161  framebuffer = sharpdisplay.SharpMemoryFramebuffer(bus, board.D6, 400, 240)
162  display = framebufferio.FramebufferDisplay(framebuffer, auto_refresh = True)
163  
164  # Load our font
165  font = bitmap_font.load_font("/GothamBlack-54.bdf")
166  
167  # Create a Group for the BLM text
168  blm_group = displayio.Group()
169  display.show(blm_group)
170  
171  # Create a 3 line set of text for BLM
172  blm_font = [None, None, None]
173  for line in range(3):
174      label = adafruit_display_text.label.Label(font, color=0xFFFFFF)
175      label.anchor_point = (0, 0)
176      label.anchored_position = (8, line*84+8)
177      blm_font[line] = label
178      blm_group.append(label)
179  
180  # Get something on the display as soon as possible by loading
181  # specific glyphs.
182  font.load_glyphs(b"BLACK")
183  blm_font[0].text = "BLACK"
184  font.load_glyphs(b"ISEV")
185  blm_font[1].text = "LIVES"
186  font.load_glyphs(b"RMT")
187  blm_font[2].text = "MATTER"
188  font.load_glyphs(b"' DFGHJNOPQUWXYZabcdefghijklmnopqrstuvwxyz")
189  
190  
191  # Create a 2 line set of font text for names
192  names_font = [None, None]
193  for line in range(2):
194      label = adafruit_display_text.label.Label(font, color=0xFFFFFF)
195      # Center each line horizontally, position vertically
196      label.anchor_point = (0.5, 0)
197      label.anchored_position = (200, line*84+42)
198      names_font[line] = label
199  
200  # Create a Group for the name text
201  name_group = displayio.Group()
202  for line in names_font:
203      name_group.append(line)
204  
205  # Repeatedly show the BLM slogan and then 5 names.
206  while True:
207      display.show(blm_group)
208  
209      # Show the BLM slogan
210      with BatchDisplayUpdate(display):
211          blm_font[1].color = blm_font[2].color = 0  # hide lines 2&3
212      time.sleep(1)
213  
214      with BatchDisplayUpdate(display):
215          blm_font[1].color = 0xFFFFFF  # show middle line
216          blm_font[0].color = blm_font[2].color = 0  # hide lines 1&3
217      time.sleep(1)
218  
219      with BatchDisplayUpdate(display):
220          blm_font[2].color = 0xFFFFFF  # show last line
221          blm_font[0].color = blm_font[1].color = 0  # hide lines 1&2
222      time.sleep(1)
223  
224      with BatchDisplayUpdate(display):
225          for line in blm_font:
226              line.color = 0xFFFFFF
227      time.sleep(2)
228  
229      # Show 5 names
230      display.show(name_group)
231      for name in sample(names, 5):
232          print(name)
233          lines = name.split(" ")
234          with BatchDisplayUpdate(display):
235              for i in range(2):
236                  names_font[i].text = lines[i]
237  
238                  # Due to a bug in adafruit_display_text, we need to reestablish
239                  # the position of the labels when updating them.
240                  # Once https://github.com/adafruit/Adafruit_CircuitPython_Display_Text/issues/82
241                  # has been resolved, this code will no longer be necessary (but
242                  # will not be harmful either)
243                  names_font[i].anchor_point = (0.5, 0)
244                  names_font[i].anchored_position = (200, i*84+42)
245          time.sleep(5)
246      names_font[0].text = names_font[1].text = ""