# Attiny85 digital input (read faster - direct)

I am trying to read a clocked signal via pin change interrupt (clock on PB2 - Int0) and read the data on PB1 or (d1 Arduino pin) The "digitalRead(buttonPin)" looks to be too slow. I am trying to do a more direct approach. What would be the correct way to do this? Is "PINB & _BV(PB1)" the correct way to do this?

DaOne:
I am trying to read a clocked signal via pin change interrupt (clock on PB2 - Int0) and read the data on PB1 or (d1 Arduino pin) The “digitalRead(buttonPin)” looks to be too slow. I am trying to do a more direct approach. What would be the correct way to do this? Is “PINB & _BV(PB1)” the correct way to do this?

‘PINB & 2’ will work. If there’s a define for PB1, what you wrote will work. I forget if is defined as 1 as it would have to be for that too work ( _BV(x) is just 1<<x )

That will give you 2 if the pin is high, 0 if not. (So you can’t compare to HIGH but you can use it add the test (ie, if (PINB&2) will run if that pin reads high, but if ((PINB&2)==HIGH) won’t.

I am trying to build a string of 1s and 0s based on the the state of the data input pin when the clock falls.

So does this look correct?

mySensVals[countClock] = (PINB&2);

Actually from the looks of it the interrupt is on PB2. I would like to use PB1 (pin 6 on the micro)

so I wanna replace...

``````mySensVals[countClock] = digitalRead(1);
``````

with

``````mySensVals[countClock] = (PINB&1);
``````

correct?

DaOne: Actually from the looks of it the interrupt is on PB2. I would like to use PB1 (pin 6 on the micro)

``````mySensVals[countClock] = (PINB&1);
``````

correct?

Nope.

PINB&1 looks at bit zero (the ones place), which I'd for PB0. You want to look at bit 1, corresponding to PB1, so PINB&2

I think I understand now. Its always 1 higher than the pin number. So I would be using...

``````mySensVals[countClock] = (PINB&2);
``````