Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions lib/tasks/project_components/astro_pi_demo/exc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class GPIOZeroError(Exception):
"Base class for all exceptions in GPIO Zero"

class GPIODeviceError(GPIOZeroError):
"Base class for errors specific to the GPIODevice hierarchy"

class GPIOPinInUse(GPIODeviceError):
"Error raised when attempting to use a pin already in use by another device"
50 changes: 50 additions & 0 deletions lib/tasks/project_components/astro_pi_demo/gpiozero.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import _internal_sense_hat as _ish
from exc import GPIOPinInUse

class MotionSensor(object):

inst = False

def __init__(self, pull_up=False, active_state=None, queue_len=1, sample_rate=10, threshold=0.5, partial=False, pin_factory=None):
if MotionSensor.inst:
raise GPIOPinInUse()
self._pin = 12
self.when_motion = None
self.when_no_motion = None
MotionSensor.inst = True

def wait_for_motion(self, timeout=None):
_ish._waitmotion(timeout, True)

def wait_for_no_motion(self, timeout=None):
_ish._waitmotion(timeout, False)

@property
def motion_detected(self):
return _ish.motionRead() == 1

@property
def pin(self):
pass

@property
def value(self):
return _ish.motionRead()

@property
def when_motion(self):
return self._when_motion

@when_motion.setter
def when_motion(self, value):
self._when_motion = value
_ish._start_motion(value)

@property
def when_no_motion(self):
return self._when_no_motion

@when_no_motion.setter
def when_no_motion(self, value):
self._when_no_motion = value
_ish._stop_motion(value)
52 changes: 52 additions & 0 deletions lib/tasks/project_components/astro_pi_demo/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from sense_hat import SenseHat
from time import sleep

sense = SenseHat()
colour = sense.colour
motion = sense.motion

# Sensor output
print("Motion:", motion.motion_detected)
print("Colour:", colour.color)
print("Temperature:", sense.get_temperature())
print("Pressure:", sense.get_pressure())
print("Humidity:",sense.get_humidity())

# # Motion sensor
# def moving_function():
# print("moving")

# def not_moving_function():
# print("not moving")

# motion.when_motion = moving_function
# motion.when_no_motion = not_moving_function

# while True:
# sleep(0.25)

# # Wait for motion function
# motion.wait_for_motion()
# print("it's moving")

# # LED display
# sense.set_rotation(270)
# sense.show_message(":)")
# green = [0,255,0]
# sense.set_pixel(7,7,green)
# sleep(3)
# sense.clear()

# # Testing that changing sensor values can be read mid code run
# while True:
# print(sense.get_temperature())
# print(sense.get_pressure())
# print(sense.get_humidity())
# print(motion.motion_detected)
# print(colour.colour)
# sleep(1)

# # Test that the roll, pitch and yaw are working and update with the 3d model in real time
# while True:
# print(sense.get_orientation())
# sleep(1)
33 changes: 33 additions & 0 deletions lib/tasks/project_components/astro_pi_demo/project_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
NAME: "Astro Pi Test Project"
IDENTIFIER: "flight-case-demo"
COMPONENTS:
- name: "main"
extension: "py"
location: "main.py"
index: 0
default: true
- name: "sense_hat"
extension: "py"
location: "sense_hat.py"
index: 1
default: false
- name: "_sense_hat_text_dict"
extension: "py"
location: "_sense_hat_text_dict.py"
index: 2
default: false
- name: "sense_stick"
extension: "py"
location: "sense_stick.py"
index: 3
default: false
- name: "exc"
extension: "py"
location: "exc.py"
index: 4
default: false
- name: "gpiozero"
extension: "py"
location: "gpiozero.py"
index: 5
default: false
Loading