Skip to content

Instantly share code, notes, and snippets.

@SebastianGaud
Last active October 12, 2017 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SebastianGaud/dc1cbc644b70d31d9e0cfb96df31a151 to your computer and use it in GitHub Desktop.
Save SebastianGaud/dc1cbc644b70d31d9e0cfb96df31a151 to your computer and use it in GitHub Desktop.
# This file has been written to your home directory for convenience. It is
# saved as "/home/pi/temperature-2017-10-12-13-53-36.py"
import time
import threading
import csv
import datetime
from sense_emu import SenseHat
brake = 1
sense = SenseHat()
def wait_n_read(brake, worker, iterations=0):
if iterations != 1:
threading.Timer(brake, wait_n_read, [brake, worker, 0 if iterations == 0 else iterations - 1]).start()
worker(iterations)
def write_csv_file(temp):
dt = datetime.datetime.now()
humidity = sense.humidity
pressure = sense.get_pressure()
with open('data.csv', 'a') as csvfile:
writer = csv.writer(csvfile, delimiter=',')
writer.writerow([temp, humidity,pressure, build_readble_date(dt)])
def build_readble_date(dt):
return str(dt.year)+"-"+str(dt.month)+"-"+str(dt.day)+"T" + str(dt.hour)+":"+str(dt.minute)+":"+str(dt.second)
def read(iterations):
print('read' + str(iterations))
red = (255, 0, 0)
blue = (0, 0, 255)
temp = sense.temp
write_csv_file(temp)
pixels = [red if i < temp else blue for i in range(64)]
sense.set_pixels(pixels)
wait_n_read(brake, read, 100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment