def main(): #initialize Pygame which handles joystick inputs on SenseHat pygame.init() pygame.display.set_mode((640, 480)) subprocess.call(["mpc","clear"]) subprocess.call(["mpc","load","playlist1"]) subprocess.call(["mpc","enable","1"]) # SenseHat initialization and configuration sense = SenseHat() sense.low_light = True sense.rotation = 90 #initialize last weather update time last_update_time = 0 #Main loop while True: #Handle Senshat Joystick inputs for event in pygame.event.get(): #if event.type == KEYDOWN: #radio_commands(event) #print('DN') if event.type == KEYUP: radio_commands(event) print('SenseHat Input')
def start_climate_station(self, interval=60, nightly=False, rotation=0): """ :param interval: refresh rate of checking temperature :param nightly: dim the light if value is true :param rotation: rotate the Sense Hat LED to fit proper direction :return: no return value. Start the climate station in daemon mode. """ sense = SenseHat() # sense.clear() sense.rotation = rotation sense.low_light = nightly while True: self.clear_temp_row(sense) self.display_temp(sense) sleep(interval)
return minecraftOP anotherGo = True while anotherGo: choice = menu() if choice == 1: temp = sense.get_temperature() print("Temperature: %s C" % temp) elif choice == 2: degreesMenu() degrees = degreesMenu() if degrees == 1: sense.rotation = 90 degreesMenu() elif degrees == 2: sense.rotation = 180 degreesMenu() elif degrees == 3: sense.rotation = 270 degreesMenu() elif degrees == 4: menu() if choice == 3: minecraftMenu()
def ticker(): delta_t = time.time() - tick_launch ticker_x = f'{delta_t:.3f}:' debug_time = time.localtime(time.time()) ticker_x = str(ticker_x) + (" ") + str(time.asctime()) + (" ") return ticker_x sleeptime_l = 1.0 sleeptime_m = sleeptime_l / 2 sleeptime_s = sleeptime_l / 4 sleeptime_watchtick = 1 s = SenseHat() s.low_light = False s.rotation = 90 nightmode = False nightmodehours = [0, 1, 2, 3, 4, 5, 7, 9, 11, 13, 15, 17, 19, 21, 22, 23, 24] G = green = [0, 255, 0] g = green_low = [0, 100, 0] Y = yellow = [255, 255, 0] y = yellow_low = [100, 100, 0] B = blue = [0, 0, 255] b = blue_low = [0, 0, 100] R = red = [255, 0, 0] r = red_low = [100, 0, 0] W = white = [255, 255, 255] w = white_low = [100, 100, 100] O = nothing = [0, 0, 0]
from sense_hat import SenseHat from time import sleep import icon_mapper import os import sys sense = SenseHat() sense.clear() sense.rotation = 180 import json import requests try: forecast_key = os.environ['FORECAST_KEY'] except KeyError as e: print 'FORECAST_KEY not set' sys.exit(1) latitude = os.getenv('FORECAST_LATITUDE', 53.4667) longitude = os.getenv('FORECAST_LONGITUDE', -2.2333) url = 'https://api.darksky.net/forecast/%s/%s,%s' % (forecast_key, latitude, longitude) while True: response = requests.get(url) if(response.ok): jData = json.loads(response.content) current = jData['currently']['icon']
from sense_hat import SenseHat import time sense = SenseHat() sense.rotation = 90 from random import randint hello = ["Hello! We are New Media Development :)"] def repeat(): for i in hello: color = (randint(0, 255), randint(0, 255), randint(0, 255)) background_color = (randint(0, 50), randint(0, 50), randint(0, 50)) sense.show_message(i, text_colour=color, back_colour=background_color) time.sleep(1) repeat() repeat()
from sense_hat import SenseHat from random import random sense = SenseHat() sense.clear() sense.rotation = 180 def listToString(list): listToStr = ' '.join(map(str, list)) return listToStr def scrollIt(command): command.pop(0) msg = listToString(command) sense.clear() sense.show_message(msg, scroll_speed=0.075) return 'message sent' def getWeather(command): command.pop(0) t = round(sense.get_temperature_from_pressure(), 1) h = round(sense.get_humidity(), 1) p = round(sense.get_pressure(), 1) switch = { 'temperature': f'The temperature is {t}', 'humidity':
from sense_hat import SenseHat import time s = SenseHat() s.rotation = 180 s.low_light = True green = (0, 255, 0) yellow = (255, 255, 0) blue = (0, 0, 255) red = (255, 0, 0) white = (255, 255, 255) nothing = (0, 0, 0) pink = (255, 105, 180) def trinket_logo(): G = green Y = yellow B = blue O = nothing logo = [ O, O, O, O, O, O, O, O, O,
#!/usr/bin/python # Dormouse v1 by Mandrake Fernflower, 2016 # Free to use and modify - just leave this notice intact # Made for a RPI3 with a SenseHat import os import time from sense_hat import SenseHat sensebrd = SenseHat() sensebrd.low_light = True sensebrd.rotation = 180 def getCPUtemperature(): res = os.popen('vcgencmd measure_temp').readline() return (res.replace("temp=", "").replace("'C\n", "C")) while True: sensebrd.clear() sensebrd.show_message("CPU " + getCPUtemperature(), text_colour=[0, 148, 200]) time.sleep(8) etemp = round(sensebrd.get_temperature_from_humidity(), 1) sensebrd.show_message("EXT " + str(etemp) + "C", text_colour=[240, 230, 140]) time.sleep(8) rh = round(sensebrd.get_humidity(), 1) sensebrd.show_message("RH % " + str(rh), text_colour=[0, 110, 0])
def main(): sense = SenseHat() sense.low_light = True last_update_time = 0 sense.rotation = 90 SunPictos = [1,2,3,4,5,6,13,14,15] SunCloudPictos = [7,8,9,10,11,12,31,32] CloudPictos = [16,17,18,19,20,21,22,23] RainPictos = [23,25,33,35] SnowPictos = [24,26,29,34] StormPictos = [27,28,30] while True: # Fetch weather data every update period if time.time()-last_update_time > update_period*60: Weather = get_weather(url) last_update_time = time.time() Baro = get_press(AltitudeAboveSeaLevel) Humidity = sense.get_humidity() print('Current, Max, Min temp, Picto:',Weather.CurrentTemp,Weather.ForecastMaxTemp,Weather.ForecastMinTemp,Weather.Picto) print('Weather info updated at:', strftime("%a, %d %b %Y %H:%M:%S", localtime())) print('Local Pressure',Baro) # display Time & Weather info on SenseHat if ShowTime: sense.show_message('{} {}'.format('Heure:',strftime("%H:%M",localtime())),text_colour=(180,180,180)) if ShowTemperature: sense.show_message('{} {}{}'.format('T:', str(Weather.CurrentTemp),' '), text_colour=Weather.CurrentColor,scroll_speed=0.15) sense.show_message('{} {}'.format('Max:', str(Weather.ForecastMaxTemp)), text_colour=Weather.MaxColor,scroll_speed=0.15) sense.show_message('{} {}'.format('Min:', str(Weather.ForecastMinTemp)), text_colour=Weather.MinColor,scroll_speed=0.15) if ShowWeatherPicto: if Weather.Picto in SunPictos: for i in range (0,10): sense.load_image("/home/pi/SenseHat/WeatherMonitor/Images/soleil.png") time.sleep(0.3) sense.load_image("/home/pi/SenseHat/WeatherMonitor/Images/soleil2.png") time.sleep(0.3) elif Weather.Picto in SunCloudPictos: sense.load_image("/home/pi/SenseHat/WeatherMonitor/Images/soleil&nuage.png") time.sleep(5) elif Weather.Picto in CloudPictos: sense.load_image("/home/pi/SenseHat/WeatherMonitor/Images/nuage.png") time.sleep(5) elif Weather.Picto in RainPictos: sense.load_image("/home/pi/SenseHat/WeatherMonitor/Images/nuage&pluie.png") time.sleep(5) elif Weather.Picto in SnowPictos: sense.load_image("/home/pi/SenseHat/WeatherMonitor/Images/nuage&neige.png") time.sleep(5) elif Weather.Picto in StormPictos: sense.load_image("/home/pi/SenseHat/WeatherMonitor/Images/nuages&eclairs.png") time.sleep(5) if ShowPressure: sense.show_message('{} {}'.format(format(Baro, '.1f'),'hPa'), text_colour=Weather.CurrentColor,scroll_speed=0.15) #print(format(Baro, '.1f'),'hPa') if ShowHumidity: sense.show_message('{} {} {}'.format(format(Humidity, '.1f'),'%','Hum.'), text_colour=Weather.CurrentColor,scroll_speed=0.15) #print(format(Humidity, '.1f'),'%','Hum.') time.sleep(1)
def main(): #parameters last_update_time = 0 #Initialize Sense Hat sense = SenseHat() sense.low_light = True sense.rotation = 90 #Initialize Google Calendar credentials = get_credentials() http = credentials.authorize(httplib2.Http()) service = discovery.build('calendar', 'v3', http=http) # Main Loop while True: # Fetch weather & calendar data every update period if time.time()-last_update_time > update_period*60: Weather = get_weather(url) last_update_time = time.time() Baro = get_press(AltitudeAboveSeaLevel) Humidity = sense.get_humidity() print('Current, Max, Min temp:',Weather.CurrentTemp,Weather.ForecastMaxTemp,Weather.ForecastMinTemp) print('Weather info updated at:', strftime("%a, %d %b %Y %H:%M:%S", localtime())) print('Local Pressure',Baro) now = datetime.datetime.utcnow().isoformat() + 'Z' # 'Z' indicates UTC time print('Getting the upcoming 10 events') eventsResult = service.events().list( calendarId='primary', timeMin='2011-06-03T10:00:00-07:00', maxResults=2, singleEvents=True, orderBy='startTime').execute() events = eventsResult.get('items', []) print(events) if not events: print('No upcoming events found.') for event in events: start = event['start'].get('dateTime', event['start'].get('date')) print(start, event['summary']) # Fetch Calendar data # display Weather info on SenseHat for event in events: eventtime=dateutil.parser.parse(event['start'].get('dateTime')) print(eventtime.strftime('%I:%M')) sense.show_message(eventtime.strftime('%I:%M')) sense.show_message(event['summary']) # if ShowTemperature: # sense.show_message('{} {}{}'.format('T:', str(Weather.CurrentTemp),' '), text_colour=Weather.CurrentColor,scroll_speed=0.15) # sense.show_message('{} {}'.format('Max:', str(Weather.ForecastMaxTemp)), text_colour=Weather.MaxColor,scroll_speed=0.15) # sense.show_message('{} {}'.format('Min:', str(Weather.ForecastMinTemp)), text_colour=Weather.MinColor,scroll_speed=0.15) # if ShowTime: # sense.show_message('{} {}'.format('Heure:',strftime("%H:%M",localtime()))) # if ShowWeatherPicto: # if Weather.Picto > 0: # sense.load_image("Soleil.png") # time.sleep(3) # if ShowPressure: # sense.show_message('{} {}'.format(format(Baro, '.1f'),'hPa'), text_colour=Weather.CurrentColor,scroll_speed=0.15) # #print(format(Baro, '.1f'),'hPa') # if ShowHumidity: # sense.show_message('{} {} {}'.format(format(Humidity, '.1f'),'%','Hum.'), text_colour=Weather.CurrentColor,scroll_speed=0.15) # #print(format(Humidity, '.1f'),'%','Hum.') time.sleep(1)
[255, 255, 0], [255, 255, 0], [255, 255, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [255, 255, 0], [255, 255, 0], [255, 255, 0], [255, 255, 0], [0, 0, 0], [0, 0, 0], ] ] sh.rotation = 180 def show_frame(): for x in FRAMES: sh.set_pixels(x) time.sleep(0.5) def main(): try: while True: show_frame() except (KeyboardInterrupt, SystemExit): sys.exit()
def main(): #parameters last_update_time = 0 #Initialize Sense Hat sense = SenseHat() sense.low_light = True sense.rotation = 90 #Initialize Google Calendar credentials = get_credentials() http = credentials.authorize(httplib2.Http()) service = discovery.build('calendar', 'v3', http=http) # Main Loop while True: # Fetch weather & calendar data every update period if time.time() - last_update_time > update_period * 60: Weather = get_weather(url) last_update_time = time.time() Baro = get_press(AltitudeAboveSeaLevel) Humidity = sense.get_humidity() print('Current, Max, Min temp:', Weather.CurrentTemp, Weather.ForecastMaxTemp, Weather.ForecastMinTemp) print('Weather info updated at:', strftime("%a, %d %b %Y %H:%M:%S", localtime())) print('Local Pressure', Baro) now = datetime.datetime.utcnow().isoformat( ) + 'Z' # 'Z' indicates UTC time print('Getting the upcoming 10 events') eventsResult = service.events().list( calendarId='primary', timeMin='2011-06-03T10:00:00-07:00', maxResults=2, singleEvents=True, orderBy='startTime').execute() events = eventsResult.get('items', []) print(events) if not events: print('No upcoming events found.') for event in events: start = event['start'].get('dateTime', event['start'].get('date')) print(start, event['summary']) # Fetch Calendar data # display Weather info on SenseHat for event in events: eventtime = dateutil.parser.parse(event['start'].get('dateTime')) print(eventtime.strftime('%I:%M')) sense.show_message(eventtime.strftime('%I:%M')) sense.show_message(event['summary']) # if ShowTemperature: # sense.show_message('{} {}{}'.format('T:', str(Weather.CurrentTemp),' '), text_colour=Weather.CurrentColor,scroll_speed=0.15) # sense.show_message('{} {}'.format('Max:', str(Weather.ForecastMaxTemp)), text_colour=Weather.MaxColor,scroll_speed=0.15) # sense.show_message('{} {}'.format('Min:', str(Weather.ForecastMinTemp)), text_colour=Weather.MinColor,scroll_speed=0.15) # if ShowTime: # sense.show_message('{} {}'.format('Heure:',strftime("%H:%M",localtime()))) # if ShowWeatherPicto: # if Weather.Picto > 0: # sense.load_image("Soleil.png") # time.sleep(3) # if ShowPressure: # sense.show_message('{} {}'.format(format(Baro, '.1f'),'hPa'), text_colour=Weather.CurrentColor,scroll_speed=0.15) # #print(format(Baro, '.1f'),'hPa') # if ShowHumidity: # sense.show_message('{} {} {}'.format(format(Humidity, '.1f'),'%','Hum.'), text_colour=Weather.CurrentColor,scroll_speed=0.15) # #print(format(Humidity, '.1f'),'%','Hum.') time.sleep(1)
#!/usr/bin/env python #coding=utf-8 #http://framboise-pi.fr from sense_hat import SenseHat from sensehat_pictures import * import MPMM_config import random from random import randint sense = SenseHat() sense.rotation = MPMM_config.sensehat_rotation sense.low_light = True # seconds to display LED draw display = 3 # seconds to leave blank between blank = 10 def Welcome(): sense.show_message(MPMM_config.sensehat_welcome, text_colour=[255, 0, 0]) def Blank(): sense.clear() def Randomize(): dice = random.randint(0,5) if dice == 0: sense.set_pixels(monstre_01); if dice == 1: sense.set_pixels(monstre_02); if dice == 2: if dice == 3: if dice == 4:
# et coucher du soleil a Rome. import ephem # l'idee d'utilisation de la librairie PyEphem pour le calcul # de la position de l'ISS vient du code "ISS_Tracker" de la Thirsk School # (www.thirskschool.org), lors de leur contribution au Challenge AstroPi 2015. # Voir https://github.com/astro-pi/iss-tracker import animations # fichier local contenant toutes les animations realisees par # l'autre partie de la classe s = SenseHat() s.low_light = True s.rotation = 270 f=open('data_FM.csv','a') f.write('timestamp,humidite,accX,accY,accZ,latitude,longitude,commentaire \n') f.close() with open('rome.csv') as csvfile: liste=csv.DictReader(csvfile) for ligne in liste: if ligne['date']==time.strftime("%Y-%m-%d"): Hlever=ligne['sunrise'] Hcoucher=ligne['sunset']
import random from picamera import PiCamera from twython import Twython #CONSUMER_KEY = #CONSUMER_SECRET = #ACCESS_KEY = #ACCESS_SECRET = in your code put the twitter codes here (without the comments). I keep them elsewhere for safe keeping though ;) from secretCodes import * twitter = Twython(CONSUMER_KEY,CONSUMER_SECRET,ACCESS_KEY,ACCESS_SECRET) sense = SenseHat() #This will make the image the correct way up when the camera ribbon is towards the USBs sense.rotation = 270; Y = [random.randint(50,255),random.randint(50,255),random.randint(50,255)] N = [0,0,0] happy = [ N,N,N,N,N,N,N,N, N,Y,Y,N,N,Y,Y,N, N,Y,Y,N,N,Y,Y,N, N,N,N,N,N,N,N,N, N,N,N,N,N,N,N,N, N,Y,N,N,N,N,Y,N, N,Y,Y,Y,Y,Y,Y,N, N,N,N,N,N,N,N,N ]
def main(): sense = SenseHat() sense.low_light = True last_update_time = 0 sense.rotation = 90 SunPictos = [1, 2, 3, 4, 5, 6, 13, 14, 15] SunCloudPictos = [7, 8, 9, 10, 11, 12, 31, 32] CloudPictos = [16, 17, 18, 19, 20, 21, 22, 23] RainPictos = [23, 25, 33, 35] SnowPictos = [24, 26, 29, 34] StormPictos = [27, 28, 30] while True: # Fetch weather data every update period if time.time() - last_update_time > update_period * 60: Weather = get_weather(url) last_update_time = time.time() Baro = get_press(AltitudeAboveSeaLevel) Humidity = sense.get_humidity() print('Current, Max, Min temp, Picto:', Weather.CurrentTemp, Weather.ForecastMaxTemp, Weather.ForecastMinTemp, Weather.Picto) print('Weather info updated at:', strftime("%a, %d %b %Y %H:%M:%S", localtime())) print('Local Pressure', Baro) # display Time & Weather info on SenseHat if ShowTime: sense.show_message('{} {}'.format('Heure:', strftime("%H:%M", localtime())), text_colour=(180, 180, 180)) if ShowTemperature: sense.show_message('{} {}{}'.format('T:', str(Weather.CurrentTemp), ' '), text_colour=Weather.CurrentColor, scroll_speed=0.15) sense.show_message('{} {}'.format('Max:', str(Weather.ForecastMaxTemp)), text_colour=Weather.MaxColor, scroll_speed=0.15) sense.show_message('{} {}'.format('Min:', str(Weather.ForecastMinTemp)), text_colour=Weather.MinColor, scroll_speed=0.15) if ShowWeatherPicto: if Weather.Picto in SunPictos: for i in range(0, 10): sense.load_image( "/home/pi/SenseHat/WeatherMonitor/Images/soleil.png") time.sleep(0.3) sense.load_image( "/home/pi/SenseHat/WeatherMonitor/Images/soleil2.png") time.sleep(0.3) elif Weather.Picto in SunCloudPictos: sense.load_image( "/home/pi/SenseHat/WeatherMonitor/Images/soleil&nuage.png") time.sleep(5) elif Weather.Picto in CloudPictos: sense.load_image( "/home/pi/SenseHat/WeatherMonitor/Images/nuage.png") time.sleep(5) elif Weather.Picto in RainPictos: sense.load_image( "/home/pi/SenseHat/WeatherMonitor/Images/nuage&pluie.png") time.sleep(5) elif Weather.Picto in SnowPictos: sense.load_image( "/home/pi/SenseHat/WeatherMonitor/Images/nuage&neige.png") time.sleep(5) elif Weather.Picto in StormPictos: sense.load_image( "/home/pi/SenseHat/WeatherMonitor/Images/nuages&eclairs.png" ) time.sleep(5) if ShowPressure: sense.show_message('{} {}'.format(format(Baro, '.1f'), 'hPa'), text_colour=Weather.CurrentColor, scroll_speed=0.15) #print(format(Baro, '.1f'),'hPa') if ShowHumidity: sense.show_message('{} {} {}'.format(format(Humidity, '.1f'), '%', 'Hum.'), text_colour=Weather.CurrentColor, scroll_speed=0.15) #print(format(Humidity, '.1f'),'%','Hum.') time.sleep(1)
from sense_hat import SenseHat from time import sleep sense = SenseHat() sense.set_imu_config(True, True, True) sense.rotation = 270 while True: try: temp = sense.get_temperature_from_humidity() humidity = sense.get_humidity() print("Humidity: %s %%rH" % humidity) # orientation = sense.get_orientation_degrees() # print("p: {pitch}, r: {roll}, y: {yaw}".format(**orientation)) # print(sense.accelerometer_raw) # print(sense.gyroscope_raw) # print(sense.compass_raw) sense.show_message(str(round(temp, 2)), text_colour=[0, 255, 224]) # sleep() except KeyboardInterrupt: sense.clear() break