Exemplo n.º 1
0
# %%
from mindstorms import MSHub, Motor, MotorPair, ColorSensor, DistanceSensor, App
from mindstorms.control import wait_for_seconds, wait_until, Timer
from mindstorms.operator import greater_than, greater_than_or_equal_to, less_than, less_than_or_equal_to, equal_to, not_equal_to
import math

# %% [markdown]
# # Initialization

# %%
print("-"*15 + " Execution started " + "-"*15 + "\n")

# %%
hub = MSHub()
app = App()

# %%
hub.status_light.on('black')

# %% [markdown]
# # Configure motors

# %%
print("Configuring motors...")
motors_wheels = MotorPair('A', 'E')
motors_wheels.set_default_speed(70)

motor_left_arm = Motor('B') # Left arm
motor_right_arm = Motor('F') # Right arm
from mindstorms.operator import greater_than, greater_than_or_equal_to, less_than, less_than_or_equal_to, equal_to, not_equal_to
import math

# %%
from utime import sleep as wait_for_seconds
from utime import ticks_diff, ticks_ms

# %% [markdown]
# # Initialization

# %%
print("-" * 15 + " Execution started " + "-" * 15 + "\n")

# %%
hub = MSHub()
app = App()

# %%
hub.status_light.on('black')

# %% [markdown]
# # Configure motors

# %%
print("Configuring motors...")
motor_left_arm = Motor('B')  # Left arm
motor_right_arm = Motor('F')  # Right arm
motors_arms = MotorPair('B', 'F')
motors_wheels = MotorPair('A', 'E')
print("DONE!")
Exemplo n.º 3
0
from mindstorms.control import wait_for_seconds, wait_until, Timer
from mindstorms.operator import greater_than, greater_than_or_equal_to, less_than, less_than_or_equal_to, equal_to, not_equal_to
import math

# %%
import random  # Needed to generate random numbers

# %% [markdown]
# # Initialization

# %%
print("-" * 15 + " Execution started " + "-" * 15 + "\n")

# %%
hub = MSHub()
app = App()

# %%
hub.status_light.on('black')

# %% [markdown]
# # Configure motors

# %%
print("Configuring motors...")
motor_left_arm = Motor('B')  # Left arm
motor_right_arm = Motor('F')  # Right arm
motors_arms = MotorPair('B', 'F')
motors_wheels = MotorPair('A', 'E')
print("DONE!")
# You can find the code in the accompanying [`.py` file](https://github.com/arturomoncadatorres/lego-mindstorms/blob/main/base/charlie/programs/hello_world.py). To get it running, simply copy and paste it in a new Mindstorms project.
#
# # Imports

# %%
from mindstorms import MSHub, Motor, MotorPair, ColorSensor, DistanceSensor, App
from mindstorms.control import wait_for_seconds, wait_until, Timer
from mindstorms.operator import greater_than, greater_than_or_equal_to, less_than, less_than_or_equal_to, equal_to, not_equal_to
import math

# %% [markdown]
# # Initialization

# %%
hub = MSHub()
app = App()

# %% [markdown]
# # Set color of center button
# For a list and demo of all possible colors, see the example [`push_my_color`](https://github.com/arturomoncadatorres/lego-mindstorms/tree/main/examples)
#
# It is worth mentioning that `black` will turn off the center button.

# %%
button_color = 'black'
print("Turning color of center button to " + button_color + "...")
hub.status_light.on(button_color)
print("DONE!")

# %% [markdown]
# # Set orientation
# %%
from mindstorms import MSHub, Motor, MotorPair, ColorSensor, DistanceSensor, App
from mindstorms.control import wait_for_seconds, wait_until, Timer
from mindstorms.operator import greater_than, greater_than_or_equal_to, less_than, less_than_or_equal_to, equal_to, not_equal_to
import math

# %% [markdown]
# # Initialization

# %%
print("-" * 15 + " Execution started " + "-" * 15 + "\n")

# %%
hub = MSHub()
app = App()

# %%
hub.status_light.on('black')

# %% [markdown]
# # Configure motors

# %%
print("Configuring motors...")
motor_left_arm = Motor('B')  # Left arm
motor_right_arm = Motor('F')  # Right arm
motors_arms = MotorPair('B', 'F')

motor_left_arm.set_default_speed(-100)
motor_right_arm.set_default_speed(100)
from mindstorms.control import wait_for_seconds, wait_until, Timer
from mindstorms.operator import greater_than, greater_than_or_equal_to, less_than, less_than_or_equal_to, equal_to, not_equal_to
import math

# %%
import random  # Needed to generate random numbers

# %% [markdown]
# # Initialization

# %%
print("-" * 15 + " Execution started " + "-" * 15 + "\n")

# %%
hub = MSHub()
app = App()

# %%
# If we set the button color to black, we turn it off.
hub.status_light.on('black')

# %% [markdown]
# # Choose random color
# Black is a bit of a boring color, so we will exclude it as a possibility.
# The other possible colors are:
# <table><tr>
# <td> <img src="../multimedia/azure.jpeg" alt="" style="width: 100%;"/> </td>
# <td> <img src="../multimedia/blue.jpeg" alt="" style="width: 100%;"/> </td>
# <td> <img src="../multimedia/cyan.jpeg" alt="" style="width: 100%;"/> </td>
# <td> <img src="../multimedia/green.jpeg" alt="" style="width: 100%;"/> </td>
# <td> <img src="../multimedia/orange.jpeg" alt="" style="width: 100%;"/> </td>
Exemplo n.º 7
0
import math

# %%
# Required for our own timer implementation.
from utime import sleep as wait_for_seconds
from utime import ticks_diff, ticks_ms

# %% [markdown]
# # Initialization

# %%
print("-" * 15 + " Execution started " + "-" * 15 + "\n")

# %%
hub = MSHub()
app = App()

# %%
hub.status_light.on('black')

# %% [markdown]
# # Configure motors

# %%
print("Configuring motors...")
motor_left_arm = Motor('B')  # Left arm
motor_right_arm = Motor('F')  # Right arm
motors_arms = MotorPair('B', 'F')
print("DONE!")

# %% [markdown]
Exemplo n.º 8
0
# You can find the code in the accompanying [`.py` file](https://github.com/arturomoncadatorres/lego-mindstorms/blob/main/base/charlie/programs/time_to_celebrate.py). To get it running, simply copy and paste it in a new Mindstorms project.
#
# # Imports

# %%
from mindstorms import MSHub, Motor, MotorPair, ColorSensor, DistanceSensor, App
from mindstorms.control import wait_for_seconds, wait_until, Timer
from mindstorms.operator import greater_than, greater_than_or_equal_to, less_than, less_than_or_equal_to, equal_to, not_equal_to
import math

# %% [markdown]
# # Initialization

# %%
hub = MSHub()
app = App()

# %%
print("-" * 15 + " Execution started " + "-" * 15 + "\n")

# %% [markdown]
# # Turn off center button
# By setting its color to black

# %%
print("Turning center button off...")
hub.status_light.on('black')
print("DONE!")

# %% [markdown]
# # Display (happy) image
Exemplo n.º 9
0
# %%
from mindstorms import MSHub, Motor, MotorPair, ColorSensor, DistanceSensor, App
from mindstorms.control import wait_for_seconds, wait_until, Timer
from mindstorms.operator import greater_than, greater_than_or_equal_to, less_than, less_than_or_equal_to, equal_to, not_equal_to
import math

# %% [markdown]
# # Initialization

# %%
print("-"*15 + " Execution started " + "-"*15 + "\n")

# %%
hub = MSHub()
app = App()

# %%
hub.status_light.on('black')
hub.light_matrix.show_image('SILLY')


# %% [markdown]
# # Configure motors

# %%
print("Configuring motors...")
motors_wheels = MotorPair('A', 'E')
motors_wheels.set_default_speed(80)

motor_left_arm = Motor('B') # Left arm
Exemplo n.º 10
0
# %%
from mindstorms import MSHub, Motor, MotorPair, ColorSensor, DistanceSensor, App
from mindstorms.control import wait_for_seconds, wait_until, Timer
from mindstorms.operator import greater_than, greater_than_or_equal_to, less_than, less_than_or_equal_to, equal_to, not_equal_to
import math

# %% [markdown]
# # Initialization

# %%
print("-" * 15 + " Execution started " + "-" * 15 + "\n")

# %%
hub = MSHub()
app = App()

# %% [markdown]
# # Start hue
# By turning its button off (i.e., setting its color to black) and displaying the asleep image

# %%
print("Turning center button off...")
hub.status_light.on('black')
print("DONE!")

# %%
print("Displaying asleep face...")
hub.light_matrix.show_image('ASLEEP')
print("DONE!")
Exemplo n.º 11
0
# %%
from mindstorms import MSHub, Motor, MotorPair, ColorSensor, DistanceSensor, App
from mindstorms.control import wait_for_seconds, wait_until, Timer
from mindstorms.operator import greater_than, greater_than_or_equal_to, less_than, less_than_or_equal_to, equal_to, not_equal_to
import math

# %% [markdown]
# # Initialization

# %%
print("-" * 15 + " Execution started " + "-" * 15 + "\n")

# %%
hub = MSHub()
app = App()

# %%
hub.status_light.on('black')

# %% [markdown]
# # Configure motors

# %%
print("Configuring motors...")
motor_left_arm = Motor('B')  # Left arm
motor_right_arm = Motor('F')  # Right arm
motors_arms = MotorPair('B', 'F')
motors_wheels = MotorPair('A', 'E')
print("DONE!")