When using a Port as input it is floating.
So You have to take it to a allowed Logic Level.
When using a Switch, You should use a pullup Resistor from +5V to the input Pin.
Then connect the Switch to the Pin and GND.
When the Switch is open, the Controller "see" a logic high Level, when closed a logic low Level will be seen.
The ATMEGA serias has integrated Pullups, they can be activated by setting the according PORTx to 1.
To readout the input Level, You have to read the PINx Register.
The AVR Assembler supports single input readouts.
Some "C" Compilers use the Syntax PINx.0, while x ist the Port e.g. B and 0 can be 0...7 for the whished Port.
When Your compile is not such one, You have to figure out the Port with logical commands like
PINB & 0b00000001
For example
if(PINB.0 == 0)
{
PORTD.0=0; //Switch on PORTD.0 = low LED get Current
}
else
{
PORTD.0=1;
}
That should work without any problem.
To measure some pulses, You could use the Input Capture function.
You have to configure a timer to count.
When the level on the according ICP Pin changed the actual Counter Result will be written to the input capture register.
You can read out it an get a very precise result.
To get a longer counting period I'll suggest You to use a Timer Overflow Interrupt to count up an external variable.
To use that function properly, You shoud get more experience by using Interrupts.