What was Scott Key doing when he wrote the Star Spangled Banner?

He was on a ship watching the explosions and fireworks