Showing posts with label MIT App Inventor 2. Show all posts
Showing posts with label MIT App Inventor 2. Show all posts

2017/01/14

MIT App Inventor 2 - Voice Recognition

** Hi All, I have received few requests to ask me to post App here in the Blog **

Get this .APK File From here!


Hi Guys, I wished you all had a happy holidays!

It's been a while since I published my last tutorial.  This morning, when I checked MIT App Inventor 2 web editor, I found few new interesting new components.

One of them specially caught my eyes is the "SpeechRecognizer" under Media block.
Checked the explanation on the right, I decided to do a quick test on this new component.


What I want to do here is very simple:
  1. Click "Speak" button to talk to the App
  2. The App send the voice to SpeechRecognizer 
  3. The App then show the particular sentence into a Text next to "You've said"

Here is the Screen1 Layout:
Here are all the components I've used in this tutorial, a button, two labels, and SpeechRecognizer1 component as shown below.





Here are the programming blocks. Only few blocks to get the Speech Recognizer to work. I was very surprised!

First, initial varibles and text to blank or "".

Secondly, when "SpeakBTN" clicked, just call "SpeechRecognizer1" to GetText. 




After get your Voice to Text, just set it to label.







Well, that's all need you do do the complete Voice Recognizer App.
See the YouTube Video for the demo below.



I guess you might want to give it a try now!

The End.
==================================================================


** Hi, 收到幾位朋友希望我把 .APK 放到這裡可以直接下載!沒問題,已經放到底下連結 **

請由此下載 Android APP .APK 檔案

哈囉大家好,但願大家都有一個開心的假期!

距離上次我發布新的教學已經有一段時間 了。這個早上,我在查看MIT App Inventor 2時
我發現了幾個有趣的新東西。

第一個吸引我的目光的是音樂裡的「聲音辨識」。看一下解釋後,我決定針對這個新東西做個小測試。

我要做的測試非常簡單:

  1. 按下「說話按鈕」後對他說話
  2. 程式把你說的話丟給聲音辨識系統
  3. 辨識完後再將你說的話顯示出來

Here is the Screen1 Layout:
下圖是這次測試所用到的原件,一個按鈕、兩個文字元件和一個聲音辨識元件。





這些是程式方塊。其實,只要這些方塊就能使聲音辨識起作用讓我還蠻驚訝的呢!

首先,先設定變數和把文字設定成空格。


再來,當「說話按鈕」被按下時,就叫聲音辨識元件辨識並得到字串.








當系統辨識完後,就將它設成文字。








只要有上方這幾行程式就能完成你的聲音辨識App了。
請觀看底下的示範影片。


我想你現在一定迫不及待想去試試看了吧!

2016/09/04

Android App Control RGB LED w/ color Sliders


If you haven't seen my previous Arduino + Bluetooth + RGB LED tutorials, please check them out from here, before you start this one.

Tutorial 1 Make the Arduino + Bluetooth + RGB LED
Tutorial 2 Make this App (older version)
Tutorial 3 Make a nigh lamp
In this tutorial, I will add RGB slider bar under the bottom of the App using App Inventor 2 (AI2) from MIT to allow users to adjust the particular LED brightness. This feature was requested by quite few of visitors. Hope you will enjoy this one!

For whatever reasons you do not want to do this yourself, please download this App from Google Play Store directly. It's FREE!


Screenshot of RGB LED Controller:





Here is screenshot of the component layout in App Inventor 2 for your reference.


First, let's initialize few variables in AI2.


Screen1.Initialize block is to reset App components status and set ColorPicked at x1, y1. The ColorPicked variable is used to store x1, y1 coordinates which are exact positions where users finger tip location on the display.


















This part is considered as Bluetooth initialization to get nearby Bluetooth client list into the App.

After users select Arduino Bluetooth clients (Arduino + HC-05 + RGB module), this App set "Status.Text" to BT Connected and let user know the App has connected to Arduino successfully.


The block below turns the LED On/Off.

The block below will disconnect Bluetooth connection and reset component status.

This block sends Bluetooth command to Arduino after received color-code as well as save R, G, B color code value into a local Color_List2 (List is called Array in other programming languages)



The following three big blocks process the R, G, B sliders respectively.
Each time a slider's position changed, the App reflects the R/G/B value changed and save the value into Color_Code_to_BT variable and sends the new color code through SendBTCommend2 block to achange RGB LED color.


This block works the same as the one above except it only handle Green color value.


This block works the same as the one above except it only handle Blue color value.

When user's finger is touch or slide across the display, this SendBTCommend block will send R, G, B value accordingly to Arduino.

This SendBTCommend2 block is used to send RGB value to Arduino when R, G, or B value updated through R, G, B color sliders. The reason why I created this SendBTCommand2 to send R,G,B value was because there were different parameters needed to be processed before send BT command to Android phone.

The block blow is used to update RGB color to Arduion when user's finger touch on any part of the screen or in this case we only focus on the color wheel.


The block blow is used to update RGB color to Arduion when user's finger slide through the screen of the screen or in this case we only focus on the color wheel. This block is also where this App process rapid change of the LED colors!


Here is a video demonstration of this App:


You probably want to test this APP first before making it, correct? Please download the RGB LED Controller V3.0 with R/G/B Color slider from App Store. For people who already downloaded this App, you should be able to upgrade to this version directly from Google Play Store.  

Thank you!

END
--------------------------------------------------------------------
如果你尚未閱讀過我前幾篇介紹如何製作Android + Arudino + BT + RGB LED的文章,建議先參考前幾篇(下列的連結),再回來看這一篇。

Tutorial 1 製作 Arduino + Bluetooth + RGB LED
Tutorial 2 自制 APP (本篇為新版APP,加入了 R.G.B 顏色拉桿)
Tutorial 3 製作夜燈

如果你不想自己動手做這個 APP, 請你到 Google Play Store 免費直接下載!


在本篇教學裡,我們將修改前一版的 V2.0 APP,使用 App Inventor 2  (AI2) 加入 R.G.B 三個顏色拉桿,讓使用者可以自行調整每個顏色的強度,進一步改變 LED 的顏色。會加入這個功能的主要原因是很多讀者都留言要求這個功能!讓我們開始動手吧!

V3.0 APP 的畫面如下:




這是 AI2 App 元件的畫面參考圖,你也可以依自己的需求作調整位置/大小等等⋯⋯



首先先在AI2中設定幾個變數如下:

下面的區塊是 AI2  的螢幕啟動設定,除了設定一些參數之外,也把 ColorPicked 設在 x1, y1 的位置。 ColorPicked 這個變數是用來儲存螢幕上,使用者正用手指點下的 x, y 位標。


















BTList.BeforePicking 是設定 Android 手機上所偵測到的藍芽裝置清單。


BTList.AfterPicking 區塊主要作用為,一但使用者由手機選取了藍芽裝置(以這個APP例子來說,我們就是 HC-05 的 Android  上的藍芽裝置)。這個區塊也會把 Status.Text  設成 "BT Connected", 讓使用者知道,手機已成功連上 Arduino HC-05 藍芽模組。

LedTurnOn 這個區塊主要功能是直接開/關 RGB LED。

Disconnect.Click 這個區塊是用來中止藍芽的連線,同時也在 App 上顯示 "No BT Connected"。

以下三個區塊 R.PositionChanged, R.PositionChanged 和 R.PositionChanged 主要是用來處理本次新增的 R, G, B 顏色拉桿。例如 R 拉桿位置改變時,這個區塊就會把 新的 R 顏色值和原來的 G, B 顏色值整合存入到 Color_Code_to_BT 變數,透過 SendBTCommend2 區塊送到 Arduino。

這個區塊負責 R.PositionChanged 其運作方式和上面一樣。

這個區塊負責 G.PositionChanged 其運作方式和上面一樣。

這個區塊負責 B.PositionChanged 其運作方式和上面一樣。

當使用者用手指點取調色盤上的某一個點或是用手指滑過調色盤時,這個 SendBTCommend 區塊是用來傳送 R, G, B 顏色參數到 Arduino。


由於透過拉桿改變顏色的方法和直接在螢幕點選時參數不同,所以我建立了這個 SendBTCommand2 的區塊來專門㲃理。這個 SendBTCommend2 區塊是用來傳送 RGB 的參數到手機。

Canvas1.TouchDown 區塊主要是處理手指點在調色盤的每一個位置的顏色,快速即時的把當時的顏色回報到 Arduino。

Canvas1.Dragged 區塊主要是處理手指滑過調色盤的每一個點,快速即時的把當時的顏色回報到 Arduino。


請看我手機錄下的 RGB LED Controller APP V3.0 執行過程:



看完後是不是很想動手試試這個 APP?請由 Google Play Store下載 RGB LED Controller V3.0 with R/G/B Color slider  APP。如果你已經下載之前的版本,你應該可以以直接在手機上做更新。

全篇完!
--------------------------------------------------------------------

2015/02/15

Android control color RGB LED using HC-05 Bluetooth module with Arduino (Part II)

 Android control color RGB LED using HC-05 Bluetooth with Arduino(Part II)

You probably have seen my first part of Arduino hardware setup tutorial. If you haven't please visit here: My previous Arduino (Part I tutorial).

After few weeks of struggling with MIT App Inventor 2, I finally completed my second generation of Color LED Controller V2.0 App.


Basically, 2nd generation of Android APP shows a color RGB wheel on the display and you might pick any color on the display to wirelessly change the RGB color accordingly. With glide/drag capability built in the App, you may glide your finger through the color wheel to see RGB LED changes color gradually.

For the Arduino part, all the code stays the same. Yes, I haven't modified a single line of code in the Arduino.

Please watch the video below to see how it works! :)




Here are the App coding screenshot for your reference:

************************************************************
0) Sorry blog readers....here are the two missing global variable blocks.... :-)
*************************************************************

1) App Inventor 2 screen initialisation code.












2) Android to HC-05 Bluetooth connection code.

3) The button to turn on/off LED



4) Code for touch on the color wheel to change LED color


 5) Code for Glide/Drag finger across the color wheel to see the color change accordingly

6) Here is the code for RGB color code split and then send to Arduino to change RGB LED color through Bluetooth.


How RGB Color Code was Processed:==*==*==*====*====*====*====*====*====*====*====*====*====*====*==
In App Inventor, the color code string after [Split Color] will be something like "(255 255 255 255)". What I need in Arduino is only R, G B, so I have to remove last 255.

*** The last 255 is a string in color code and it will be 255 all the time***

For easier string processing, I replace " "(space) with a "." (dot).
Then, I send each color code string to Arduino as "255.255.255)"

In side Arduino, I could split R, G, and B easily with the "."(dot) and use ending ")"(parenthesis) to check if the color code is complete or not.
==*==*==*====*====*====*====*====*====*====*====*====*====*====*==


After you put all these codes into MIT App Inventor 2, you should able to build the code on your PC/Mac to generate an Android .APK to place on your Android phone to test it out with Arduino.

Please do not ask me to post the original code here for you to download. If I do so, no one would download my App from Android Play Store! ;)

If you don't want to create this App yourself, please Download this App here!

Happy coding!!

Stonez


--------------------------------------------------------------------------------------------------------------------

Part II - Android HC-05 藍芽連線控制彩色 RGB LED


你們可能已經讀過我上一次的Arduino硬體設定和下載了第一代APP。如果還沒看過,可參閱我上一個教學 Android 藍芽連線控制彩色 LED

經過幾個禮拜的努力,我終於完成我第二代的 LED 遙控 APP 了。

基本上第二代的設計是一個可以任君挑選顏色RGB調色盤。你可以點選你想要的顏色或是用手指滑過螢幕上的任一個顏色,應用程式會透過藍芽把顏色代碼送變 Arduino 來改變 RGB LED 燈泡的顏色。

Arduino 程式碼的部分是維持跟之前一樣,一行程式碼都不用更改就能使用了。

請先看一下底下影片的示範:






MIT App Inventor 的程式代碼如下:


1) App Inventor 2 Screen1 初始化設定:













2) Android 連結到 Arduino + HC-05 藍芽模組程式碼:

3) 這組程式碼是用來開關 RGB LED



4) 這組程式碼是用來回應點選的顏色並改變 LED 顏色


 5) 這組程式碼是用來控制滑過螢幕並即時改變其顏色

6) 這組程式碼是用來把顏色編碼成 RGB 代號並且把這組編碼顏色代號以藍芽送到Arduino該LED依照代碼變色。



只要按照以上程式碼輸入MIT App Inventor 2後,你就應該可以做成一個APK檔案。
Sorry, 我不會把原始檔整會貼在這裡,所以請你動手做做看吧!!

如果不想動手做,那請從 Play Store 下載吧

Stonez