#!/usr/bin/env python import alsaaudio as aa import smbus from struct import unpack import numpy as np import wave import time import math from Adafruit_8x8 import ColorEightByEight grid = ColorEightByEight(address=0x70) # Initialise matrix grid.clear() matrix = [0,0,0,0,0,0,0,0] frequencyRange = [] scaling = [2,2,2,2,2,2,2,2] # Set up audio # Open the wave file wavfile = wave.open('/home/pi/Beethoven_Symphony_n.wav','r') # We are going to use the frame rate from the file as a # sample rate in our output sampleRate = wavfile.getframerate() # Set the frame size - advisable to be multiple of 8 frameSize = 2048
class LED_Matrix: #Variables for converting Pixel Colors ColorInt_To_String = ["Blank", "Green", "Red", "Yellow"] ColorString_To_Int = {"Blank": 0, "Green": 1, "Red": 2, "Yellow": 3} #These are used for easy use throughout the code for specific colors Blank_Pixel = 0 Green_Pixel = 1 Red_Pixel = 2 Yellow_Pixel = 3 #We need to track the state of each Grid LED. Grid_State = [[0 for Column in range(8)] for Row in range(8)] Pixel_Refresh_Rate = 0.0001 #Reference locations # x,y | References for Grid #---------------- # 0,0 = TOP RIGHT # 7,0 = TOP LEFT # 0,7 = BOTTOM RIGHT # 7,7 = BOTTOM LEFT #Construction function that is ran when class is initiated. #Here we initiate the Adafruit8x8 API def __init__(self): self.Grid = ColorEightByEight(address=0x70) #self.Connection = Database.connect('localhost', 'root', 'cool', 'gamedb') #=========================================== #General Use Functions that return a value== #=========================================== def get_Random_ColorString(self, boolean_Inc_Blank=True): if boolean_Inc_Blank is True: return LED_Matrix.ColorInt_To_String[randrange(0, 4)] else: return LED_Matrix.ColorInt_To_String[randrange(1, 3)] def get_Buffer_Value(self, i): return self.Grid.getBufferValue(i) def get_Random_ColorInt(self, boolean_Inc_Blank=True): if boolean_Inc_Blank is True: return randrange(0, 4) else: return randrange(1, 3) def get_Current_XY_Color(self, x, y): return LED_Matrix.ColorInt_To_String[LED_Matrix.Grid_State[x][y]] #=========================================== #End of General Use Functions=============== #=========================================== #=========================================== #Drawing Functions #=========================================== def draw_4px_Square(self, Bottom_Left_X, Bottom_Left_Y, string_Pixel_Color="Blank"): self.set_Pixel(Bottom_Left_X, Bottom_Left_Y, string_Pixel_Color) self.set_Pixel(Bottom_Left_X, Bottom_Left_Y-1, string_Pixel_Color) self.set_Pixel(Bottom_Left_X-1, Bottom_Left_Y-1, string_Pixel_Color) self.set_Pixel(Bottom_Left_X-1, Bottom_Left_Y, string_Pixel_Color) def draw_Row_Line(self, row_number, string_Row_Color="Blank"): y = 0 Random = False if(string_Row_Color=="Rainbow"): Random = True while(y < 8): if(Random==True): string_Row_Color = self.get_Random_ColorString(False) self.set_Pixel(row_number, y, string_Row_Color) y = y + 1 time.sleep(LED_Matrix.Pixel_Refresh_Rate) def draw_Column_Line(self, column_number, string_Column_Color="Blank"): x = 0 Random = False if(string_Column_Color=="Rainbow"): Random = True while(x < 8): if(Random==True): string_Column_Color = self.get_Random_ColorString(False) self.set_Pixel(x, column_number, string_Column_Color) x = x + 1 time.sleep(LED_Matrix.Pixel_Refresh_Rate) #=========================================== #End of Drawning Functions================== #=========================================== #=========================================== #I/O Functions #=========================================== def write_FlatFile(self): Config = ConfigParser.ConfigParser() with open ('Grid_Status.ini', 'w') as FlatFile: Config.read('Grid_Status') Config.add_section('Grid_Status') for x in range(0, 8): for y in range(0, 8): Config.set("Grid_Status", str(x) + "," + str(y), self.get_Current_XY_Color(x, y) ) Config.write(FlatFile) #=========================================== #End of I/O Functions======================= #=========================================== #=========================================== #Set Functions #=========================================== #Instant grid clear for prettier transitions. #We do it this way to bypass the pixel refresh interval. def set_Clear_Grid(self): self.Grid.clear() for x in range(0, 8): for y in range(0, 8): LED_Matrix.Grid_State[x][y] = 0 #Wrapper for setting a pixel so we can track it in our code and not need to reference the hardware. def set_Pixel(self, x, y, string_Pixel_Color="Blank"): int_Pixel_Color = LED_Matrix.ColorString_To_Int[string_Pixel_Color] #Here we update our instances's record of the grid screen LED_Matrix.Grid_State[x][y] = int_Pixel_Color #This is the function from our AdaFruit_8x8.py API self.Grid.setPixel(x, y, int_Pixel_Color) #If x and y are valid, update the database #//if (x >= 0 and y >= 0): #//self.write_FlatFile() #//self.set_Database_GridStatus_Update(x, y, int_Pixel_Color) #//thread.start_new_thread(self.set_Database_GridStatus_Update, (x, y, int_Pixel_Color)) #This function will display a color to every pixel of the matrix based on input string. #See Class Variables for acceptable input. Defaults to BLANK. def set_All_Pixels(self, string_Pixel_Color="Blank"): for x in range(0, 8): for y in range(0, 8): self.set_Pixel(x, y, string_Pixel_Color) time.sleep(LED_Matrix.Pixel_Refresh_Rate) def set_Random_Pixel(self, string_Pixel_Color="Blank"): x = randrange(0, 8) y = randrange(0, 8) self.set_Pixel(x, y, string_Pixel_Color) #Brightness is messured 0-15 def set_Matrix_Brightness(self, brightness): self.Grid.setBrightness(brightness) # Sets the displays Blink Rate, 0 = OFF , 1 = 2HZ , 2 = 1HZ , 3 = Half HZ def set_Matrix_BlinkRate(self, blinkRate): self.Grid.setBlinkRate(blinkRate) def set_Database_GridStatus_Update(self, x, y, int_Color): with self.Connection: Cursor = self.Connection.cursor() #SQL = "INSERT INTO Grid_Status(ID, Value) VALUES(%s, %s) ON DUPLICATE KEY UPDATE Value = %s" SQL = "UPDATE Grid_Status SET Value = %s WHERE ID = %s" DATA = ( str(int_Color), str(x) + "," + str(y), ) Cursor.execute(SQL, DATA) time.sleep(LED_Matrix.Pixel_Refresh_Rate)
from time import sleep # =========================================================================== # 8x8 Pixel Example # =========================================================================== InvaderBMPup = [ 0B00011000, 0B00111100, 0B01111110, 0B11011011, 0B00100100, 0B01011010, 0B10100101, 0B00000000 ] InvaderBMPdown = [ 0B00000000, 0B00011000, 0B00111100, 0B01111110, 0B11011011, 0B00100100, 0B01011010, 0B10100101 ] grid = ColorEightByEight(address=0x70) # Draw a bit map graphic def drawBitMap(bMap): for y in range(8): for x in range(8): if (bMap[y] & (2**x)): grid.setPixel(x, y, 1) # Draw the jumping invader print("The jumping Invader..") count = 20 pauseTime = 0.15 grid.clear()
os.system("export EPASS") USERNAME = os.environ["ENAME"] # just the part before the @ sign, add yours here PASSWORD = os.environ["EPASS"] NEWMAIL_OFFSET = 0 # my unread messages never goes to zero, yours might MAIL_CHECK_FREQ = 30 # check mail every 60 seconds # GPIO.setmode(GPIO.BCM) # GREEN_LED = 18 # RED_LED = 23 # GPIO.setup(GREEN_LED, GPIO.OUT) # GPIO.setup(RED_LED, GPIO.OUT) # =========================================================================== # 8x8 Pixel Example # =========================================================================== grid = ColorEightByEight(address=0x70) print "Press CTRL+Z to exit" smile_bmp = [0b00011110,0b00100001,0b11010010,0b11000000,0b11010010,0b11001100,0b00100001,0b00011110] neutral_bmp = [0b00011110,0b00100001,0b11010010,0b11000000,0b11011110,0b11000000,0b00100001,0b00011110] frown_bmp = [0b00011110,0b00100001,0b11010010,0b11000000,0b11001100,0b11010010,0b00100001,0b00011110] grid.setBrightness(15) while True: newmails = int(feedparser.parse("https://" + USERNAME + ":" + PASSWORD +"@mail.google.com/gmail/feed/atom")["feed"]["fullcount"]) if DEBUG: print "You have", newmails, "new emails!"
# .__ __ # |__| _____ ______ ____________/ |_ ______ # | |/ \\____ \ / _ \_ __ \ __\/ ___/ # | | Y Y \ |_> > <_> ) | \/| | \___ \ # |__|__|_| / __/ \____/|__| |__| /____ > # \/|__| \/ # #--------------------------------------------------- import time import datetime from Adafruit_8x8 import ColorEightByEight from collections import deque grid = ColorEightByEight(address=0x70) print "-----=-=-=-------=- bioreactor-one - montior-one -=---------=-=-=--------" print " .... testing .... pixels ... LEDS .................... " print "-------=---------=---------------------------------=-----------=----------" print "Press CTRL+Z to exit" print "--------------------------------------------------------------------------" iter = 0 #---------------------------------------------------------------------------- # test code from orig library, cycles through each led # #----------------------------------------------------------------------------
#!/usr/bin/python import time import datetime from Adafruit_8x8 import ColorEightByEight # =========================================================================== # 8x8 Pixel Example # =========================================================================== grid = ColorEightByEight(address=0x70) print "Press CTRL+Z to exit" iter = 0 # Continually update the 8x8 display one pixel at a time while(True): iter += 1 for x in range(0, 8): for y in range(0, 8): grid.setPixel(x, y, iter % 4 ) time.sleep(0.02)
import datetime # Enable debug output DEBUG = True # display buffer to represent the 8x8 LED matrix matrix = [ [0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0] ] grid = ColorEightByEight(address=0x70) # clear matrix for x in range(0, 8): for y in range(0, 8): grid.setPixel(x, y, 0) ADC.setup() # continually scroll the matrix and plot new ADC sample while(True): for x in range(7): for y in range(8): matrix[x][y] = matrix[x+1][y]
#!/usr/bin/python import sys import time import datetime sys.path.append( '/home/pi/python-code/Adafruit-Raspberry-Pi-Python-Code/Adafruit_LEDBackpack' ) from Adafruit_8x8 import ColorEightByEight board = [[0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]] grid = ColorEightByEight(address=0x70) iter = 0 while (True): iter = iter + 1 for i in range(0, 8): for j in range(0, 8): if (board[i][j]): grid.setPixel(i, j, i % 4) else: grid.clearPixel(i - 1, j - 1) neighbors = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]] for i in range(0, 8): for j in range(0, 8): for k in [-1, 0, 1]: for m in [-1, 0, 1]:
#!/usr/bin/python import time import datetime from Adafruit_8x8 import ColorEightByEight grid = ColorEightByEight(address=0x70) #smile_bmp = [0b00011110,0b00100001,0b11010010,0b11000000,0b11010010,0b11001100,0b00100001,0b00011110] neutral_bmp = [ 0b1000000, 0b0000000, 0b0100100, 0b0000000, 0b0000000, 0b0111100, 0b0000000, 0b0000000 ] frown_bmp = [ 0b1000000, 0b0000000, 0b0100100, 0b0000000, 0b0000000, 0b0111100, 0b1000010, 0b0000000 ] smile_bmp = [ 0b1000000, 0b0000000, 0b0100100, 0b0000000, 0b1000010, 0b1111110, 0b0000000, 0b0000000 ] while True: # Write a smiley face) for i in range(0, 8): grid.writeRowRaw(i, smile_bmp[i]) time.sleep(.33) # Write a neutral face for i in range(0, 8):
def get_time(): s = time.strftime("%I:%M") if(s[0] == '0'): s=s[1:] if(time.strftime('%p') == 'AM'): s=s+'A' else: s=s+'P' return s MATRICES = 3 matrix = [] color=2 info_matrix = ColorEightByEight(address=0x73) info_matrix.setTextWrap(False) # Allow text to run off edges info_matrix.setRotation(3) info_matrix.setBrightness(4) info_matrix.setTextSize(1) for i in range(0,MATRICES): matrix.append(ColorEightByEight(address=0x70+i)) matrix[i].setTextWrap(False) # Allow text to run off edges matrix[i].setRotation(3) matrix[i].setBrightness(4) matrix[i].setTextSize(1) #message = 'Hello World!!!' message = get_time()
#!/usr/bin/python import sys import time import datetime sys.path.append('/home/pi/python-code/Adafruit-Raspberry-Pi-Python-Code/Adafruit_LEDBackpack') from Adafruit_8x8 import ColorEightByEight board = [[0,1,0,0,0,0,0,0], [0,0,1,0,0,0,0,0], [1,1,1,0,0,0,0,0], [0,0,0,0,0,1,1,0], [0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0]] grid = ColorEightByEight(address=0x70) iter =0; while(True): iter=iter+1 for i in range(0,8): for j in range(0,8): if (board[i][j]): grid.setPixel(i, j, i%4) else: grid.clearPixel(i-1,j-1) neighbors = [[0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0],
#!/usr/bin/python import time import datetime import serial from Adafruit_8x8 import ColorEightByEight # must have pyserial install sudo apt-get install python # commands for LCD found here //https://www.parallax.com/sites/default/files/downloads/27979-Parallax-Serial-LCDs-Product-Guide-v3.1.pdf # =========================================================================== # 8x8 Pixel Example # =========================================================================== grid = ColorEightByEight(address=0x70, debug=True) grid.disp.setBlinkRate(2) serialport = serial.Serial("/dev/ttyAMA0", 9600, timeout=0.5) print "Press CTRL+Z to exit" iter = 0 serialport.write("\x11") serialport.write("\x0C") # Continually update the 8x8 display one pixel at a time while(True): iter += 1 for x in range(-1, 8): for y in range(1, 7): grid.setPixel(x, y, iter % 8 )
#--------------------------------------------------- # .__ __ # |__| _____ ______ ____________/ |_ ______ # | |/ \\____ \ / _ \_ __ \ __\/ ___/ # | | Y Y \ |_> > <_> ) | \/| | \___ \ # |__|__|_| / __/ \____/|__| |__| /____ > # \/|__| \/ # #--------------------------------------------------- import time import datetime from Adafruit_8x8 import ColorEightByEight from collections import deque grid = ColorEightByEight(address=0x70) print "-----=-=-=-------=- bioreactor-one - montior-one -=---------=-=-=--------" print " .... testing .... pixels ... LEDS .................... " print "-------=---------=---------------------------------=-----------=----------" print "Press CTRL+Z to exit" print "--------------------------------------------------------------------------" iter = 0 #---------------------------------------------------------------------------- # test code from orig library, cycles through each led # #---------------------------------------------------------------------------- # Continually update the 8x8 display one pixel at a time #while(True):
def __init__(self): self.Grid = ColorEightByEight(address=0x70)
# Blink rate __HT16K33_BLINKRATE_OFF = 0x00 __HT16K33_BLINKRATE_2HZ = 0x01 __HT16K33_BLINKRATE_1HZ = 0x02 __HT16K33_BLINKRATE_HALFHZ = 0x03 #Colors __HT16K33_OFF = 0 __HT16K33_GREEN = 1 __HT16K33_RED = 2 __HT16K33_YELLOW = 3 # setup backpack grid = ColorEightByEight(address=0x72) backpack = LEDBackpack(address=0x72) # command from RasPiConnect Execution Code def completeCommand(): f = open("/home/pi/MouseAir/state/MouseCommand.txt", "w") f.write("DONE") f.close() def processCommand(): f = open("/home/pi/MouseAir/state/MouseCommand.txt", "r")
m_bmp = [ 0B00000000, 0B00000000, 0B00000000, 0B00000000, 0B11101110, 0B10111010, 0B10010010, 0B10000010 ] am_bmp = [ 0B01110000, 0B10001010, 0B10001010, 0B01110100, 0B00110110, 0B01001001, 0B01001001, 0B01001001 ] pm_bmp = [ 0B01111100, 0B10000010, 0B11111100, 0B10000000, 0B00110110, 0B01001001, 0B01001001, 0B01001001 ] grid = ColorEightByEight(address=0x71) # Draw a bit map (BMP) graphic def drawBitMap(bMap): for y in range(8): for x in range(8): if (bMap[y] & (2**x)): grid.setPixel(x, y, 1) # Continually update the 8x8 display, one pixel at a time count = 0 iter = 0 while (count < 10):
# refer to https://github.com/adafruit/PyBBIO import Adafruit_BBIO.ADC as ADC import random import time import datetime # Enable debug output DEBUG = True # display buffer to represent the 8x8 LED matrix matrix = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]] grid = ColorEightByEight(address=0x70) # clear matrix for x in range(0, 8): for y in range(0, 8): grid.setPixel(x, y, 0) ADC.setup() # continually scroll the matrix and plot new ADC sample while (True): for x in range(7): for y in range(8): matrix[x][y] = matrix[x + 1][y]