Was not declared in scope

int ledpin2 = 12;

You probably meant int ledPin2 = 12; as that is what you called it else where in your sketch. C/C++ is case sensitive.

Lefty