def main(): sense = SenseHat() """ sense.show_message("Hello World!!"); sense.set_rotation(180) sense.show_message("Hello World!!"); """ sense.flip_v() list = sense.get_pixels() #print list sense.set_pixel(0,0,255,0,0) sense.clear() for i in range(0, 5): sense.show_letter(str(i)) time.sleep(1) sense.clear()
def random_color(): random_red = randint(0, 255) random_green = randint(0, 255) random_blue = randint(0, 255) return (random_red, random_green, random_blue) def spain_flag(): pixels = [ red, red, red, green, red, red, red, red, red, red, red, red, red, red, red, red, yellow, yellow, yellow, yellow, yellow, yellow, yellow, yellow, yellow, yellow, yellow, yellow, yellow, yellow, yellow, yellow, yellow, yellow, yellow, yellow, yellow, yellow, yellow, blue, yellow, yellow, yellow, yellow, yellow, yellow, yellow, yellow, red, red, red, red, red, red, red, red, red, red, red, red, red, red, red, red ] sense.set_pixels(pixels) return spain_flag() sleep(1) sense.flip_h() sleep(1) sense.flip_v() sleep(1) sense.set_rotation(90) sleep(1) sense.clear()
g, b, g, r, r, g, r, g, r, b, r, g, r, r, g, g, r, r, g, g, r, ] sense.set_pixels(image) v = 0 while v < 4: time.sleep(1) v = v + 1 sense.flip_v() sense.clear(255, 0, 0)
class senseHAT: def __init__(self): self.sense = SenseHat() self.red = (255, 0 , 0) self.green = (0, 255, 0) self.blue = (0, 0, 255) self.lightGreen = (70, 255, 102) self.black = (0, 0, 0) self.white = (255, 255, 255) # Display a message using user input with orange text & black background def displayText(self): textColor = (253, 95, 0) message = input('Enter a message to display: ') self.sense.show_message(message, text_colour = textColor, back_colour = self.black) # Given any word, this method will display each char every x seconds in red def displayChars(self, word, x): for letter in word: self.sense.show_letter(letter, text_colour = self.red) sleep(x) # Lights the entire board light green def makeOneColor(self): self.sense.clear(self.lightGreen) # Makes a happy face by setting individual pixels def onePixel(self): self.sense.set_pixel(2, 2, self.blue) self.sense.set_pixel(4, 2, self.blue) self.sense.set_pixel(3, 4, self.lightGreen) self.sense.set_pixel(1, 5, self.red) self.sense.set_pixel(2, 6, self.red) self.sense.set_pixel(3, 6, self.red) self.sense.set_pixel(4, 6, self.red) self.sense.set_pixel(5, 5, self.red) # Lights up entire LED Board based on list def manyPixels(self): matrix = [] # Appends black or white into matrix based on number value while len(matrix) < 64: randNum = randint(0, 1) if randNum == 0: matrix.append(self.black) matrix.append(self.white) self.sense.set_pixels(matrix) # Given an orientation, LED Matrix will either be flipped horizontally, vertically, or rotated def setOrientation(self, option): w = (150, 150, 150) e = self.white b = self.blue option = option.lower() image = [ e,e,e,e,e,e,e,e, e,e,e,e,e,e,e,e, w,w,w,e,e,w,w,w, w,w,b,e,e,w,w,b, w,w,w,e,e,w,w,w, e,e,e,e,e,e,e,e, e,e,e,e,e,e,e,e, e,e,e,e,e,e,e,e ] if option == 'horizontal': self.sense.flip_h(image) elif option == 'vertical': self.sense.flip_v(image) elif option == 'rotate': rotation = int(input('Enter degrees to rotate: ')) self.sense.set_rotation(rotation) else: self.sense.set_pixels(image) # Output environment details to LED Matrix def getEnvironment(self): # get_temperature() returns celsius... convert this to farenheit temp = round(self.sense.get_temperature() * 1.8 + 32, 2) humidty = round(self.sense.get_humidity(), 2) pressure = round(self.sense.get_pressure(), 2) tempMessage = "Temperature: " + str(temp) + "F" humidtyMessage = "Humidity: " + str(humidty) + "%" pressureMessage = "Pressue: " + str(pressure) + "millibars" self.sense.show_message(tempMessage) sleep(1) self.sense.show_message(humidtyMessage) sleep(1) self.sense.show_message(pressureMessage) sleep(1) # Will water freeze right now? if temp <= 32: self.sense.show_message('Water will freeze at current temp') else: self.sense.show_message('Water will not freeze right now') # Detecting Movement using IMU def detectMovement(self): while True: acceleration = self.sense.get_accelerometer_raw() x = acceleration['x'] y = acceleration['y'] z = acceleration['z'] x = abs(x) y = abs(y) z = abs(z) if x > 1 or y > 1 or z > 1: self.sense.show_letter('!', self.red) else: self.sense.clear() # Using the joystick def joystick(self): choice = input( 'Enter the key of what you want to do: \n 1 - Show on terminal directions \n 2 - Show on LED Matrix \n ' ) if choice == '1': while True: for event in self.sense.stick.get_events(): print(event.direction, event.action) elif choice == '2': e = self.black w = self.white self.sense.clear() while True: for event in self.sense.stick.get_events(): if event.action == 'pressed': if event.direction == 'up': self.sense.show_letter('U') elif event.direction == 'down': self.sense.show_letter('D') elif event.direction == 'left': self.sense.show_letter('L') elif event.direction == 'right': self.sense.show_letter('R') elif event.direction == 'middle': self.sense.show_letter('M') sleep(0.5) self.sense.clear()
parser.add_argument( '--redraw', type=str2bool, nargs='?', default=True, help='Whether or not to redraw what is already being displayed on the LED matrix. Defaults to True' ) args = parser.parse_args() try: from sense_hat import SenseHat sense = SenseHat() result = sense.flip_v( args.redraw ) # A list containing 64 smaller lists of [R, G, B] pixels (red, green, blue) representing the flipped image. finish( { "result": result } ) except Exception, e: finish( e, 1 )
sys.exit() if key == "setRotation": if showDebug: print("[ledMatrixBridge] set rotation", payload["value"]) sense.set_rotation(payload["value"], True) if key == "flipH": if showDebug: print("[ledMatrixBridge] flip horizontal") sense.flip_h(True) if key == "flipV": if showDebug: print("[ledMatrixBridge] flip vertical") sense.flip_v(True) if key == "setPixels": if showDebug: print("[ledMatrixBridge] set pixels from array") sense.set_pixels(payload["value"]) if key == "getPixels": if showDebug: print("[ledMatrixBridge] flip vertical") print(sense.get_pixels()) if key == "setPixel": if showDebug: print("[ledMatrixBridge] set single pixel") sense.set_pixel(payload["x"], payload["y"], payload["r"],
# Astro Pi Submission for Matthew Charlston, Owen Cole and James Cook for Phase 2 of Mission Space Lab 2018 # Import libraries needed for experiment from sense_hat import SenseHat # For outputting to the hat import time # For timing and sleeping import logging # For logging from logzero import logger # For the csv output import logzero # For logging import os # For getting current directory import datetime # For getting the current time # Initiate Sense Hat sense = SenseHat() # Initiate sense.flip_v() # Flip the screen so it is visible to the astronauts sense.flip_h() # Continued # Set up libraries, timing, logging and variables numberOfPassings = 0 # Variable to store the number of times an astronaut has passed dirPath = os.path.dirname(os.path.realpath(__file__)) # Get current directory nowTime = datetime.datetime.now() # Get current time startTime = datetime.datetime.now() # Get start time logzero.logfile(dirPath + "/data01.csv") # Set file to output data to formatter = logging.Formatter( '%(name)s - %(asctime)-15s - %(levelname)s: %(message)s') # Create custom formatter logzero.formatter(formatter) # Use custom formatter # Loop for 170 minutes so the program is not terminated by the pi uncleanly while (nowTime < startTime + datetime.timedelta(minutes=17)): # Declare variables