Create your compass code to make Phiro to keep rotating with green light and stop and flashing red light when Phiro detects North direction.
1. Create compass and needle objects to detect direction. (Use images from download material section)
2. Program compass needle direction
- When Program Started
- Initializing Size to 100
- Initializing look to Compass needle
- Display object
- Object always pointing NORTH direction using Forever and Compass Direction Block.
3. Get user to enter direction to detect. Use the "Ask" Block
- When Program Started
- Initialize Background
- Initialising Background Costume.
4. Check conditions for each direction detection and give Phiro output for each
- Check condition for North Direction
- Set Compass value between - 5 to +5
- Stop Phiro and LED glows Red.
- Else, Phiro turns Left and LED glows Green.
- Checks condition for East Direction
- Set Compass value between -85 to 95
- Stop Phiro and LED glows Red.
- Else, Phiro turns Left and LED glows Green.
- Check condition for South Direction
- Set Compass value either > 175 or < -175
- Stop Phiro and LED glows Red.
- Else, Phiro turns Left and LED glows Green.
- Check condition for West Direction
- Set Compass value between 85 to 95
- Stop Phiro and LED glows Red.
- Else, Phiro turns Left and LED glows Green.
Testing out your Compass Code:
After you have completed creating your code
- Switch ON Phiro and Turn ON Bluetooth mode
- Place Smartphone aligned on top of Phiro
- Press Play Button to start your code in Pocket Code
- Enter the option number for direction.
- Tap Submit answer and test!