Hello All, I try to read digital Absolute Rotary Encoder with Arduino in SerialMonitor, with this code:
boolean pin_state[10];
byte input_pin[] = {2,3,4,5,6,7,8,9,10,11}; // Config Pins Input Here bit-1 to 10
int dec_position = 0;
boolean a = 0;
void setup() {
Serial.begin(9600);
for(byte i = 0; i <10; i = i +1 ){ // declare pin mode
pinMode(input_pin*, INPUT);*
}
}
void loop() {
Read_input(); // Read Encoder Signal
delay(100);
}
void Read_input(){
- for(byte i = 0; i <10; i = i + 1 ){*
pin_state = !digitalRead(input_pin*); // Bitwise for active LOW*
* }*
* // Gray Code Decoder*
* dec_position = pin_state[9];
_ for( int i = 8; i >= 0; i = i -1){
dec_position = (dec_position << 1) | (pin_state ^ (dec_position&0x1));
}*_
* // Print 0-1023 position with line feed*
* Serial.println(dec_position, DEC);
_}
OUTPUT SERIAL
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
544
599
597
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
341
170
170
170
170
170
170
138
253
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
512
544
607
599
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
682
.....
I want Questions about this output and code Absolute Rotary ENcoder, Thanks for you attention._
*