device that converts mechanical to electrical energy