Pages: [1]   Go Down
Author Topic: Reading a byte from the digital pins  (Read 355 times)
0 Members and 1 Guest are viewing this topic.
Roma
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Seattle, WA
Offline Offline
God Member
*****
Karma: 11
Posts: 673
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 360
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.
Logged

Pages: [1]   Go Up
Jump to: