Go Down

Topic: Reading a byte from the digital pins (Read 396 times) previous topic - next topic


Hello everybody,
I am new user of Arduino and I am learning the difference between the old microprocessor 8080 I have used many years ago and this new PIC. In my brain I remember a simple instruction which loads in the ALU (or in the RAM) one byte from the input port and then you can assign this byte as variable. In Arduino I have not found similar instruction, instead it uses a string, sent by serial line. Where is the trick by loading a parallel byte from input digital pins in the ALU?
Thanks in advance, Godifredo

I don't think we do that anymore.  It's all serial these days.


There's a couple ways you can do this.  If you hook up the lines such that all the IO pins you want are on a single 8-bit port, copying the values in PIN[letter] will grab the inputs.  However, the Arduino isn't laid out to make such port manipulation easy.  As such, you probably would want something like this:

Code: [Select]

uint8_t pins[8] = {/* pin numbers */};

// ...

// read in as byte:

byte reading;
for (uint8_t i = 0; i < 8; i++) {
  reading |= digitalRead(pins[i]) << i;

Of course, this is of rather limited utility - it's usually more useful to just read the relevant pins directly.

Go Up