跳到主要內容

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]);
            }
        }
    }
}









留言

這個網誌中的熱門文章

小蟻智慧攝影機支援RTSP

來源: http://en.miui.com/thread-196713-1-1.html 小蟻智慧攝影機版本: 1.8.5.1l_201511061661(台灣版) 下載檔案 https://drive.google.com/file/d/0ByjBix7wpeJJY0ZWZXlvWl9Za1E/view?usp=sharing 把攝影機SD卡拿讀卡機讀取 把壓縮檔內的test資料夾放進SD根目錄 插回SD卡至攝影機 重開 攝影機會呈現橘燈並執行更新 等恢復至藍燈或是用app確認攝影機開啟 用VLC或相關程式讀取串流 Main stream:rtsp:// <CameraIP> :554/ch0_0.h264 Minor stream:rtsp:// <CameraIP> :554/ch0_1.h264 Audio stream:rtsp:// <CameraIP> :554/ch0_3.h264 Telnet與FTP開啟加上 # Telnet if [ ! -f "/etc/init.d/S88telnet" ]; then     echo "#!/bin/sh" > /etc/init.d/S88telnet     echo "telnetd &" >> /etc/init.d/S88telnet     chmod 755 /etc/init.d/S88telnet fi # FTP echo "#!/bin/sh" > /etc/init.d/S89ftp echo "tcpsvd -vE 0.0.0.0 21 ftpd -w / &" >> /etc/init.d/S89ftp chmod 755 /etc/init.d/S89ftp User:  root Password:  1234qwer 使用passwd改密碼 參考: http://en.miui.com/thread-224653-1-1.html

V-USB Joystick for Arduino

上次做好沒存檔 這次再翻出來從弄一次...QAQ 花了我一天阿阿阿阿 D+ 接腳2 D-  接腳3 詳情請看usbconfig.h 想改搖桿配置可以用 HID Descriptor Tool 改完記得回usbconfig.h填 USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 長度 程式碼: https://www.dropbox.com/s/n0rgkb370wto2lv/UsbJOY.rar?dl=0

Arduino Web Server DECodeURI

1. 架設一個簡單Web Server,以GET方式傳值發現傳入中文字收到的東西變得很不正常 原因是以GET傳值會進行ENCodeURI, 如 : http://192.168.137.177/?test= 送出 ENCodeURI : http://192.168.137.177/?test=%E9%80%81%E5%87%BA 2. 而 unicode utf-8是一種針對Unicode的可變長度字元編碼 在中文文字使用 3byte 表示 以 ” 送 ” 的 16 進位表示為 ” E9 80 81” 以 ” 出 ” 的 16 進位表示為 ” E5 87 BA” URL 編碼會把一個字元以 16 進制表示轉成兩個字元,然後在其前面放置轉義字元 ("%") ,編碼完後 ” 送 ” 為 ” %E9%80%81” 、 " 出 ” 為 %E5%87%BA 。 3. 把 ’%’ 去除並 把兩個 ASCII 字元為一組如 ”E9”, 轉換成一個以 16 進位 表示 E9一個 字元。 ASCII 的 ’A’ 為 65 , 16 進位 A 為 10 , ASCII 的 ’0’ 為 48 , 16 進位 0 為 0 , 當讀到大寫英文字母進行數字計算以 ’A’ 為首減掉 ’A’ 的 65 加 10 ,讀到數字以 ’0’ 為首減掉 ’0’ 的 48 即可轉換成 16 進位表示。 因為兩個字元為一組把先讀到的字元轉成 16 進位做左移 4BIT 即乘於 16 ,與下一個字元轉成 16 進位相加,組合出一個 byte 存入字串內。 String newstring; for(int i=0;i<outputString.length();i++) { if(outputString[i]=='%') { int temp; char tempchar=0; int test=16; for(int j=1;j<3;j++) { if(outputString[i+j]>='A') { temp=(int)(outputString...