Как считать сигналы с энкодера на arduino

Тема в разделе "Глядите, что я сделал", создана пользователем aptem, 3 апр 2016.

  1. aptem

    aptem Нуб

    Как сделать так, чтобы если до единицы была единица, то Х не плюсуется, а если ноль был до единицы, то
    Х+1 ?
    Как складывать сигналы?
    Написал вот такой скейтч:
    int enk = 5;
    int x;
    void setup() {
    Serial.begin(9600);
    pinMode (enk, INPUT);
    }
    void loop() {
    if (digitalRead(enk) == HIGH)
    {(x = x +1) ;
    }
    Serial.println (digitalRead(enk));
    Serial.println (x);
    delay(500);
    }
     
    Последнее редактирование: 3 апр 2016
  2. Tomasina

    Tomasina Сушитель лампочек Модератор

  3. aptem

    aptem Нуб

    Попробовал скейтч с того сайта чет у меня не выходит как хотелось
    не складывает сигналы
    Вот добавил туда (Х ) тож самое что и у меня в скейтче получается
    #include <Encoder.h>

    // Change these pin numbers to the pins connected to your encoder.
    // Best Performance: both pins have interrupt capability
    // Good Performance: only the first pin has interrupt capability
    // Low Performance: neither pin has interrupt capability
    Encoder knobLeft(5, 6);
    Encoder knobRight(7, 8);
    int x;

    // avoid using pins with LEDs attached

    void setup() {
    Serial.begin(9600);
    Serial.println("TwoKnobs Encoder Test:");
    }

    long positionLeft = -999;
    long positionRight = -999;

    void loop() {
    long newLeft, newRight;
    newLeft = knobLeft.read();
    newRight = knobRight.read();
    if (newLeft != positionLeft || newRight != positionRight) {
    Serial.print("Left = ");
    Serial.print(newLeft);
    Serial.print(", Right = ");
    Serial.print(newRight);
    Serial.println();
    positionLeft = newLeft;
    positionRight = newRight;
    }
    // if a character is sent from the serial monitor,
    // reset both back to zero.
    if (Serial.available()) {
    Serial.read();
    Serial.println("Reset both knobs to zero");
    knobLeft.write(0);
    knobRight.write(0);
    }
    x = x + newLeft;
    Serial.println (x);
    delay (500);
    }
     
  4. 9xA59kK

    9xA59kK Гик

    Скачай архив с примерами по ссылке от Tomasina, открой пример "NoInterrupts" и сним потренеруйся.