[實驗目的]

   這集教給大家 APP語音辨識,採用說得讓車子改變化方向。


步驟 1:進入「appinventor」。

投影片1.JPG

官網連結 = [ http://appinventor.mit.edu/ ]


步驟 2:點「Create Apps!」> 「註冊/登入」。

投影片2.JPG


步驟 3:就可以進來appinventor專案頁。

投影片3.JPG


步驟 4:點「專案」>「匯入專案(.aia)」>「選擇檔案」。

投影片4.JPG


步驟 5:選擇「D1_mini_Lab11.aia」並確定。

投影片5.JPG


步驟 6:點「打包Apk」>「Android App(.apk)」。

投影片6.JPG


步驟 7:這是 APP 的編輯程式碼。

投影片7.JPG

注意:appinventor僅支援Android安卓作業系統


步驟 8:開啟「Thonny」軟體。

投影片8.JPG


步驟 9:選擇「工具」>「選項」>「ESP8266」>「序列阜」。

投影片9.JPG


步驟 10:開啟「myWemotor_IP_AppVoice」。

投影片10.JPG


步驟 11: 點「停止」>「執行」。

投影片11.JPG


步驟 12: 點「檔案」>「儲存副本」 。

投影片12.JPG


步驟 13: 點「MicroPython設備」> 輸入「main.py」>「確定」。

投影片13.JPG


步驟 14:在程式碼中 第40行 改為自己的網路。

投影片14.JPG


步驟 15:輕按「板子上重啟鈕」>「顯示網路位址」。

投影片15.JPG


步驟 16:在 Google Play 商店 輸入「旗標語音助理」。

投影片16.JPG


步驟 17:輸入「網路位址IP」。

投影片17.JPG


import network
import ESP8266WebServer                 
import wemotor
from machine import I2C,Pin
import time

motor = wemotor.Motor()

# 處理 /Race 指令的函式
def handleCmd(socket, args):            
    # 檢查是否有 output 參數
    if 'output' in args:                     
        if args['output'] == 'L':       
            motor.move(0,40)            # 左轉
            print('左轉')
        elif args['output'] == 'R':     
            motor.move(40,0)            # 右轉
            print('右轉')
        elif args['output'] == 'F':
            motor.move(40,40)           # 直走
            print('前進')
        elif args['output'] == 'B':
            for i in range(20):         
                motor.move(20-i,20-i) 
                time.sleep(0.05)                
            motor.move(-40,-40)         # 後退
            print('後退')
        elif args['output'] == 'S':
            motor.move(0,0)             # 停止
            print('停止')
        time.sleep(1)
        ESP8266WebServer.ok(socket, "200", "OK")   
    else:
        ESP8266WebServer.err(socket, "400", "ERR") 

LED = Pin(2,Pin.OUT,value=1)  

sta = network.WLAN(network.STA_IF)
sta.active(True)   
sta.connect('網路名稱', '網路密碼')   

while(not sta.isconnected()):
    pass

LED.value(0)               

ESP8266WebServer.begin(80)                      
ESP8266WebServer.onPath("/Race",handleCmd)      
print("伺服器位址:" + sta.ifconfig()[0])        

ap = network.WLAN(network.AP_IF) 
ap.active(True)
ap.config(essid='LAB11-'+str(sta.ifconfig()[0]))  

while True:
    ESP8266WebServer.handleClient()       
    motor.avoidTimeout()

[成果影片]

創作者介紹
創作者 Code Create++ 的頭像
程式創造++

Code Create++

程式創造++ 發表在 痞客邦 留言(0) 人氣( 7 )