2012年3月7日 星期三

Case Structure

在這篇我們將介紹 LabVIEW 的 Case Structure。

如果你學過其它程式語言,你可能已經熟悉 If-Then-Else 或 Switch 這些條件結構,這些結構是用來選擇要執行哪一段程式碼,在 LabVIEW 裏要做同樣的事是用叫一個作 Case Structure 的結構。底下我們將說明如何使用 Case Structure。

認識 Case Structure

我們來看底下這支程式:

2012-01-29 15h34_09 

這支程式是一個很簡單的程式,它可以讓使用者利用 Button 來控制 LED 的開關。如下圖左,當 Button 被按下時 LED 燈就會打開;而當你再按一下 Button,LED 燈就會變成關閉的狀態,如下圖右:

2012年3月4日 星期日

For Loop and Shift Regsiter

在這篇,我們將介紹如何利用 LabVIEW 的 For Loop 和 Shift Register 寫一支從 1 加到 10 的程式。

首先,打開 LabVIEW,建立一個 Blank VI,然後在 Block Diagram 上按滑鼠右鍵打開 Functions Palette,接著點選 Structures > For Loop 在 Block Diagram 上拖曳畫出一個 For Loop:

 image_thumb5 

由於我們要計算 1 加到 10 的總合,Loop Count 是 10,所以我們要把 For Loop 的 Loop Count 設定為 10,先在 Count (N) Terminal 上按右鍵,點選 Create Constatn:

2012年3月1日 星期四

Shift Register

這篇我們將介紹 LabVIEW 的 Shift Register。

在 LabVIEW,Shift Register 可以加到 While Loop 和 For Loop 中。Shift Register 提供一個在迴圈迭代 (Loop Iteration) 之間傳遞資料的方法。讓我們從一個簡單的例子來認識 Shift Register。

認識 Shift Register

底下是一個簡單的 While Loop,迴圈裏只有一個 Wait (ms) 等待 1000 ms 的 function:

2012-01-29 01h03_25 2012-01-29 01h03_55

要建立 Shift Register,方法是在 Loop 的邊框上按右鍵,然後點選 Add Shift Register: