Go Down

Topic: writing digitalread states as bits (Read 784 times) previous topic - next topic

robse

Hi,

I just want to print to the serial every digitalread bit I catch.

How to do that ? How to use a buffer to do that ?

Thanks

PaulS

Quote
I just want to print to the serial every digitalread bit I catch.

How to do that ?

Code: [Select]
int digitalReadBit = digitalRead(theRightPin);
Serial.print(digitalReadBit);


Quote
How to use a buffer to do that ?

Code: [Select]
int buffer[1];
buffer[0] = digitalRead(theRightPin);
Serial.print(buffer[0]);

Though why you want to use a buffer is a mystery.

robse

that way i would print on the serial a bit as a byte.

Am I wrong ? I want raw bits

PaulS

Quote
Am I wrong ? I want raw bits

Well, don't cook them.

What do you mean? The digitalRead() function returns an int, whose values are either 0 or 1. That looks like bits to me.


robse

if you Serial.print(0) it should give 00110000, not 00000000

instead I want:

byte = read_8_bits()
Serial.print(byte)


Go Up