Paste the reading helper
A SPIKE App Python project is a single file and cannot import your own .py, so paste the whole "reading helper" at the very top (its first lines say so: copy it as is). Without it the hub does not know CamSchoolApp and stops with NameError.
- Open the LEGO SPIKE App (Education, yellow SPIKE Prime hub), create a project and choose "Python".
- Paste the program marked ① on the right at the top (only the first helper line shows; press "Show helper" to see it all, and "Copy program" always copies everything). The helper alone: MBC_cam_school_App_helper.py (open it in a text editor and copy all; the file has Chinese and English comments).
- Plug the camera into any port A–F; the hub powers it. Use the same port as in step 2. Set the colours on the camera first: "1: COLOR" picks the colour point and "2: TRACK" the colour to follow (the program cannot change them).
The helper splits the numbers the App reads for you (the same conversion as the SPIKE App blocks page):
| What the App reads | What it holds | Helper function |
|---|---|---|
color_sensor.color() (color) | hue at the colour point: −1, 0–100 | hue() |
color_sensor.reflection() (reflection) | motion (how much the picture changed) 0–100 | motion() |
color_sensor.rgbi() item 1 (raw red) | blob X: left 0 – right 98; 0 = not found | blob_x() |
rgbi() item 2 (raw green) | blob Y: bottom 1 – top 75; 0 = not found | blob_y() |
rgbi() item 3 (raw blue) | blob area 0–100, 0 = not found | area(), found() |