Noobish question!

Hey,

Im trying to figure out an easy(or complicated.. easy for me to understand)way to decode 6-bit gray code.

however, i have a problem. With the following code, serial monitor gets line 110100, but shouldnt it turn this if-function to true and print "Well done!"?

pls halp!

br,
Newbie

void setup() {
  pinMode(22,INPUT);
  pinMode(24,INPUT);
  pinMode(26,INPUT);
  pinMode(28,INPUT);
  pinMode(30,INPUT);
  pinMode(32,INPUT);

  Serial.begin(9600);
}

void loop() { 
  if((digitalRead(22),1)&(digitalRead(24),1)&(digitalRead(26),0)&(digitalRead(28),1)&(digitalRead(30),0)&(digitalRead(32),0)){
    Serial.print("well done!");
  }
  
  else{
    Serial.print(digitalRead(22));
    Serial.print(digitalRead(24));
    Serial.print(digitalRead(26));
    Serial.print(digitalRead(28));
    Serial.print(digitalRead(30));
    Serial.print(digitalRead(32));
  }
  delay(1000);
}

if((digitalRead(22),1)&What do you think the comma is doing in that expression?

TolpuddleSartre:

if((digitalRead(22),1)&

What do you think the comma is doing in that expression?

ahh....

changed it to

if((digitalRead(22)) == 1 &

and works now.. Feeling quite stupid now :smiley:

thanks!

Also, your use of & means that the whole series of expressions has to be evaluated.

If you had used && instead, any expression not evaluating to true would stop evaluation of the remaining expressions.