rasmonkey17

Untitled

Aug 5th, 2021
1,019
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import time
  2. from rpi_ws281x import *
  3.  
  4. LED_COUNT = 64
  5. LED_PIN = 18
  6. NUM_PIXELS_ROW = 8
  7. NUM_PIXELS_COL = 8
  8.  
  9. COLOR_1 = Color(235, 64, 52)
  10.  
  11. epoch = time.time()
  12.  
  13. def getRow(index):
  14.     return index // NUM_PIXELS_ROW
  15.  
  16. def getColumn(index):
  17.     return index - getRow(index) * NUM_PIXELS_ROW
  18.  
  19. def makeBlank(strip):
  20.     for i in range(LED_COUNT):
  21.         strip.setPixelColor(i, Color(0, 0, 0))
  22.     strip.show();
  23.  
  24. def stripeUp(strip, color, wait_ms=50):
  25.     for i in range(LED_COUNT):
  26.         strip.setPixelColor(i, color)
  27.         strip.show()
  28.         time.sleep(wait_ms / 1000.0)
  29.  
  30. def stripeDown(strip, color, wait_ms=50):
  31.     for i in range(LED_COUNT - 1, 0, -1):
  32.         strip.setPixelColor(i, color)
  33.         strip.show()
  34.         time.sleep(wait_ms / 1000.0)
  35.  
  36. def checkerFill1(strip, color, wait_ms=10):
  37.     for i in range (LED_COUNT):
  38.  
  39.         even_fill_color = Color(0, 0, 0) if getRow(i) % 2 == 0 else color
  40.  
  41.         odd_fill_color = Color(0, 0, 0) if even_fill_color == color else color
  42.  
  43.         if (i % 2 == 0):
  44.             strip.setPixelColor(i, even_fill_color)
  45.         else:
  46.             strip.setPixelColor(i, odd_fill_color)
  47.         strip.show()
  48.     time.sleep(wait_ms / 1000.0)
  49.  
  50. def checkerFill2(strip, color, wait_ms=10):
  51.     for i in range (LED_COUNT):
  52.  
  53.         odd_fill_color = Color(0, 0, 0) if getRow(i) % 2 == 0 else color
  54.  
  55.         even_fill_color = Color(0, 0, 0) if odd_fill_color == color else color
  56.  
  57.         if (i % 2 == 0):
  58.             strip.setPixelColor(i, even_fill_color)
  59.         else:
  60.             strip.setPixelColor(i, odd_fill_color)
  61.         strip.show()
  62.  
  63. iterations = 0
  64. def diagonal(strip, color, wait_ms=10):
  65.     global iterations
  66.     for i in range(LED_COUNT):
  67.         if getRow(i) == getColumn(i):
  68.             c = COLOR_1 if color != Color(0, 0, 0) else Color(0, 0, 0)
  69.             strip.setPixelColor(i + iterations, c)
  70.         else:
  71.             c = COLOR_1 if color == Color(0, 0, 0) else Color(0, 0, 0)
  72.             strip.setPixelColor(i + iterations, c)
  73.         strip.show()
  74.    
  75.     iterations += 1
  76.     time.sleep(10 / 1000.0)
  77.  
  78. if __name__ == "__main__":
  79.     strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, 800000, 10, False, 10, 0)
  80.     strip.begin()
  81.  
  82.    
  83.     while True:
  84.         checkerFill1(strip, COLOR_1)
  85.         time.sleep(5 / 1000)
  86.         checkerFill2(strip, COLOR_1)
  87.         time.sleep(5 / 1000)
RAW Paste Data