Write an application that interfaces with an input &/or output device that you made
I make an app which can control the RGB LED by cell-phone and a RGB LED's circuit board.It make with the satshakit MCU from previous week, and it is the same like Bluetooth communications before few weeks ago .RGB mode refers to the three primary colors of light , representing the red, blue, green. When the maximum sum of three colors in different proportions, it will produce different kinds of colors, three types of hybrid is white. It is noteworthy that the three primary colors of the three primary colors and painting printed in different lights, painting is magenta, yellow and cyan, which are theoretically three types of mixed black. Many editors reference to design and edit this post. 本周的interface and application programming,做了一個可以使用手機控制RGB LED燈的APP與RGB LED燈光的電路板,同時搭配前一周的satshakit MCU,與前幾周一樣是透過用藍芽作為通訊。RGB是指三原色光模式(RGB color model),分別代表紅色、藍色、綠色。當三種顏色以不同比例相加,將產生不同種類顏色,三種類混合的最大值是白光。值得注意的是燈光的三原色與繪畫印刷的三原色不同,繪畫是以洋紅色、黃色和青色,而這三種類混合後理論上是黑色。許多編輯參考了此篇進行設計及編輯。
This week more focused on interface design and function of APP, we made four modes which can adjust LED lighting : 1. RGB selection of color model contains 2. RGB slider to adjust the color code 3. breathing light manual / automatic mode 4. Random replace mode, the RGB information sent by Bluetooth. After Satshakit received, the PWM converted into RGB signals to output analog signals do. Three color lights are combined into each having a different brightness of different colors of light. To design user interface, continue to use Bluetooth communication list and disconnection button. Another lighting mode selection menu and turn on the lights on / off button. The interface buttons are mostly dual function, such as pressing for the closure function enabled; press to start closing function. Another Notifier message warning element, BluetoothClient communication, Clock timer function element. Use Properties field to adjust the layout of the above elements, text size, background color, alignment, and other display interface, it can be arbitrarily set until satisfactory UI appearance. 本周較著重於APP的介面及功能設計,做了4個可以調整LED燈光的模式:包含1.RGB色彩模型手動選擇 2.RGB滑桿調整色碼 3.呼吸燈手動/自動模式 4.隨機更換模式,透過藍芽將RGB資訊送出。Satshakit 接收到後,轉換成RGB的PWM訊號,以類比訊號做輸出。三種顏色燈光各自具有不同亮度組合成不同色彩之光線。先設計使用者介面,延續使用藍芽通訊的清單及斷線按鈕。另外還有燈光模式選擇選單以及開燈/關燈按鈕。本介面中的按鈕多為雙重功能,例如啟用時按下為關閉的功能;關閉時按下為開始功能。另外有Notifier訊息警示元件、BluetoothClient通訊功能、Clock計時器功能元件。使用屬性(Properties)欄位調整上述元件的布局、文字大小、背景顏色、對齊等顯示介面,可任意設定直到滿意的UI出現。
1.RGB manually select the color model
The first function is the interface to select the desired color conversion to LED lighting in the color image on the screen. Setting a canvas block, then RGB color image upload, choose a background. Chiduo can set the size of the phone line with the resolution. 第一個功能介面是在螢幕上的色彩圖片上選擇所要的顏色轉換成LED燈光。設定一個畫布區塊,然後將RGB色彩的圖片上傳,選成背景。可以設定尺吋大小來符合手機解析度。
RGB slider to adjust the color code
The second function is the main function interface uses three slider, slider position transition couplers yards, the left-most slider minimum 0, maximum value of 255 is right in the end. Properties can be selected by the maximum and minimum values may be replaced sliders show the color and size, the other with the caption bar icon. 第二個功能介面主要功能是使用三個滑桿,滑塊的位置轉換成色碼,滑塊最左為最小值0,向右到底是最大值255。可以由properties中選擇最大與最小數值,也可更換滑桿顯示顏色與尺寸,另外配合標上說明文字欄。
3.Breathing light manual / Automatic mode
The third function interface is breathing light mode of operation, from the darkest slowly brighten and then slowly darken, repeated cycles. Forefront have enabled (checkbox) Select the column, you can choose whether you want to enable. Then is a color of the text field, the last three after the opening of the individual is the minimum, maximum, and every increase or decrease in value. The bottom of the column there is a Enable / stop button. The other is random button pressed will automatically fill the random value. 第三個功能介面是以呼吸燈模式運作,由最暗慢慢變亮然後再慢慢變暗,反覆循環。最前端有啟用(checkbox)勾選欄,可選擇是否要啟用。然後是說明顏色文字欄,最末三個別是啟用後的最小值、最大值,以及每次增減的數值。欄位底部有一個啟用/停止按鈕。另一個則為隨機按鈕,按下後會自動隨機填入各項數值。
4.Random replacement mode
Finally, a function interface is only one button to start and stop function. It may send a random color to RGB display lights. 最後一個功能介面只有一個按鈕,具有開始與停止功能。其可以隨機的發送顏色給RGB燈光做顯示。
After the completion of four interface, switch to the "blocks" were prepared and programming. It begins with global variables set, and when the picture initialization work to be accomplished, such as setting the canvas, Bluetooth enabled menus, function buttons, and so can not afford to use. 四個介面完成後,切換到"blocks"進行程式設計及編寫。開頭為全域變數的設定,以及畫面初始化時所要完成的工作,如設定畫布、藍芽選單啟用、功能按鈕不起用等等。
The second part is to connect and disconnect the Bluetooth communication function. First read the name and address of your phone to the Bluetooth menu. When it be wired radio elected, Notifier messages display warning, normal connection is displayed when the connected device name could not connect properly. Bluetooth is another close button, when checked, immediately disconnect the Bluetooth, reply original state, modify the display text, color, etc., again waiting for the connection. 第二部分為藍芽通訊連線及斷開功能。先讀取手機內藍芽名稱及地址給選單,當選單選中時進行連線,無法正確連線時顯示Notifier訊息警示,正常連線則顯示連線裝置名稱。另一個是藍芽關閉按鈕,當點選後,立即斷開藍芽,回復原始狀態,修改顯示文字、顏色等,等待再次連線。
This section contains the program switch LED button is pressed LEDbutton, judgment is currently the lights or turn off the lights, send "ON)" or "OFF)" text to determine the MCU or turn on the lights turn off the lights. Send last column ")" represents the stop code, the MCU judges the communication sent over. The first program is a function screen canvas type, when a finger click / over the canvas, according to the sensed finger position x and y coordinates to read the background RGB color values and parsed and stored to "ColorPicked", Last Call subroutine "SendBTcommand" transmitted color. 此段程式包含開關LED按鈕按下LEDbutton時,判斷目前是開燈還是關燈,發送"ON)"或"OFF)"文字讓MCU判斷要開燈還是關燈。發送欄最末")"代表中止碼,讓MCU判斷此次通訊發送結束。 第一個功能畫面程式為畫布型式,當手指點選/滑過畫布時,根據感應到手指位置的x與y座標進行讀取背景RGB色彩,並進行解析數值並儲存到"ColorPicked",最後呼叫副程式"SendBTcommand"進行發送顏色。
Here it is responsible for sending the color information of two subroutine. The first "SendBTcommand" When is called, the first LED button turns off function, and then the "ColorPicked" values rewrites usually read color values to "(** ** ** 255)", and MCU control LED agreement I set to "** ** **)", representing the red, blue, green value, and an intermediate delimiter "." and the last ")" abort information symbol. The second "SendBTcommand2" subroutine is called directly when "ColorPicked" information, because its content is in accordance with my agreement combination of materials, such as: "255.255.255)." This subroutine when two simultaneous transmission will be judged by the color of the menu there is no Bluetooth is turned on, if only to send the information to open. 此處是負責發送顏色資料的兩個副程式。第一個"SendBTcommand"被呼叫時,先將LED按鈕變成關閉功能,再對"ColorPicked"數值進行改寫,通常讀取到的顏色數值為"(** ** ** 255)",與MCU控制LED的協定我設定為"**.**.**)",分別代表紅色、藍色、綠色數值,以及中間分隔號"."及最末")"中止資訊符號。 第二個"SendBTcommand2"副程式被呼叫時直接發送"ColorPicked"資料,因為其內容是我依協定所組合而成的資料,如:"255.255.255)"。此兩個副程式在發送時同時會依選單顏色判斷藍芽有沒有被開啟,若有開啟才發送資料。
This paragraph apps menu selection operation after four modes. Click determine what kind of function, open the corresponding interface, the interface does not have to close other use. Avoid bug and misinformation phenomenon. 此段程式為四種模式選單選擇後的動作。判斷點選是何種功能,開啟相應的介面,關閉其他不須使用的介面。避免bug及誤傳現象。
This section program for the second function, the slider to select a color. No matter which one is RGB slider, it will call subroutine "Silderchange", reads three ˙ position of the slider, and can successfully set menu text colors (more than once within a set image), to facilitate the user identification of the current color sent. The second step is to send a combination of numerical data into agreement, and then call "SendBTcommand2" send data. 此段程式為第二項功能,由滑桿來選擇顏色。無論是RGB哪一個滑桿被移動時,都會呼叫副程式"Silderchange",讀取三個˙滑塊的位置,並設成功能選單文字的顏色(圖片內多設定了一次),以利使用者辨識目前發送的顏色。第二步是將數值組合成協定發送資料,再呼叫"SendBTcommand2"發送資料。
This section program and random breath lamp lights to enable / stop function will now determine the status of the lights are pressed, the timer is started, if not already lit, starts lighting LED lights. If present, the LED light is on, turn off the lights, and then wait to open or switch to another function interface. 此段程式為呼吸燈及隨機燈光的啟用/停止功能,按下後分別都會判斷現在燈光狀態,若尚未亮燈則啟動計時器,開始點亮LED燈。若目前LED燈已亮起,則關閉燈光,等待再開啟或切換成其他功能介面。
The following snippet is the third function: Button Function random breath lamp. Once you press on a random fill value. Respectively, will remove 9 digits (large and small numerical interval and within three color). And to determine the size of populated min and max. Enable and set the minimum value of each color. 以下這段程式為第三個功能:呼吸燈的隨機按鈕功能。一旦按下就隨機填入數值。分別會取出9個數字(三個顏色內的大、小數值及間隔)。並判斷大小填入min與max。並設定啟用數值為各顏色的最小值。
This section of the program timer function enabled, the third and fourth lamp function respiratory function random timer lamp will take action to send the value to the MCU. So start to read menus, a function which is to determine the current operation again. If you are breathing light mode, each trigger to determine whether the present transmission value has reached the maximum, if not to continue to accumulate; otherwise the maximum reverse the Range becomes negative, the lights will gradually dim. When you reach the minimum value likewise, reverse Range become positive and gradually accumulate. The three color values are summed to call "SendBTcommand2" send. If the fourth function random lights, randomly selected three digits after the timer is triggered, then the assembly and call "SendBTcommand2" send. This two functions when sending text color will replace the function menu. 此段程式為計時器啟用時的功能,第三功能呼吸燈及第四功能隨機燈都會藉此計時器時動作,發送數值到MCU。所以一開始要讀取功能選單,確定目前是哪一個功能再運作。如果是在呼吸燈模式時,每次觸發先判斷目前發送數值是否已達最大值,若沒有就繼續累加;若已到最大則反轉Range成為負值,燈光將會漸漸變暗。當到達最小值時亦同,反轉Range成為正數而漸漸累加。將三個顏色數值加總,呼叫"SendBTcommand2"進行發送。若是第四功能隨機燈時,計時觸發後隨機挑選三個數字,再進行組合及呼叫"SendBTcommand2"發送。此兩項功能在發送時都會更換功能選單文字顏色。
Reference site, RGB LED has four pins, representing R, common, G, B. Either common anode or common cathode type LED, pin pin are the same. I am here using a common anode RGB LED. 參考網站,RGB LED都有四隻接腳,分別代表R、common、G、B。無論是共陽或共陰型LED,接腳腳位都相同。我這邊使用的是共陽極的RGB LED。
Use Designspark PCB drawing RGB circuit board, the second legs are coupled with the outer resistance, not because of the protection of LED current is too large to burn. Referring to the first few weeks of experience in carving out the circuit board and weld elements. 使用Design Spark PCB繪製RGB 電路板,第二隻腳外都加上電阻,保護LED不因電流過大而燒毀。參照前幾周的經驗雕刻出電路板及焊好元件。
Reference Cipian rewrite pin into satshakit use of, for example, I used pin10, Pin11 as Bluetooth communication pin. Having the PWM pin, respectively, 3,5,6, and use the first 13 feet of the LED light switches do judgment. Importing the first paragraph of Bluetooth communication library, declaring Bluetooth communication using one foot, and then to declare the use of parameters: Including pin, RGB output value, the previous RGB value, light switch, a value of the received complete degree. Bluetooth communication baud rate set at the setup, RGB string length and RED_LED pin as an output.The loop is continually fed information to determine whether Bluetooth, if the material is fed to the read data stored as characters. If you receive a ")", is set to receive RGB values is completed, the absence of binding character. Upon receipt of the RGB values is completed, the judgment is received ON / OFF or value, if it is ON then call subroutine Light_RGB_LED (); a light output of the previous state; if it is OFF, then set to "0.0.0" unlit send; the rest are direct numerical subroutine call coexist under current SIGNAL value. Subroutine will eventually do string parsing in order. "" Analyzing R, G, B values, and read out stored separately. Then use the analog output value to the output pins 3,5,6. RGB LED is noteworthy that such acts are using common cathode or common anode. Values are all displayed in front of the positive voltage output (The larger the value, LED more light), used directly in common cathode type LED. If you use common male LED, because the common terminal to a high voltage, so the lighting will be to pin a low voltage, so that the reverse current flow back, it is necessary to use 255 minus the value of re-output (high voltage differential) .
The satshakit, Bluetooth module, RGB lights, wires connected to the battery, and turn on the phone APP were using and testing. The movie shows the four functions, the LED lights of different colors, but if the LED and the brightness of the environment are too different, the recorder will not be able to clearly identify what color LED current. Site identification using human eye resolution could be better. 將satshakit、藍芽模組、RGB燈光、電池以電線接上,並開啟手機APP進行使用及測試。影片中展示了四個功能,點亮的LED具有不同顏色,不過若LED與環境亮度差異太大,錄影機將無法清楚辨識LED目前為何種顏色。現場使用人眼睛辨識的解析度可以更好。
Troubleshooting:
RGB LED common endpoint selection. I did not realize a hand ˙LED common anode type, it can not successfully lit. And when writing programs in the Arduino IDE, if a common cathode type LED, visual output voltage and the forward end of the ground. The common male type LED lights to be displayed in RGB color output with different values. The output value of 256 complement each other (and also do use 256 minus the value of the output). RGB LED共同端點選擇問題。一開始沒有意識到我手邊的˙LED為共陽型,所以無法順利點亮。而在Arduino IDE中編寫程式時,如果是共陰型LED,直觀輸出電壓及順向達接地端。而共陽型LED所要顯示的RGB燈光顏色與輸出數值不同。輸出數值與256互為補數(亦及使用256減去數值再做輸出)。
The Fab Academy is a Digital Fabrication Program directed by Neil Gershenfeld of MIT's Center For Bits and Atoms and based on MIT's rapid prototyping course, MAS 863: How to Make (Almost) Anything. The Fab Academy began as an outreach project from the CBA, and has since spread to Fab Labsaround the world. The program provides advanced digital fabrication instruction for students through an unique, hands-on curriculum and access to technological tools and resources.
Fab Lab Tainan was founded at Dec. 2013 at Tainan, Taiwan. It is the first Fab Lab at Southern Taiwan. Supported by Tainan City Government, this Lab hope could open for local citizen. The background photo of web page is the roundabout in front of Tainan train station.
I'm Jia-Hao Chang from Fablab Tainan.I'm senior staff of Association of Digital Culture, Taiwan (ADCT).In this years, I have participated the project of digital curriculum.My career is to empower people employing digital manufacturing technology or tools toimprove their problem.