Synthesis, Characterization, Optical, Electrochemical, and Theoretical Studies of Substituted Terpyridines