Как сделать так, чтобы если до единицы была единица, то Х не плюсуется, а если ноль был до единицы, то Х+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); }
Попробовал скейтч с того сайта чет у меня не выходит как хотелось не складывает сигналы Вот добавил туда (Х ) тож самое что и у меня в скейтче получается #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); }