跳到主要內容

k-shoot mania 旋鈕 第二戰


 題外話...

 用寶特瓶做的小馬達固定架!!
大小剛好呢~
旋鈕也從寶特瓶蓋換成了鋁製旋鈕~


可是洞好像有點大ˊˇˋ....
讓我探討可變電阻與小馬達結合的可能性.....
才能塞進特別買的鋁製殼..

失敗了呢........(哭
以上屍體



1.
為了讓可變電阻有點貢獻
就用可變電阻做做看旋鈕好了

解除封印!!
只要打掉外面凹槽就可以讓可變電阻無限旋轉~!!!
其實裡面在旋轉時有塊塑膠突出物會卡到凹槽,就不能轉了
要馬幹掉塑膠,不然就把凹槽弄掉
然後寫段簡單的程式碼
const int analogInPin = A0;
int sensorValue = 0;
int oldval = 0;
int count = 0;
void setup() {

    Serial.begin(9600);
}

void loop() {

    sensorValue = analogRead(analogInPin);
    int outputValue = map(sensorValue, 0, 1023, 0, 255);

    int type = oldval - outputValue;
    if (abs(type) > 240) {
        oldval = outputValue;
        if (type < 0) {
            count++;
        } else {
            count--;
        }
        Serial.print(" outputValue: = ");
        Serial.print(outputValue);
        Serial.print("   val: = ");
        Serial.println(count);
    } else if (abs(type) > 5) {

        oldval = outputValue;

        if (type > 0) {
            count++;
        } else {
            count--;
        }

        Serial.print(" outputValue: = ");
        Serial.print(outputValue);
        Serial.print("   val: = ");
        Serial.println(count);

    }
    delay(10);
}


電路






結果






大部分沒問題
只不過0跳到255 這區間旋鈕要轉一小段才會出現變化
就是紅色區域範圍

簡單來說就是失敗了惹~
不在意那小區塊的倒是可以試試

留言