問題:
新買的 Arch Pro 在 OS X(Mac) 出現 「OS X 無法修復磁碟 MBED」的錯誤,或者找不到 mbed 資料夾。
解決方法:
請使用 Windows 電腦(非 VM),並至官網 wiki 下載更新檔,依照日期更新(將檔案丟至 Arch Pro 磁碟)即可解決。
Blog for Coding Learner
Mango Lai's learning notes.
2015年4月14日 星期二
2015年2月10日 星期二
[ARM mbed] 控制RGB LED
RGB LED 原理是將三原色的 LED 封裝在同一個 LED 內,利用三原色的混色達到顯示各色的效果。本文使用的 RGB LED 為此。
圖 1 Chainable RGB LED
一、腳位接法
| RGB LED pin | Mbed pin |
|---|---|
| 1 - RX | P14 - RX |
| 2 - TX | P13 - TX |
| 3 - Vcc | Vout - 3.3V |
| 4 - GND | GND |
圖 2 RGB LED 腳位接法
備註:ARM Mbed 腳位只要是 RX 及 TX 即可,以 LPC1768 為例:P10 & P9、P27 & P28 也可使用。
二、函式庫介面
class ChainableLED {
public:
ChainableLED(byte clk_pin, byte data_pin, byte number_of_leds);
void setColorRGB(byte led, byte red, byte green, byte blue);
void setColorHSB(byte led, float hue, float saturation, float brightness);
}
三、程式碼
開始撰寫 ARM mbed 程式碼。首先,必須引入 mbed.h 及 ChainableLED.h 標頭檔,接著將連接腳位。並且我們利用 wait 函數使 RGB LED 隨時間產生變化。
Github 連結請按此。
Github 連結請按此。
#include "mbed.h"
#include "ChainableLED.h"
// ChainableLED(clk, data, number_of_leds)
ChainableLED color_led(p14, p13, 1);
int main() {
uint8_t value = 0;
while(1) {
value++;
// ChainableLED.setColorRGB(index_of_led, red, green, blue)
color_led.setColorRGB(0, value, 255 - value, value + 80);
wait_ms(10);
}
}
Reference
2015年2月9日 星期一
[ARM mbed]控制直流有刷馬達
直流有刷馬達好處在為控制速度方面比較簡單,可以在不受電源頻率的限制下,使用電壓大小控制轉速。而本篇即要透過此方法展示使用 PwmOut 來控制直流有刷馬達。本文使用的馬達為此。
一、控制電路
圖 1 馬達控制電路
依照此電路圖可以選擇自己手焊或者使用 Mini Fan 電路板來連接馬達。
圖 2 手焊電路
圖 3 Mini Fan 電路板
二、腳位接法
由於 LPC1768 有電路保護,因此馬達的供應電源需要再額外供應。
| Motor pin | Mbed pin |
|---|---|
| 1 - Pwm | P21 - SCL |
| 3 - Vcc | Vout - 3.3V |
| 4 - GND | GND |
三、程式碼
開始撰寫 ARM mbed 程式碼。首先,必須引入 mbed.h 標頭檔,接著將連接腳位 (這邊要特別注意馬達的腳位宣告要使用 PwmOut)。並且我們利用 LED 燈來表示轉速的變化。
Github 連結請按此。
Github 連結請按此。
#include "mbed.h"
DigitalOut ledForPower1(LED1);
DigitalOut ledForPower2(LED2);
DigitalOut ledForPower3(LED3);
DigitalOut ledForPower4(LED4);
PwmOut motor(p21);
int main() {
motor=0;
wait(2);
motor=0.4;
ledForPower1=1;
wait(2);
motor=0.6;
ledForPower2=1;
wait(2);
motor=0.8;
ledForPower3=1;
wait(2);
motor=1;
ledForPower4=1;
}
Reference
2015年2月8日 星期日
[ARM mbed]三軸加速感應器
三軸加速度感測器的可以在預先不知道物體運動方向的情況下,應用各個維度的加速度感測器來檢測加速度資訊。三維加速度感測器具有體積小和輕量的特點,可以測量空間加速度,並且能夠全面準確反映物體的運動情形。本文使用的三軸加速感測器為此。
一、腳位接法
圖2 腳位接法範例圖
備註:ARM mbed 腳位只要是 SCL 及 SDA 即可,以 LPC1768 為例:P9、P10 也可使用。
二、數據解析
感測器本身會會回傳 0~63 的結果,我們可以透過此結果依表轉換成 G 值(1g=m/s^2)或者角度(不建議使用),詳細對照表可參照此文件 P.26~P.27。
圖3 數據解析對照表
三、程式碼
開始撰寫 ARM mbed 程式碼。首先,必須引入 mbed.h 及 MMA7660FC.h 標頭檔,接著將連接腳位。並且我們利用 LED 燈來顯示感測器的變化。
程式碼如下:
#include "mbed.h"
#include "MMA7660FC.h"
DigitalOut myled1(LED1);
DigitalOut myled2(LED2);
DigitalOut myled3(LED3);
DigitalOut myled4(LED4);
#define ADDR_MMA7660 0x98 // I2C SLAVE ADDR MMA7660FC
MMA7660FC Acc(p28, p27, ADDR_MMA7660); //sda、cl、Addr,更換接角時請務必更改此處
Serial pc(USBTX, USBRX);
// G值對照表
float G_VALUE[64] = {0, 0.047, 0.094, 0.141, 0.188, 0.234, 0.281, 0.328, 0.375, 0.422, 0.469, 0.516, 0.563, 0.609, 0.656, 0.703, 0.750, 0.797, 0.844, 0.891, 0.938, 0.984, 1.031, 1.078, 1.125, 1.172, 1.219, 1.266, 1.313, 1.359, 1.406, 1.453, -1.500, -1.453, -1.406, -1.359, -1.313, -1.266, -1.219, -1.172, -1.125, -1.078, -1.031, -0.984, -0.938, -0.891, -0.844, -0.797, -0.750, -0.703, -0.656, -0.609, -0.563, -0.516, -0.469, -0.422, -0.375, -0.328, -0.281, -0.234, -0.188, -0.141, -0.094, -0.047};
int main()
{
Acc.init(); // Initialization
pc.printf("Value reg 0x06: %#x\n", Acc.read_reg(0x06)); // Test the correct value of the register 0x06
pc.printf("Value reg 0x08: %#x\n", Acc.read_reg(0x08)); // Test the correct value of the register 0x08
pc.printf("Value reg 0x07: %#x\n\r", Acc.read_reg(0x07)); // Test the correct value of the register 0x07
while(1)
{
myled4=1;
float x=0, y=0, z=0;
float ax=0, ay=0, az=0;
Acc.read_Tilt(&x, &y, &z); // Read the acceleration
pc.printf("Tilt x: %2.2f degree \n", x); // Print the tilt orientation of the X axis
pc.printf("Tilt y: %2.2f degree \n", y); // Print the tilt orientation of the Y axis
pc.printf("Tilt z: %2.2f degree \n", z); // Print the tilt orientation of the Z axis
wait_ms(100);
pc.printf("x: %1.3f g \n", G_VALUE[Acc.read_x()]); // Print the X axis acceleration
pc.printf("y: %1.3f g \n", G_VALUE[Acc.read_y()]); // Print the Y axis acceleration
pc.printf("z: %1.3f g \n", G_VALUE[Acc.read_z()]); // Print the Z axis acceleration
pc.printf("\n");
//換算成 G值
ax = G_VALUE[Acc.read_x()];
ay = G_VALUE[Acc.read_y()];
az = G_VALUE[Acc.read_z()];
//用 LED簡單展示數值變化
if(ax<0 data-blogger-escaped-ay="" data-blogger-escaped-az="" data-blogger-escaped-else="" data-blogger-escaped-if="" data-blogger-escaped-myled1="0;" data-blogger-escaped-myled2="0;" data-blogger-escaped-myled3="0;" data-blogger-escaped-pre="" data-blogger-escaped-wait="">
Reference
2014年8月20日 星期三
[WS2012] 關於 Windows Server 2012的一些筆記
一、Active Directory 是甚麼?(引用自Wiki)
Active Directory是微軟 Windows Server 中,負責架構中大型網路環境的集中式目錄管理服務(Directory Services),在 Windows 2000 Server 開始內建於 Windows Server 產品中,它處理了在組織中的網路物件,物件可以是使用者,群組,電腦,網域名稱控制站,信件,設定檔,組織單元,樹系等等,只要是在 Active Directory 結構定義檔(schema)中定義的物件,就可以儲存在 Active Directory 資料檔中,並利用 Active Directory Service Interface 來存取,實際上,許多 Active Directory 的管理工具都是利用這個介面來呼叫並使用 Active Directory 的資料。
二、Directory System(目錄服務)用途?
- 驗證
- 查詢資訊
三、命名空間(namespace)
- 參考DNS名稱
- 一定要"."
- AD的Domain名稱和註冊上可以不同(運作上絕對不會有問題)
四、在客戶端要如何知道有伺服器?
利用DNS名稱查詢
五、為什麼單位內要有AD?(詳細內容引用自此)
1. 電腦帳號密碼集中伺服器管理,強化電腦安全性。
2. 控管所有電腦內軟體安裝。
3. 方便使用資產管理系統,減少管理時間與成本。
4. 統一由 AD 伺服器派送軟體安裝到電腦。
5. 印表機 統一由 AD 伺服器集中管理。
6. 網路磁碟機集中管理。
7. 網路分享資料夾和電腦資料夾權限控制,增加安全性。
8. 外地分公司統一連線 AD 伺服器集中管理。
2. 控管所有電腦內軟體安裝。
3. 方便使用資產管理系統,減少管理時間與成本。
4. 統一由 AD 伺服器派送軟體安裝到電腦。
5. 印表機 統一由 AD 伺服器集中管理。
6. 網路磁碟機集中管理。
7. 網路分享資料夾和電腦資料夾權限控制,增加安全性。
8. 外地分公司統一連線 AD 伺服器集中管理。
六、為什麼沒有人稱為 AD Server?
沒有 AD Server,只有 DC( Domain Controller) Server。若是稱為 AD Server,別人會以為是擁有AD功能的 Server。
七、AD的驗證過程

八、AD中的 Object是甚麼?
在AD中所有的東西都稱為物件(Object)
- 使用者
- 群組
- 電腦
屬性(Attribute)
- 欄位
- 紀錄
九、Domain Tree
在 AD 中會有數個網域名稱,若需要在網域名稱中共享資料或是做委派管理與組態設定時,便需要建立彼此間的組織關係,微軟將 AD 中多網域名稱相互的關係階層化,稱為網域名稱樹(domain tree),網域名稱樹結構以 DNS 識別方式來區分。

十、Trust(信任)
AD的主要目的是為了達到 Single Sign On,而Trust是希望在多個 Domain之間作 Single Sign On。
十一、AD Forest
AD的範圍,共用相同的Schema
WiKi解釋如下:
在多個網域名稱的環境下,可能在不同的網域名稱之間會需要交換與共享資料,像是組態設定、使用者帳戶與群組原則設定等,在這個時候需要有一個角色來做為不同網域名稱間的資訊交換角色,同時又必須要符合 AD 樹狀結構的規範,因此微軟在多網域名稱之間建立了一個中介用的角色,稱為森林(Forest),一個組織中最多只能有一個 Forest,在 Forest 下則是各自的網域名稱樹系,而在 Forest 下的網域名稱或網域名稱樹系間,可以共享資訊。
十二、DC(網域控制站)
- 一個Domain至少要有兩台DC。並且在AD的環境內,兩台DC都採用雙向複寫,因此經過複寫過後兩邊的結果會相同。
- RODC(Read Only Domain Controller),採用單向複寫(例如:DC1複寫給RODC),無法對RODC作新增、刪除、修改,只負責作驗證的工作,且RODC不需要做備份。需求是給沒有IT人員的分公司,如果RODC壞掉,重灌就好。
十三、其他補充
- 可重新啟用的ADDS:本機的DB SAM停用時,傳統的作法是重新開機然後按F8,選擇DSRM(目錄服務還原模式),然後進行維護,但因為此方法無法作遠端管理。因此從WS2008開始就新增這個功能(可重新啟用的ADDS)。
- 資源回收桶(預設不存在):若不小心把一個物件刪掉,可以從這裡救回來。
- WS2012 R2 分為 Standard與 datacenter(較貴,價錢差四倍)版本,兩者功能相同。兩版本差別在授權,在VM中Standard版本免費授權兩台Guest OS,而 datacenter版本 Guest OS全部免費。
- Guest OS-指在VMware中運作的虛擬電腦作業系統,也就是經由VMware產生的虛擬作業系統。
- AD不穩定通常都是 DNS解析有問題。AD中的電腦,DNS IP只能指向AD中的DNS Server,因為外部不知道內部的AD。客戶端查詢DNS都是使用UDP。
- DNS 客戶端查不到的record會記得在本機的Negative Cache中,因此建議關閉Negative Cache。
- 驗證Negative Cache是否關閉(使用cmd):
ipconfig /flushdns 清除DNS快取ipconfig /displaydns 顯示DNS快取
- 關閉 Negative Cache:
- 打開 regedit。
- HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters。
- 新增DWORD,名稱為MaxNegativeCacheTtl,數值為0。
- 重啟網卡。
2014年7月28日 星期一
[Android]多選一的單選鈕 (RadioButton)
單選按鈕即RadioButton,表示在同一群組內只能選擇一個項目。
RadioButton & RadioGroup元件
要讓一組 RadioButton每次只能有一個被選,就必須把它們都放置在同一個 RadioGroup中。
如上圖所示,其中就有三個 RadioButton,而三個都被包在同一個 RadioGroup(你看不見)中。
getCheckedRadioButtonId():讀取單選鈕狀態
由於 RadioButton通常是組合在 RadioGoup之下,因此在程式中要判斷使用者選擇哪一個 RadioButton,可透過 RadioGrop的 getCheckedRadioButtonId()方法,取得被選取的 RadioButton之資源 ID。接著利用判斷式(例: if/else)就可以據以決定程式的走向,其格式如下:
※讀取RadioGroup的選取項目:
MainActivity.java
備註:別忘了,R.id.XXX都是在 R.java中以 final宣告的常數,其值是固定不變的,因此可用在 switch敘述中用來區別選取的單選鈕。
activity_main.xml
RadioButton & RadioGroup元件
要讓一組 RadioButton每次只能有一個被選,就必須把它們都放置在同一個 RadioGroup中。
如上圖所示,其中就有三個 RadioButton,而三個都被包在同一個 RadioGroup(你看不見)中。
getCheckedRadioButtonId():讀取單選鈕狀態
由於 RadioButton通常是組合在 RadioGoup之下,因此在程式中要判斷使用者選擇哪一個 RadioButton,可透過 RadioGrop的 getCheckedRadioButtonId()方法,取得被選取的 RadioButton之資源 ID。接著利用判斷式(例: if/else)就可以據以決定程式的走向,其格式如下:
//取得 RadioGroup之物件
RadioGroup Iwant = (RadioGroup) findViewById(...);
...
//判斷選擇的項目資源 ID是不是所選擇的該項ID
if(Iwant.getCheckedRadioButtonId() == R.id.takeSword) {
...
}
else if(Iwant.getCheckedRadioButtonId() == R.id.cutSoul){
...
}
else{
...
}
※讀取RadioGroup的選取項目:
package tw.com.Mei_Jiang;
import android.app.Activity;
import android.os.Bundle;
import android.view.*;
import android.widget.*;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void show(View v){
TextView txv=(TextView)findViewById(R.id.txv);
RadioGroup ticketType =
(RadioGroup) findViewById(R.id.ticketType);
// 依選取項目顯示不同訊息
switch(ticketType.getCheckedRadioButtonId()){
case R.id.sword: // 選 拿勝利寶劍
txv.setText("拿勝利寶劍");
break;
case R.id.soul: // 選 斷開魂節
txv.setText("斷開魂節");
break;
case R.id.chain: // 選 斷開鎖練
txv.setText("斷開鎖練");
break;
}
}
}
備註:別忘了,R.id.XXX都是在 R.java中以 final宣告的常數,其值是固定不變的,因此可用在 switch敘述中用來區別選取的單選鈕。
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="@+id/txv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world"
android:textSize="30sp" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/txv"
android:layout_centerHorizontal="true"
android:onClick="show"
android:text="確定" />
<RadioGroup
android:id="@+id/ticketType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button1"
android:layout_centerHorizontal="true" >
<RadioButton
android:id="@+id/sword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="拿勝利寶劍" />
<RadioButton
android:id="@+id/soul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="斷開魂節" />
<RadioButton
android:id="@+id/chain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="斷開鎖練" />
</RadioGroup>
</RelativeLayout>
2014年7月1日 星期二
[Eclipse] 常用快速鍵 及 自動完成( Auto Complete)
一、常用鍵
- 【Ctrl+Shift+O】:自動匯入所需要的類別
- 【Alt + /】:程式碼提示,自動補齊 Template
- 【Ctrl+Shift+F】:程式碼自動排版
- 【Ctrl + F11】:快速執行程式
- 【Ctrl+Shift+P 】:轉至匹配的括號
- 【Ctrl+/】:將選取的文字多行註解起來
- 【Ctrl+D】:刪除當前這一行
- 【Ctrl+F8】:視景切換
二、快速鍵修改處
英文版:Window->Preference->General->Keys
中文版:視窗->喜好設定->一般->按鍵
備註:快捷鍵組合可在Eclipse按下Ctrl+Shift+L來查看。
三、尋找參照
- 【F3】:找變數宣告處
- 【Ctrl+T】:顯示繼承樹
- 【Ctrl+Shift+T】:快速搜尋 Class
- 【Ctrl+滑鼠左鍵點擊】:查看使用類別的原始碼
- 【Ctrl+L】:前往某一行
四、Debug
- 【F11】:以除錯模式啟動 (Debug)
- 【Ctrl + F11 】:啟動 (Run)
- 【F5】: 步進,深入一層 (Step Into)
- 【F6】:步進,往下一行 (Step Over)
- 【F7】: 步進,回上一層 (Step Return)
- 【Ctrl+.】:尋找下一個error位置
- 【Ctrl+,】:尋找前一個error位置
五、JAVA的自動完成( Auto Complete)設定
中文版:視窗 --> 喜好設定 --> Java --> 編輯器 --> 內容輔助 --> Auto Activation
英文版:Window--> Preferences --> Java --> Editor --> Content Assist --> Auto Activation
六、XML的自動完成(Auto Complete)設定
中文版:視窗 --> 喜好設定 --> XML --> XML Files --> 編輯器 --> 內容輔助 --> Auto Activation
英文版:Window --> Preferences --> XML --> XML Files --> Editor --> Content Assist --> Auto Activation
Reference
訂閱:
意見 (Atom)

















