Trouble in Encoder Town

I’m currently trying to read a gray code sent by an absolute encoder, and i’m using it to covert it to binary and then to decimal, but i got a problem: in order for my converter work, i need to store the gray code in a char array, but for some reason, i can’t. I can’t figure out why, can someone help??

the code:

#include <string.h>
#include <stdlib.h>
#include <math.h>

char ac[2], bits[4];

void setup() {
Serial.begin(9600);
Serial.flush();
pinMode(0, INPUT);
pinMode(1, INPUT);
pinMode(2, INPUT);
pinMode(3, OUTPUT);

}

void loop() {
while(!Serial.available());
Serial.readBytesUntil(’\n’, ac, 2);
if(strcmp(“L”, ac) == 0) //just for test
{
digitalWrite(5, HIGH); // 74LS244 activation
for(int i=0;i<4;i++)
{
bits*=digitalRead(i); //reading the encoder and storing it on an array char*

  • }*
  • }*
  • digitalWrite(5, LOW);*
  • Serial.println(bits);*
    }

Read How to post code properly and then fix up your message so that your code doesn't turn into italics.

Pete

  pinMode(0, INPUT);
  pinMode(1, INPUT);

Why are you diddling with the hardware serial pins?

   for(int i=0;i<4;i++)
    {
      bits[i]=digitalRead(i); //reading the encoder and storing it on an array char
    }

Assuming that the italics were caused by your incorrect posting, this is what the for loop actually looks like. Again, why are you reading the hardware serial pins? You are using Serial, so those pins are NOT available for you to connect your encoder to.