In dem Sketch Arduino Ky 040 auslesen ist die Code Zeile (d=c^d);. Was sagt diese Zeile?
1 | int clock = 2; // Define encoder pin A |
2 | int data = 3; // Define encoder pin B |
3 | int count = 0; // pre-init the count to zero |
4 | int c = LOW; // pre-init the state of pin A low |
5 | int cLast = LOW; // and make its last val the same - ie no change |
6 | int d = LOW; // and make the data val low as well |
7 | |
8 | void setup() { |
9 | pinMode (clock,INPUT); // setup the pins as inputs |
10 | pinMode (data,INPUT); |
11 | Serial.begin (9600); // and give some serial debugging |
12 | }
|
13 | |
14 | void loop() { |
15 | c = digitalRead(clock); // read pin A as clock |
16 | d = digitalRead(data); // read pin B as data |
17 | |
18 | if (c != cLast) { // clock pin has changed value... now we can do stuff |
19 | d = c^d; // work out direction using an XOR |
20 | if ( d ) { |
21 | count--; // non-zero is Anti-clockwise |
22 | }else{ |
23 | count++; // zero is therefore anti-clockwise |
24 | }
|
25 | Serial.print ("Jog:: count:"); |
26 | Serial.println(count); |
27 | cLast = c; // store current clock state for next pass |
28 | }
|
29 | }
|