
「品質検査システム」を作成しました。カラーセンサーを使って、ブロックの色を判定するロボットです
公式の教員向けのレッスンプランはこちらです

品質検査システム
ユーザーガイドのビデオに従って、「品質検査」ロボットの動きを再現しましょう。
カラーセンサーに紫のブロックをかざすと品質OK(色はプログラム次第です)

緑のブロックだと品質NGです

プログラムはこのようになります

Pythonではこうなります
from spike import PrimeHub, App, ColorSensor, DistanceSensor, Motor
from spike.control import wait_for_seconds
hub = PrimeHub()
app = App()
distance_sensor = DistanceSensor('C')
color_sensor = ColorSensor('D')
arm_motor = Motor('A')
base_motor = Motor('F')
arm_motor.set_default_speed(50)
base_motor.set_default_speed(50)
arm_motor.run_to_position(350)
base_motor.run_to_position(350)
app.start_sound('Connect')
distance_sensor.light_up_all()
for x in range(1):
hub.light_matrix.show_image('HEART')
wait_for_seconds(0.5)
hub.light_matrix.show_image('HEART_SMALL')
wait_for_seconds(0.5)
hub.light_matrix.show_image('HEART')
while True:
color = color_sensor.get_color()
if color == 'violet':
hub.light_matrix.show_image('HAPPY')
arm_motor.run_for_degrees(30)
arm_motor.run_for_degrees(-60)
arm_motor.run_for_degrees(60)
arm_motor.run_for_degrees(-30)
app.start_sound('Connect')
hub.light_matrix.show_image('HEART')
elif color == 'green':
hub.light_matrix.show_image('ASLEEP')
base_motor.run_for_degrees(60)
base_motor.run_for_degrees(-60)
hub.light_matrix.show_image('HEART')
[lego-spike]


