def senseStickService(): print 'Starting SenseHat Stick Service' STICK_MIDDLE = 28 stick = SenseStick() while True: if stick.wait(timeout=0.10) == True: # Get the input from the joystick stick_input = stick.read() direction = stick_input[1] state = stick_input[2] # 1 = pressed, 2 = held, 0 = released if (state == 0): # Only register if the joystick has been released if (direction == STICK_MIDDLE): # cycle the currentDisplayMode through the allDisplayModes array currentDisplayMode.value = allDisplayModes[(allDisplayModes.index(currentDisplayMode.value) + 1) % len(allDisplayModes)]
#camera.rotation = 180 #use this if the camera rotation is not correct camera.resolution = (3280, 2464) #this can be changed #starting the Sense Stick joystick = SenseStick() #opening the output files filestamp = localtime() delay = 1 #use this number to set the delay between camera captures in seconds pic_number = 1 #this is the starting number for taking pictures pic_dir = "/home/pi/Desktop/Pictures_" + repr(filestamp.tm_year) + '-' + repr( filestamp.tm_mon) + '-' + repr(filestamp.tm_mday) + '__' + repr( filestamp.tm_hour) + '-' + repr(filestamp.tm_min) if not os.path.isdir(pic_dir): os.makedirs(pic_dir) camera_check = True ## This is the main picture taking loop while camera_check: camera.capture(pic_dir + '/image%s.jpg' % pic_number) pic_number += 1 led_display.data_display('camera') joystick_press = joystick.wait(timeout=delay) if joystick_press: event = joystick.read() if event.state == joystick.STATE_PRESS: if event.key == joystick.KEY_ENTER: camera_check = False
data_filename = directory + repr(filestamp.tm_year) + '-' + repr( filestamp.tm_mon) + '-' + repr(filestamp.tm_mday) + '__' + repr( filestamp.tm_hour) + '-' + repr(filestamp.tm_min) + '_data.csv' f = open(data_filename, 'w') #################################################################### #################################################################### #################################################################### # MAIN LOOP while True: timestamp = time.time() data_record(timestamp) led_display.data_display('data') #checking if the center joystick has been pushed stick_press = stick.wait(timeout=0.01) if stick_press: event = stick.read() if event.state == stick.STATE_PRESS: if event.key == stick.KEY_ENTER: break #closing the data files f.close() #################################################################### #################################################################### #################################################################### # ALTITUDE REPORTING SCRIPT while True: start_alt_ft = (1 - (start_pressure / 1013.25)**0.190284) * 145366.45
#setting the resolution and framerate camera.resolution = (640, 480) camera.framerate = 90 #initializing additional variables filestamp = localtime() vid_dir = '/home/pi/Desktop/Videos/' if not os.path.isdir(vid_dir): os.makedirs(vid_dir) vid_name = 'Video_' + repr(filestamp.tm_year) + '-' + repr( filestamp.tm_mon) + '-' + repr(filestamp.tm_mday) + '__' + repr( filestamp.tm_hour) + '-' + repr(filestamp.tm_min) + '.h264' camera_check = True old_time = time() ## This is the main video loop -- will record video until told to turn off camera.start_recording(vid_dir + vid_name) #start recording the video while camera_check: cur_time = time() if ((cur_time - old_time) >= 1.0): led_display.data_display('camera') joystick_press = joystick.wait(timeout=1) if joystick_press: event = joystick.read() if event.state == joystick.STATE_PRESS: if event.key == joystick.KEY_ENTER: camera_check = False camera.stop_recording() #stop recording the video