@@ 24-37 (lines=14) @@ | ||
21 | self.go = True |
|
22 | ||
23 | ||
24 | async def train_sensor_change(self): |
|
25 | self.message_info(f'Train sensor value change {self.train_sensor.value}') |
|
26 | distance = self.train_sensor.value[VisionSensor.capability.sense_distance] |
|
27 | count = self.train_sensor.value[VisionSensor.capability.sense_count] |
|
28 | ||
29 | if count > 3: |
|
30 | # Wave your hand more than three times in front of the sensor and the program ends |
|
31 | self.keep_running = False |
|
32 | ||
33 | # The closer your hand gets to the sensor, the faster the motor runs |
|
34 | self.motor_speed = (10-distance)*10 |
|
35 | ||
36 | # Flag a change |
|
37 | self.sensor_change = True |
|
38 | ||
39 | async def run(self): |
|
40 | self.message_info("Running") |
@@ 12-25 (lines=14) @@ | ||
9 | @attach(TrainMotor, name='motor') |
|
10 | class Train(PoweredUpHub): |
|
11 | ||
12 | async def train_sensor_change(self): |
|
13 | self.message_info(f'Train sensor value change {self.train_sensor.value}') |
|
14 | distance = self.train_sensor.value[VisionSensor.capability.sense_distance] |
|
15 | count = self.train_sensor.value[VisionSensor.capability.sense_count] |
|
16 | ||
17 | if count > 3: |
|
18 | # Wave your hand more than three times in front of the sensor and the program ends |
|
19 | self.keep_running = False |
|
20 | ||
21 | # The closer your hand gets to the sensor, the faster the motor runs |
|
22 | self.motor_speed = (10-distance)*10 |
|
23 | ||
24 | # Flag a change |
|
25 | self.sensor_change = True |
|
26 | ||
27 | async def run(self): |
|
28 | self.message_info("Running") |