2018年5月14日 星期一

Microbit control html5 game :Flying sailfish ---2


□download and install   mbedWinSerial_16466
We need mbed driver to let the Microbit show as a Serial port in pc.So we download the  mbedWinSerial_16466 and install it.
http://developer.mbed.org/media/downloads/drivers/mbedWinSerial_16466.exe





□The code for microbit   Go to the  official python site 
http://python.microbit.org/v/1

Key the example code:
---------------------------------------------------
from microbit import *  

while True:  
    if accelerometer.was_gesture('shake'):
        print('a')
    sleep(10)
------------------------------------------------------------------------------------

We send a word by using the Micro:Bit accelerometer to detect a "shake" .

After writing the code,you must press the  Download image to download the code.

You can download this code here.


 □plug your microbit  and import the code







Take notice:
The usb label is MICROBIT
 □Check your microbit is which serial port
Open the pc  control center , in device manager,find  COM and LTP item.Remember  your device port (for example,my port is COM3).
Take notice:You must plug the microbit in pc  usb port.  

And remember your device baud  rate.







□Download the   Flying sailfish html5 game
Click this link Flying sailfish

It is a Self-extracting file.If you duble click it.The game will extract  to C:\testgame2





□open python  programing tool
We chose IDLE(Python GUI) and open the   file   get.py  in   c:\testgame2






Take notice:
You must  modify the port and baud with your device data.
□Run get.py code

Shake  Microbit  and  see   if   pc   get  the data

When you shake Microbit and see Got:a,
it means ...........  you success.


Next , we will shake   Microbit  to control the game-Flying sailfish 



沒有留言:

張貼留言