ImadeAnewaccount
ImadeAnewaccount

Reputation: 1

How do I read a byte (8 bit data) sent on one line from a thermometer?

I am converting the 1s and 0s (ups and downs on a pin) into relevant 8 bit data. The pin is expected to have 8 bits sent making a byte from another sort of computer. I am currently working on making a char or array to take the 1s and 0s sent from a pin. I need this so I can transfer this data into something else in the form of number or char I received. A 1 is determined at a certain time and a 0 is determined if no 1 (high pulse) appears.

So far I have tried this:

char data = (0x00);
int valid = 0;
for(int i = 0; i <= 8; i++)
{
 //Add 1 or 0 to array
    while(pin==0)
    {
        delay(5,4);  // 60ns
        data << i = 0; // add 0 to char  
        valid = 1;
    }
    if(valid == 0)
    {
        data << i = 1;  //add 1 to char 
        delay(5,4); // wait for 50 seconds
    }
}

I thought shifting into the char in the binary sense (hexadecimal/binary) I could update the individual 1s and 0s. But I am getting errors saying this isnt a valid solution.

What should I do?

Upvotes: 0

Views: 52

Answers (0)

Related Questions