Project 9 Pet the XGO
Ⅰ. Teaching Aims
Read the status of the top touch pin A0 (Foxbit logo) to understand the principle of “capacitive touch”.
Avoid misjudgment through the process of “trigger → anti-shake → re-detection”.
Utilize
if / elseto respond to touch events in real time within theforeverloop.Be able to quickly replace the “actions after being touched” as needed, such as sitting down, turnning in circles, and performing randomly.
Ⅱ. Pre-class Check
XGO + Foxbit + MicroBlocks IDE.
XGO battery power ≥ 60 %. The robot is placed in the center of a flat ground.
The copper foil on the top of its head is clean and free of oil stains. The wiring cable is firmly connected.
MicroBlocks status bar shows a green dot, XGO-lite extension is loaded and the development board model is Foxbit.
Run
XGO reset poseto confirm that the zero position is OK.
Ⅲ. Key Blocks Analysis
|
|
|---|---|
Return value / Functions |
|
Fallible points |
Wrong pin → always |
|
|
Return value / Functions |
Perform different actions according to touching results |
Fallible points |
Forgot |
|
|
Return value / Functions |
The action to be done after touching |
|
|
Return value / Functions |
The action to be done after touching |
Ⅳ. Practice
The following two scripts demonstrate common touch responses and can be directly copied and run.
Test 1: “Touch Head and Sit + Smile”

Tap the logo on the top of the device gently, and the dog will immediately sit down and display
happy.After
wait 5000, the emoji will automatically go out and enter the next round of detection.
Online code: Click here
Test 2: “Touch Head and Turn Around”

Touch once → Turn left round once (40° × 9 times), and then XGO turn 0 to immediately stop.
Online code: Click here
Ⅴ. Quiz
What will occur if the anti-shake time is reduced from 50 ms to 5 ms?
Why must
XGO turn 0be written at the end of Test 2 while Test 1 does not require additional return?How to put an action list such as “sit down, turn around, bow” into an array for random selection? Which MicroBlocks block is used to implement it?
Ⅵ. FAQ
Questions |
Possible causes |
Solutions |
|---|---|---|
No response when touching |
The copper foil is dirty |
Clean the electrode; |
Multiple actions when touching once |
Insufficient anti-shake |
|
Occasionally triggered by mistake |
Electrostatic coupling |
Add |
Always turning around |
|
Reset to zero immediately |
The action gets stuck halfway |
There is a conflict because other scripts |
Pause irrelevant scripts |



