Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sense_hat import SenseHat
- from time import sleep
- import time
- sense = SenseHat()
- def temp_h():
- th = sense.get_temperature_from_humidity()
- th = round(th, 1)
- th = str(th)
- loading(0)
- return th
- def temp_p():
- tp = sense.get_temperature_from_pressure()
- tp = round(tp, 1)
- tp = str(tp)
- return tp
- def humidity():
- h = int(sense.get_humidity())
- h = str(h)
- loading(1)
- return h
- def date():
- d = time.strftime("%Y-%m-%d; %H:%M:%S")
- loading(2)
- return d
- def pressure():
- p = int(sense.get_pressure())
- p = str(p)
- loading(3)
- return p
- def compass():
- M = sense.get_compass_raw()
- X = M['x']
- Y = M['y']
- Z = M['z']
- X = round(X, 0)
- Y = round(Y, 0)
- Z = round(Z, 0)
- loading(4)
- return "{}; {}; {}".format(X, Y, Z)
- def acceleration():
- acc = sense.get_accelerometer_raw()
- x = round(int(acc['x']), 8)
- y = round(int(acc['y']), 8)
- z = round(int(acc['z']), 8)
- loading(5)
- return "{}; {}; {}".format(x, y, z)
- def gyroscope():
- gyro_only = sense.get_gyroscope()
- p = round(gyro_only['pitch'], 8)
- r = round(gyro_only['roll'], 8)
- y = round(gyro_only['yaw'], 8)
- loading(6)
- return "{}; {}; {}".format(p,r,y)
- def loading(n):
- for i in range(8):
- sense.set_pixel(n,i, 250, 0, 0)
- with open( "team_data.csv" , "w" ) as f:
- row = "Date; Time; Temperature_hum; Temperature_pres; Humidity; Pressure; Acceleration X; Acceleration Y; Acceleration Z; Gyroscope P; Gyroscope R; Gyroscope Y; Magnetometer X; Magnetometer Y; Magnetometer Z\r\n"
- f.write(row)
- while True:
- row = "{}; {}; {}; {}; {}; {}; {}; {}\r\n".format(date(), temp_h(), temp_p(), humidity(), pressure(), acceleration(), gyroscope(), compass())
- with open( "team_data.csv" , "a" ) as f:
- f.write(row)
- loading(7)
- sleep(2)
- sense.clear()
- sleep(3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement