اطلاعیه

Collapse
No announcement yet.

صفر شدن روتاری

Collapse
X
 
  • فیلتر
  • زمان
  • Show
Clear All
new posts

    صفر شدن روتاری

    سلام تو برنامه زیر هر موقع روتاری بچرخه عدد از صفر تا صد به پورت سریال ارسال میشه کسی میتونه کمک کنه برنامه طوری تغییر کنه که هرموقع روتاری نمیچرخه صفر به پورت سریال ارسال شه مثلا هر یک ثانیه یکبار؟

    int reading = 0;
    int lowest = -100;
    int highest = 100;
    int changeamnt = 1;
    unsigned long currentTime;
    unsigned long lastTime;
    const int pinA = 3;
    const int pinB = 2;
    boolean encA;
    boolean encB;
    boolean lastA = false;
    void setup() {
    pinMode(pinA, INPUT_PULLUP);
    pinMode(pinB, INPUT_PULLUP);
    currentTime = millis();
    lastTime = currentTime;
    Serial.begin(9600);
    }

    void loop() {

    // Read elapsed time
    currentTime = millis();
    // Check if it's time to read
    if(currentTime >= (lastTime + 5))
    {
    // read the two pins
    encA = digitalRead(pinA);
    encB = digitalRead(pinB);

    // check if A has gone from high to low
    if ((!encA) && (lastA))
    {
    // check if B is high
    if (encB)
    {
    // clockwise
    if (reading + changeamnt <= highest)
    {
    reading = reading + changeamnt;
    }
    }
    else
    {
    // anti-clockwise
    if (reading - changeamnt >= lowest)
    {
    reading = reading - changeamnt;
    }

    }
    Serial.println(reading);

    }
    lastA = encA;
    lastTime = currentTime;
    }
    }
لطفا صبر کنید...
X