Answer the question
In order to leave comments, you need to log in
How to convert 4 bit Gray code to binary in Arduino?
Hello
There is a code found on the Internet:
boolean A, B, C, D, S0, S1, S2, S3;
void setup ()
{
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(5, INPUT);
Serial.begin(9600);
}
void loop()
{
A=digitalRead(2);
B=digitalRead(3);
C=digitalRead(4);
D=digitalRead(5);
S0=A;
S1=(!A&&B)||(A&&!B);
S2=(!B&&C)||(B&&!C);
S3=(!C&&D)||(C&&!D);
Serial.print("Grey:");
Serial.print(S0);
Serial.print(S1);
Serial.print(S2);
Serial.println(S3);
Serial.print("Bin:");
Serial.print(A);
Serial.print(B);
Serial.print(C);
Serial.println(D);
delay(1000);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question