/*
GRAY CODE CONVERTER
*/
byte dectoGray(byte value) {
volatile byte encoder = value;
volatile byte rotation bitRead(encoder, 7);
for ( int i = 6; i >= 0; i--) // GRAY to BCD Conversion - Not needed when external decoder used
{
rotation = (rotation << 1) | (bitRead(encoder, i) ^ (rotation & 0x1)); // XOR each bit
}
return rotation;
}
void setup(void) {
Serial.begin(115200);
}
void loop(void) {
for(byte i=0; i < 256; i++) {
Serial.print("Dec ");
Serial.print(i,DEC);
Serial.print(": Gray: ");
Serial.print(dectoGray(i),DEC);
Serial.print(": BIN :");
Serial.println(dectoGray(i),BIN);
}
while(1==1);
}