def main(): print("Running...") global current_setting while True: current_lux = SensorsInterface.getAmbientLight() # Get the current light level to see if it is in range sensor_string = "Light: " + str(current_lux) # Add the light value to the string tft_printer.screen_print_rotated(sensor_string, 1) # Print the completed string to the landscape display current_difference = current_lux - desired_lux # Calculate how different the current and desired levels are if current_difference < 0 and abs(current_difference) > lux_per_bright: # If negative difference, check low brightness_notches = math.floor(abs(current_difference) / lux_per_bright) # Calculate how much to change current_setting += brightness_notches # Increase the current brightness by the calculated amount print("Light too low, increasing brightness by " + str(brightness_notches) + " to " + str(current_setting)) if current_setting > 100: # If the setting attempts to cross the maximum of 100, set it to 100 print("Can't go brighter than 100, capping it") current_setting = 100 # Cap the setting at the maximum of 100 CloudTools.ifttt_trigger(IFTTT_KEY, IFTTT_EVENT, IFTTT_TIMEOUT, current_setting) wait_for_change(current_lux, "UP") # Waits until the brightness changes/times out elif current_difference > 0 and current_difference > lux_per_bright: # If positive difference, check high brightness_notches = math.floor(current_difference / lux_per_bright) # Calculate how much to change current_setting -= brightness_notches # Decrease the current brightness by the calculated amount print("Light too high, decreasing brightness by " + str(brightness_notches) + " to " + str(current_setting)) if current_setting < 0: # If the setting attempts to cross the minimum of 0, set it to 0 print("Can't go darker than 0, capping it") current_setting = 0 # Cap the setting at the minimum of 0 CloudTools.ifttt_trigger(IFTTT_KEY, IFTTT_EVENT, IFTTT_TIMEOUT, current_setting) # Change the brightness wait_for_change(current_lux, "DOWN") # Waits until the brightness changes/times out time.sleep(3) # Wait for 3 seconds between each check for brightness
def setup(): print("Setting up...") SensorsInterface.setupSensorian() # Prepare the sensors on the Sensorian Shield time.sleep(2) # Wait 2 seconds or some sensors won't be ready (x, y, z) = SensorsInterface.getMagnetometer() # Get the current force values of the magnetometer sensor_string = "X: " + str(x) + " Y: " + str(y) + " Z: " + str(z) # Add the magnet values to the string tft_printer.screen_print_rotated(sensor_string, 1) # Print the completed string to the landscape display
def run(self): global TFT_available TFT_available_lock.acquire() TFT_available = False TFT_available_lock.release() # tft_printer.screen_print(str(self.message)) tft_printer.screen_print_rotated(str(self.message), self.orientation) TFT_Lock.release() TFT_available_lock.acquire() TFT_available = True TFT_available_lock.release()
def run(self): global TFT_available TFT_available_lock.acquire() TFT_available = False TFT_available_lock.release() #tft_printer.screen_print(str(self.message)) tft_printer.screen_print_rotated(str(self.message), self.orientation) TFT_Lock.release() TFT_available_lock.acquire() TFT_available = True TFT_available_lock.release()
def calibrate(): global xClosed, yClosed, zClosed seconds = SECONDS # The number of seconds to give the user to prepare the device in the door closed position while seconds > 0: # While the user still has time to prepare # print("Calibrating door closed state in " + str(seconds)) calibrating = "Calibrating door closed state in " + str(seconds) print(calibrating) tft_printer.screen_print_rotated(calibrating, 1) time.sleep(1) # Wait for a second seconds -= 1 # Reduce the time remaining for preparation by 1 second (xClosed, yClosed, zClosed) = SensorsInterface.getMagnetometer() # Get the current force values of the magnetometer calibrated = "Calibrated door closed state to " + str(TOLERANCE) + " within " + str((xClosed, yClosed, zClosed)) print(calibrated) tft_printer.screen_print_rotated(calibrated, 1) time.sleep(3) # Waits 3 seconds so the user can read the screen
def main(): print("Running...") global current_setting while True: current_lux = SensorsInterface.getAmbientLight( ) # Get the current light level to see if it is in range sensor_string = "Light: " + str( current_lux) # Add the light value to the string tft_printer.screen_print_rotated( sensor_string, 1) # Print the completed string to the landscape display current_difference = current_lux - desired_lux # Calculate how different the current and desired levels are if current_difference < 0 and abs( current_difference ) > lux_per_bright: # If negative difference, check low brightness_notches = math.floor( abs(current_difference) / lux_per_bright) # Calculate how much to change current_setting += brightness_notches # Increase the current brightness by the calculated amount print("Light too low, increasing brightness by " + str(brightness_notches) + " to " + str(current_setting)) if current_setting > 100: # If the setting attempts to cross the maximum of 100, set it to 100 print("Can't go brighter than 100, capping it") current_setting = 100 # Cap the setting at the maximum of 100 CloudTools.ifttt_trigger(IFTTT_KEY, IFTTT_EVENT, IFTTT_TIMEOUT, current_setting) wait_for_change( current_lux, "UP") # Waits until the brightness changes/times out elif current_difference > 0 and current_difference > lux_per_bright: # If positive difference, check high brightness_notches = math.floor( current_difference / lux_per_bright) # Calculate how much to change current_setting -= brightness_notches # Decrease the current brightness by the calculated amount print("Light too high, decreasing brightness by " + str(brightness_notches) + " to " + str(current_setting)) if current_setting < 0: # If the setting attempts to cross the minimum of 0, set it to 0 print("Can't go darker than 0, capping it") current_setting = 0 # Cap the setting at the minimum of 0 CloudTools.ifttt_trigger(IFTTT_KEY, IFTTT_EVENT, IFTTT_TIMEOUT, current_setting) # Change the brightness wait_for_change( current_lux, "DOWN") # Waits until the brightness changes/times out time.sleep(3) # Wait for 3 seconds between each check for brightness
def main(): print("Running...") door_was_open = False # A boolean to store whether or not the door was already open if it was detected open again while True: (x, y, z) = SensorsInterface.getMagnetometer() # Get the current force values of the magnetometer sensor_string = "X: " + str(x) + " Y: " + str(y) + " Z: " + str(z) # Add the magnet values to the string # If any of the sensor values differ from the calibrated closed amount by more than the tolerance, it is open if xClosed - TOLERANCE > x or x > xClosed + TOLERANCE or yClosed - TOLERANCE > y or y > yClosed + TOLERANCE or \ zClosed - TOLERANCE > z or z > zClosed + TOLERANCE: if not door_was_open: sensor_string += " Door opened!" print(sensor_string) CloudTools.ifttt_trigger(IFTTT_KEY, IFTTT_EVENT, IFTTT_TIMEOUT) door_was_open = True else: door_was_open = False tft_printer.screen_print_rotated(sensor_string, 1) # Print the completed string to the landscape display time.sleep(1) # Wait for 1 seconds between each check for magnetic forces
import time import tft_printer import SensorsInterface import PiTools import CloudTools __author__ = "Dylan Kauling" __maintainer__ = "Dylan Kauling" __status__ = "Development" SensorsInterface.setupSensorian() # Prepare the sensors on the Sensorian Shield SensorsInterface.ledOn() # Turn on the Sensorian Orange LED # Print White Hello World to the display in Portrait mode tft_printer.screen_print_rotated("Hello world!", 0) time.sleep(2) # Wait for 2 seconds before continuing. # Print a longer black string on a white background to the display in Landscape mode tft_printer.screen_print_rotated("This is a longer string to demonstrate the wrapping and text background", 1, colour=(0, 0, 0, 0), background=(255, 255, 255)) time.sleep(2) # Wait for 2 seconds before continuing. sensor_string = "" # Prepare an empty string to be printed to the screen sensor_string += " Light: " + str(SensorsInterface.getAmbientLight()) # Add the light value to the string sensor_string += " Temp: " + str(SensorsInterface.getTemperature()) # Add the temperature to the string
HOST = "127.0.0.1" PORT = 7778 server_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) server_socket.bind((HOST,PORT)) server_socket.listen(1) while True: client_socket, client_addr = server_socket.accept() data = client_socket.recv(4096) data = str(data) try: mode = int(data[0]) data = data[1:] except: print "Mode not specified. Assuming zero." mode = 0 if mode == 0: tft_printer.screen_print(str(data)) elif mode == 1: tft_printer.screen_print_rotated(str(data),1) client_socket.close() server_socket.close() __author__ = "Michael Lescisin" __copyright__ = "Copyright Sensorian 2015"
import tft_printer import SensorsInterface import PiTools import CloudTools __author__ = "Dylan Kauling" __maintainer__ = "Dylan Kauling" __status__ = "Development" SensorsInterface.setupSensorian( ) # Prepare the sensors on the Sensorian Shield SensorsInterface.ledOn() # Turn on the Sensorian Orange LED # Print White Hello World to the display in Portrait mode tft_printer.screen_print_rotated("Hello world!", 0) time.sleep(2) # Wait for 2 seconds before continuing. # Print a longer black string on a white background to the display in Landscape mode tft_printer.screen_print_rotated( "This is a longer string to demonstrate the wrapping and text background", 1, colour=(0, 0, 0, 0), background=(255, 255, 255)) time.sleep(2) # Wait for 2 seconds before continuing. sensor_string = "" # Prepare an empty string to be printed to the screen sensor_string += " Light: " + str(