diff --git a/examples/pup/hub_primehub/imu_up.py b/examples/pup/hub_primehub/imu_up.py new file mode 100644 index 0000000..0222626 --- /dev/null +++ b/examples/pup/hub_primehub/imu_up.py @@ -0,0 +1,29 @@ +from pybricks.hubs import PrimeHub +from pybricks.parameters import Color, Side +from pybricks.tools import wait + +# Initialize the hub. +hub = PrimeHub() + +# Define colors for each side in a dictionary. +SIDE_COLORS = { + Side.TOP: Color.RED, + Side.BOTTOM: Color.BLUE, + Side.LEFT: Color.GREEN, + Side.RIGHT: Color.YELLOW, + Side.FRONT: Color.MAGENTA, + Side.BACK: Color.BLACK, +} + +# Keep updating the color based on detected up side. +while True: + + # Check which side of the hub is up. + up_side = hub.imu.up() + + # Change the color based on the side. + hub.light.on(SIDE_COLORS[up_side]) + + # Also print the result. + print(up_side) + wait(50) diff --git a/examples/pup/hub_shared/imu_up.py b/examples/pup/hub_shared/imu_up.py new file mode 100644 index 0000000..6698009 --- /dev/null +++ b/examples/pup/hub_shared/imu_up.py @@ -0,0 +1,30 @@ +# ExampleHub = TechnicHub PrimeHub +from pybricks.hubs import ExampleHub +from pybricks.parameters import Color, Side +from pybricks.tools import wait + +# Initialize the hub. +hub = ExampleHub() + +# Define colors for each side in a dictionary. +SIDE_COLORS = { + Side.TOP: Color.RED, + Side.BOTTOM: Color.BLUE, + Side.LEFT: Color.GREEN, + Side.RIGHT: Color.YELLOW, + Side.FRONT: Color.MAGENTA, + Side.BACK: Color.BLACK, +} + +# Keep updating the color based on detected up side. +while True: + + # Check which side of the hub is up. + up_side = hub.imu.up() + + # Change the color based on the side. + hub.light.on(SIDE_COLORS[up_side]) + + # Also print the result. + print(up_side) + wait(50) diff --git a/examples/pup/hub_technichub/imu_up.py b/examples/pup/hub_technichub/imu_up.py new file mode 100644 index 0000000..d7208bb --- /dev/null +++ b/examples/pup/hub_technichub/imu_up.py @@ -0,0 +1,29 @@ +from pybricks.hubs import TechnicHub +from pybricks.parameters import Color, Side +from pybricks.tools import wait + +# Initialize the hub. +hub = TechnicHub() + +# Define colors for each side in a dictionary. +SIDE_COLORS = { + Side.TOP: Color.RED, + Side.BOTTOM: Color.BLUE, + Side.LEFT: Color.GREEN, + Side.RIGHT: Color.YELLOW, + Side.FRONT: Color.MAGENTA, + Side.BACK: Color.BLACK, +} + +# Keep updating the color based on detected up side. +while True: + + # Check which side of the hub is up. + up_side = hub.imu.up() + + # Change the color based on the side. + hub.light.on(SIDE_COLORS[up_side]) + + # Also print the result. + print(up_side) + wait(50)