Synthesis of pi conjugated polymers for use in photovoltaic and electrochromic applications