2015年6月1日 星期一

k-shoot mania 旋鈕 可變電阻製作詳細說明

相關連接~
V-USB k-shoot mania controller for Arduino


這次我使用雙連後抽200K可變電阻(這個雙連後抽手感不太好阿QAQ)
因為上次改造時其中一片互換
另一方向外殼沒挖洞會造成接點夾到外殼
為了省麻煩就直接買雙連後抽

 雙連後抽200K可變電阻

接下來進行改造
把紅色圈固定用的東西拆開
從這個方向比較好施工
拆開後比較容易拿尖嘴鉗或剝線鉗進去施工


拿尖嘴鉗或剝線鉗把紅圈地方壓平
並轉轉看會不會被卡到
這樣就完成可變電阻無限旋轉了


再來照電路圖接線



硬體部分OK

Arduino 測試程式

const int analogInPin = A0;
const int analogInPin1 = A1;
void setup() {
  Serial.begin(9600); 
}
void loop() {
  Serial.print("val0 = " );                       
  Serial.print(analogRead(analogInPin));      
  Serial.print("\tval1 = " );                       
  Serial.println(analogRead(analogInPin1));      
  delay(200);                     
}

旋轉可變電阻(用雙連後抽小心別碰到後面的接點會影響數值)
確定旋轉同一方向
兩邊數值同時上升或同時下降
你會發現
當數值0在往下轉時換變成1019(沒到1023可能是1K歐姆電阻分壓到)
0到最大值中間有出現900以上的數值(不確定產生的原因...)


寫個左轉+1 右轉-1的測試程式
濾掉不可靠的區域 0以下 900以上
當其中一片在此區域時不理會他,採另外一片的數值當參考
沒問題的話就已經成功了~

const int analogInPin = A0;
const int analogInPin1 = A1;
int newValue[2]={0,0};
int oldValue[2]={0,0};
int count = 0;
void setup() {
    Serial.begin(9600);
  oldValue[0] = analogRead(analogInPin) ;
  oldValue[1] = analogRead(analogInPin1) ;
}
void loop() {
    newValue[0]=analogRead(analogInPin);
    newValue[1]=analogRead(analogInPin1);
    rotary(oldValue,newValue);

    delay(10);
}
void msg(int outputValue,int outputValue1) {
    Serial.print(" outputValue: = ");
    Serial.print(outputValue);
    Serial.print("\tval: = ");
    Serial.print("\toutputValue1: = ");
    Serial.print(outputValue1);
    Serial.print("\tval: = ");
    Serial.println(count);
}
int rotary(int oldval[2],int newval[2])
{
    int type = oldval[0] - newval[0];
    int type1 = oldval[1] - newval[1];

    if (newval[0] > 900 || newval[0] < 1) {
        if (abs(type1) > 20) {
            oldval[0] = newval[0];
            oldval[1] = newval[1];
            if (type1 < 0) {
                count++;
                msg(newval[0],newval[1]);
            } else {
                count--;
                msg(newval[0],newval[1]);
            }
        }
    } else if (newval[1] > 900 || newval[1] < 1) {
        if (abs(type) > 20) {
            oldval[0] = newval[0];
            oldval[1] = newval[1];
            if (type < 0) {
                count++;
                msg(newval[0],newval[1]);
            } else {
                count--;
                msg(newval[0],newval[1]);
            }
        }
    } else {
        if (abs(type) > 10 && abs(type1) > 10) {
            oldval[0] = newval[0];
            oldval[1] = newval[1];
            if (type < 0 && type1 < 0) {
                count++;
                msg(newval[0],newval[1]);
            } else if(type > 0 && type1 > 0) {
                count--;
                msg(newval[0],newval[1]);
            }
        }
    }
}









沒有留言:

張貼留言

預測2031/1/1可能 TWCA 憑證 IOS會出現不信任

緣由: TWCA CYBER Root CA 有兩張、兩個效期 (2030、2047年到期) 推測TWCA 預計 2030年12月會停用: TWCA CYBER Root CA (2030 年到期) TWCA Global Root CA 改用啟用: TWCA CYBER ...