Time to get create your Phiro Arduino Board Game!
Connecting Phiro, Arduino and Color Sensor
To connect Phiro and Arduino with Pocket Code, you will need to have "Standard Firmata" on the Arduino Board. Here are the steps to upload Standard firmata.
In Arduino IDE,
1. Select the COM Port - Tools -> Serial Port -> Corresponding COM Port
2. Select your Arduino Board. Tools -> Board -> Your Arduino Board (We have used an Arduino UNO, but you can use any Arduino board)
3. Select the Standard Firmata. Click on Examples -> Firmata -> Standard firmata
4. Click on Upload
Code
Before you create your Main Board Game Code, let's figure how to detect color sensor values (which you will need in your main board game code) by creating easy code in Pocket Code, using the color path mat and Arduino connected Phiro. Place Phiro on each color square and detect sensor values.
Detect sensor values and note the value of a0 (Red), a1 (Blue) & a2 (Green). For example, we got values of a0 in between 180-200 for Red, a1 in between 170-180 for Green, a2 in between 181-190.
Note: Values will vary according to user environment. Use only the values you got with this code and use it in the main board game program.
Main Board Game Code
1.Generate dice numbers & Move Phiro dice number of steps
2.Detect color & Move Phiro based on detected color
1.Generate dice numbers & Move Phiro dice number of steps
Create a program to generate a virtual dice using Pocket Code and make Phiro move dice number of steps forward.
If Phiro reaches the Green Square, take one step Forward as credit
If Phiro reaches the Red Square, take one step Backward as penalty
If Phiro reaches the Blue Square, Pocket Code announces "Reached Destination"
Use above three looks in one sprite with look name 1, 2 & 3 respectively.
Initializing default value of variables a0, a1 & a2 to Arduino AnalogPin0, AnalogPin1 & AnalogPin2 respectively.
Initializing default LED Color
Initializing default Sprite Look to 1
Initializing Variable Random to 1
Generating Random value in between 30 to 50
Increasing variable random by 1 for each change of look
Using "Next Look" block animating dice
Checking generated random value and map its value to Dice value using "MOD" function.
Using Repeat block, move Phiro Random dice number of times
2. Detect color & Move Phiro based on detected color
Checking color of Final Square using a0 variable and if it's Red, Phiro LED glows Red and moves 1 step Backward.
Checking color of Final Square using a1 variable and if it's Green, Phiro LED glows Green and moves 1 step Forward.
Checking color of Final Square using a2 variable and if it's Blue, Phiro LED glows Blue and Pocket Code says "Reached Destination"
Test your board game
Once your main board game code is completed, place Phiro on color path mat. Switch on Phiro robot and select Bluetooth Mode. Connect battery to Arduino to turn it on. Press Play on your board game program and make sure to connect with both the Arduino Bluetooth and Phiro Bluetooth. Tap the program to generate Dice numbers and play.