Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sense_hat import SenseHat
- import time
- sense = SenseHat()
- # Functions
- def Message(data, i):
- if i == -1:
- if data == 0:
- sense.show_message("Crew member detected", scroll_speed = 0.066)
- sense.set_pixels([
- e,e,e,e,e,e,e,e,
- e,w,w,e,e,w,w,e,
- e,w,w,e,e,w,w,e,
- e,e,e,e,e,e,e,e,
- e,w,e,e,e,e,w,e,
- e,w,e,e,e,e,w,e,
- e,w,w,w,w,w,w,e,
- e,e,e,e,e,e,e,e ])
- else:
- string = ["temperature", "humidity", "pressure"]
- if (data == 0):
- sense.show_message("no_variation_in: " + string[i])
- if (data == 1):
- sense.show_message("variation_at: +/-52 -- -/+52; in: " + string[i])
- if (data == 2):
- sense.show_message("variation_at: +/-52 -- 0; in: " + string[i])
- if (data == 3):
- sense.show_message("variation_at: +/-52 -- 0 -- -/+52; in: " + string[i])
- def LoadingTime(number_of_times):
- sense.clear()
- for x in range(number_of_times):
- n = 1
- while n < 16:
- for i in range(n):
- for j in range(n):
- if i + j == n - 1 and i < 8 and j < 8:
- sense.set_pixel(i, j, image[2][i + j * 8][0], image[2][i + j * 8][1], image[2][i + j * 8][2])
- time.sleep(0.5)
- n += 1
- n = 1
- while n < 16:
- for i in range(n):
- for j in range(n):
- if i + j == n - 1 and i < 8 and j < 8:
- sense.set_pixel(i, j, e)
- time.sleep(0.5)
- n += 1
- # Startup
- r = [255,0,0]
- o = [255,127,0]
- y = [255,255,0]
- g = [0,127,0]
- b = [0,0,255]
- m = [75,0,130]
- v = [159,0,255]
- w = [255,255,255]
- e = [0,0,0]
- colours = [r, o, o, y, y, y, g, g]
- image = [
- [ g,g,g,g,g,g,g,g,
- g,g,g,g,g,g,g,g,
- g,g,g,g,g,g,g,g,
- g,g,g,g,g,g,g,g,
- g,g,g,g,g,g,g,g,
- g,g,g,g,g,g,g,g,
- g,g,g,g,g,g,g,g,
- g,g,g,g,g,g,g,g ],
- [ r,r,r,r,r,r,r,r,
- r,r,r,r,r,r,r,r,
- r,r,r,r,r,r,r,r,
- r,r,r,r,r,r,r,r,
- r,r,r,r,r,r,r,r,
- r,r,r,r,r,r,r,r,
- r,r,r,r,r,r,r,r,
- r,r,r,r,r,r,r,r ],
- [ [255, 0, 0], [255, 0, 0], [255, 87, 0], [255, 196, 0], [205, 255, 0], [95, 255, 0], [0, 255, 13], [0, 255, 122],
- [255, 0, 0], [255, 96, 0], [255, 205, 0], [196, 255, 0], [87, 255, 0], [0, 255, 22], [0, 255, 131], [0, 255, 240],
- [255, 105, 0], [255, 214, 0], [187, 255, 0], [78, 255, 0], [0, 255, 30], [0, 255, 140], [0, 255, 248], [0, 152, 255],
- [255, 223, 0], [178, 255, 0], [70, 255, 0], [0, 255, 40], [0, 255, 148], [0, 253, 255], [0, 144, 255], [0, 34, 255],
- [170, 255, 0], [61, 255, 0], [0, 255, 48], [0, 255, 157], [0, 243, 255], [0, 134, 255], [0, 26, 255], [83, 0, 255],
- [52, 255, 0], [0, 255, 57], [0, 255, 166], [0, 235, 255], [0, 126, 255], [0, 17, 255], [92, 0, 255], [201, 0, 255],
- [0, 255, 66], [0, 255, 174], [0, 226, 255], [0, 117, 255], [0, 8, 255], [100, 0, 255], [210, 0, 255], [255, 0, 192],
- [0, 255, 183], [0, 217, 255], [0, 109, 255], [0, 0, 255], [110, 0, 255], [218, 0, 255], [255, 0, 183], [255, 0, 74]
- ]]
- # Initialisation
- # Tables
- # Register of 180 elements (each element corresponds to a minute, as the total time will be of 180 minutes)
- register = [
- [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,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,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],[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,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,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],[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,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,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]
- ]
- # List of the values when the ISS is at +52(North), 0(Equator), -52(South)
- list_of_critical_points = [
- [0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0]
- ]
- # Variables
- # Mission 1
- baseline_humidity = [0.0, 0.0]
- number_of_detections = 0
- # Mission 2
- mag = sense.get_compass_raw()
- min = mag['x']
- time_keeper = 0
- check_for_starting_position = 0
- first_critical_point = False
- index = 0
- start_point = 0
- end_of_critical_list = 0
- while time_keeper < 85:
- # Baseline Establishment
- sense.clear()
- baseline_humidity[0] = baseline_humidity[1]
- presence = False
- baseline_accel = [0.0, 0.0, 0.0]
- for j in range(8):
- for i in range(8):
- baseline_humidity[1] = baseline_humidity[1] + sense.get_humidity()
- acc = sense.get_accelerometer_raw()
- baseline_accel[0] = baseline_accel[0] + acc['x']
- baseline_accel[1] = baseline_accel[1] + acc['y']
- baseline_accel[2] = baseline_accel[2] + acc['z']
- sense.set_pixel(i,j,colours[j])
- time.sleep(.9375)
- baseline_humidity[1] /= 64
- for k in range(3):
- baseline_accel[k] /= 64
- if baseline_humidity[0] == 0:
- baseline_humidity[0] = baseline_humidity[1]
- # Crew detector
- ok = 0
- while presence == False:
- sense.clear()
- acc = sense.get_accelerometer_raw()
- max = [acc['x'], acc['y'], acc['z']]
- for i in range(8):
- for j in range(8):
- acc = sense.get_accelerometer_raw()
- if max[0] < acc['x']:
- max[0] = acc['x']
- if max[1] < acc['y']:
- max[2] = acc['y']
- if max[2] < acc['z']:
- max[2] = acc['z']
- sense.set_pixel(i,j,w)
- time.sleep(1.25)
- h = sense.get_humidity()
- variationOfH1 = h - baseline_humidity[1]
- variationOfH2 = baseline_humidity[1] - baseline_humidity[0]
- variationOfA = False
- if max[0] - baseline_accel[0] > 0.0006 or max[0] - baseline_accel[0] < -0.0006 or max[1] - baseline_accel[1] > 0.005 or max[1] - baseline_accel[1] < -0.005 or max[2] - baseline_accel[2] > 0.0005 or max[2] - baseline_accel[2] < -0.0005:
- variationOfA = True
- if variationOfH1 > 0.04 * baseline_humidity[1] or variationOfH2 > variationOfH1 * 0.04 or variationOfA == True:
- presence = True
- else:
- presence = False
- if presence == True:
- sense.clear()
- sense.set_pixels(image[0])
- time.sleep(3)
- Message(0, -1)
- ok = ok + 2
- time.sleep(2)
- else:
- sense.set_pixels(image[1])
- time.sleep(3)
- ok = ok + 1
- if ok >= 3:
- presence = True
- sense.clear()
- time.sleep(2)
- # Time Waiter (for 2 minutes completition)
- if ok != 4:
- LoadingTime(4 - ok)
- # Mission 2
- # Determining the "point" where the ISS passes through the Equator(0): {+52} -> {0} -> {-52}
- if first_critical_point == False:
- mag = sense.get_compass_raw()
- x = mag['x']
- register[index][0] = sense.get_temperature()
- register[index][1] = sense.get_humidity()
- register[index][2] = sense.get_pressure()
- if min > x:
- min = x
- else:
- first_critical_point = True
- # Determining the earliest registration of either one of the Poles or the Equator
- if first_critical_point == True:
- start_point = index
- while start_point - 23 > 0:
- start_point -= 23
- check += 1
- index += 1
- else:
- # Registration
- if index < 180:
- register[index][0] = sense.get_temperature()
- register[index][1] = sense.get_humidity()
- register[index][2] = sense.get_pressure()
- index += 1
- time_keeper += 1
- # The final steps
- # Assigning the found values to {list_of _critical_points}, as well as determining the end
- while start_point + 23 < 180:
- list_of_critical_points[end_of_critical_list][0] = register[start_point][0]
- list_of_critical_points[end_of_critical_list][1] = register[start_point][1]
- list_of_critical_points[end_of_critical_list][2] = register[start_point][2]
- start_point += 23
- end_of_critical_list += 1
- # Mean Calculation
- mean1 = [0, 0, 0]
- meanE = [0, 0, 0]
- mean2 = [0, 0, 0]
- # The value of {check_for_starting_position} will determine which point will the ISS pass the earliest (Poles or Equator)
- # If the list starts at one of the Poles (either +52(North) or -52(South))
- if check_for_starting_position == 3 or check_for_starting_position == 1:
- # Mean value for +52(North) or -52(South)
- counter = 0
- i = 0
- while i < end_of_critical_list:
- for j in range(3):
- mean1[j] += list_of_critical_points[i][j]
- counter += 1
- i += 4
- for j in range(3):
- mean1[j] /= counter
- # Mean value for -52(South) or +52(North)
- counter = 0
- i = 2
- while i < end_of_critical_list:
- for j in range(3):
- mean2[j] += list_of_critical_points[i][j]
- counter += 1
- i += 4
- for j in range(3):
- mean2[j] /= counter
- # Mean value for 0(Equator)
- counter = 0
- i = 1
- while i < end_of_critical_list:
- for j in range(3):
- meanE[j] += list_of_critical_points[i][j]
- counter += 1
- i += 2
- for j in range(3):
- meanE[j] /= counter
- # If the list starts at 0(Equator)
- else:
- # Mean value for +52(North) or -52(South)
- counter = 0
- i = 1
- while i < end_of_critical_list:
- for j in range(3):
- mean1[j] += list_of_critical_points[i][j]
- counter += 1
- i += 4
- for j in range(3):
- mean1[j] /= counter
- # Mean value for -52(South) or +52(North)
- counter = 0
- i = 3
- while i < end_of_critical_list:
- for j in range(3):
- mean2[j] += list_of_critical_points[i][j]
- counter += 1
- i += 4
- for j in range(3):
- mean2[j] /= counter
- # Mean value for 0(Equator)
- counter = 0
- i = 0
- while i < end_of_critical_list:
- for j in range(3):
- meanE[j] += list_of_critical_points[i][j]
- counter += 1
- i += 2
- for j in range(3):
- meanE[j] /= counter
- # Values of {varies_between}: 0 - (no_variation), 1 - (+52/-52 -- -52/+52), 2 - (+52/-52 -- 0), 3 - (+52/-52 -- 0 -- -52/+52)
- varies_between = [0, 0, 0]
- for i in range(3):
- if mean1[i] - mean2[i] > 5.0 or mean1[i] - mean2[i] < -5.0:
- varies_between[i] = 1
- if mean1[i] - meanE[i] > 5.0 or mean1[i] - meanE[i] < -5.0 or mean2[i] - meanE[i] > 5.0 or mean2[i] - meanE[i] < -5.0:
- varies_between[i] = 3
- if mean1[i] - meanE[i] > 5.0 or mean1[i] - meanE[i] < -5.0 or mean2[i] - meanE[i] > 5.0 or mean2[i] - meanE[i] < -5.0:
- varies_between[i] = 2
- # Main Conclusion (Message)
- sense.show_message("The conclusions of this experiments will be shown 3(three) times")
- for j in range(3):
- for i in range(3):
- sense.show_message("Conclusions of Mission 1: ")
- sense.show_message("The Astro Pi has detected the presence of an astro-thing {x} time(s)!".format(number_of_detections))
- time.sleep(1)
- sense.show_message("Conclusions of Mission 2: ")
- Message(varies_between[i], i)
- time.sleep(2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement