Let's Make Robots!

Binary Number directly from Arduino I/O pins?

Hey guys, I know there has got to be a way to do this, but I can't seem to find it at the Arduino reference page and I don't seem to be using the correct google terms.

I have a 4-bit parallel output from a chip going to 4 digital input pins on an arduino. The chip I am using is putting out a nibble of 4 bits representing a number in binary form. I need the arduino to read the state of these 4 pins and give me a number. I have done this via Picaxe in the past, but I can't seem to find the same thing in Arduino.

There has got to be an easy way of doing this without a lot of bit shifting and or simply assigning values to each input pin and adding them.

Anyone?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Chris the Carpenter's picture

Var = PINB is what I needed my friend, thank you. I'll take all 8 bits, no worries, if all I have to do is shove 'em over or "and" them once, I think I can handle that. 

Groovy groovy.

bdk6's picture

To the best of my knowledge, Arduino supports the entire avr-libc it is based on.  There are a LOT of useful functions there.  Here is the documentation:

http://www.nongnu.org/avr-libc/

 

bdk6's picture

You can read the entire port (8 bits) with something like x = PINB; // for port B, etc  If you only want the bottom 4 bits, mask it with  PINB & 0xF; for example.  If it isn't on the bottom 4 bits, you will have to shift.