0% found this document useful (0 votes)
3 views2 pages

Spike Prime Color Sensor Control

The document contains a Python script for controlling a motor using a color sensor with the Spike Prime hub. It initializes a color sensor and a motor, setting the motor's default speed and stop action. The script continuously checks the color detected by the sensor and starts or stops the motor based on whether the color is green.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Spike Prime Color Sensor Control

The document contains a Python script for controlling a motor using a color sensor with the Spike Prime hub. It initializes a color sensor and a motor, setting the motor's default speed and stop action. The script continuously checks the color detected by the sensor and starts or stops the motor based on whether the color is green.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Reference MAterial

from spike import PrimeHub, LightMatrix, Button, StatusLight, ForceSens


or, MotionSensor, Speaker, ColorSensor, App, DistanceSensor, Motor, Mot
orPair
from [Link] import wait_for_seconds, wait_until, Timer
from math import *

hub = PrimeHub()
color_sensor_E = ColorSensor('E')
motor_A =Motor('A')
motor_A.set_default_speed(30)
motor_A.set_stop_action('brake')
motor_A_flag = 0
def stop_at(colour):
motor_A_flag = 0 # Reset the flag for motor A to OFF.
motor_B_flag = 0 # Reset the flag for motor B to OFF.

# Move forward.
motor_A.start()

while True:
if color_sensor_E.get_color() == 'green':
motor_A.start()
else:
motor_A.stop()

You might also like