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);*
}