LINCOLNVILLE, Maine — It was the equivalent of spitting on the American flag.

On a window of a house in Castine, probably sometime in 1814, a British officer took his diamond ring and carved the phrase “Yankee Doodle Topsy Turvy,” along with an image of a British flag over an upside-down U.S. flag.

The graffiti merely illustrated the facts — the fledgling United States was, in 1814, under the heel of the British. The empire’s troops occupied the town, garrisoned in private homes such as the Whitney house, where the window pane was carved.

The house remains on the town’s village green, but the window was removed in the early 1980s.

British ships dominated Penobscot Bay and much of the coast of Maine during the latter part of the war.

As Americans mark the 200th anniversary this year of the War of 1812, they can understand how the conflict played out in human-scale drama in the midcoast and Down East regions, according to Joshua Smith, a professor at the United States Merchant Marine Academy in Kings Point, N.Y.

Remembering the War of 1812 may not inspire much celebration. The U.S. essentially lost the war, Smith said.

“Bangor and Hampden were sacked rather ruthlessly by British forces,” he noted. “The nation’s economy had entirely collapsed, and British troops had put the federal capital to the torch.”

Britain signed a peace treaty only after bigger problems emerged on the European continent as Napoleon began invading neighboring countries.

Napoleon is known around the world, but most in Maine’s midcoast don’t know about characters such as George Ulmer. Ulmer, whose house still stands on a hill in Lincolnville overlooking Route 1 and Ducktrap Harbor, illustrates for Smith both the forces that led to the war and the way it affected the region.

“The whole scale of American history can be found right here in the towns of Northport and Lincolnville,” Smith said in 1999 when presenting some of his doctoral research at a Grange Hall in the area. Since then, Smith has written about the maritime history of the war and soon will publish “Yankee Doodle Upset” about Maine’s part in the War of 1812.

The hostilities between the recent enemies were fanned into flames when the British seized as many as 10,000 Americans and forced them to work on their ships. Even so, loyalties along the coast were divided as late as 1812. Many were either politically sympathetic to the British, Smith said, or pragmatically inclined to keep trading with the enemy to retain their quality of life.

“New Englanders never bought into this war with the British,” he said. “It was bad for trade.” Many Mainers smuggled goods to and from Nova Scotia and New Brunswick, trading with those they saw as cousins, figuratively or literally, Smith said.

Politically powerful New Englanders leaned toward the Federalists, a political party that favored a strong central government and believed society ought to be stratified. Many coastal Mainers did not warm to the ideas of Thomas Jefferson and James Madison, who believed America was a glorious experiment in democracy, favoring the status of the people.

Smith said when the conflict with the British intensified, Tyler Shaw of Northport was paid to carry supplies by boat to American troops in Eastport. Instead, Shaw sailed straight for the British fleet and sold the supplies to the Royal Navy. Federal authorities uncovered his deed and arrested Shaw, who subsequently broke out of federal custody with the aid of several sword-wielding cousins and fled for the safety of Canada, never to return.

But George Ulmer was a patriot, Smith said. Born in Waldoboro, he served in the War of Independence with George Washington at Valley Forge and elsewhere.

After the War of Independence, he settled in Lincolnville and built a dam and mill where the Ducktrap River meets the bay. He became sheriff of Hancock County, which at that time included today’s Waldo County. Smith said Ulmer was known as a soft-hearted sheriff who had the habit of letting prisoners, most of whom were in jail for unpaid debts, escape.

In 1808, Ulmer secured command of the Tenth Division of Massachusetts Militia, based in what today is Hancock, Washington and Penobscot counties. When war broke out with the British in 1812, Ulmer resigned the militia and accepted a federal commission to command a regiment of American volunteers.

Ulmer traveled by horse from Lincolnville during a snowy November, arriving in December 1812 at Fort Sullivan in Eastport. He was in charge of the coast from Castine to Calais, guarding against attacks by the British. But many of those he had recruited left, persuaded by Federalists to abandon the cause, leaving him with older men and young boys, Smith said.

His primary mission was to stop the rampant smuggling, a daunting assignment.

“But he was hampered by orders not to engage the enemy, a terrible shortage of supplies and equipment, officers who bickered and refused to cooperate, the hostility of smugglers and others in the Passamaquoddy region and inadequate housing,” Smith wrote.

Some 80 British subjects living in Eastport weren’t pleased about Ulmer’s presence. He was threatened with tar and feathering, Smith said, probably by those engaged in smuggling.

In a bold move, Ulmer used his soldiers to beat down the doors of homes of those suspected of smuggling in search of contraband. He also made all aliens register and swear an oath of allegiance to the U.S. or leave Eastport within 72 hours.

“Ulmer’s methods were a little severe,” Smith said, yet he was kind, with records showing he left his quarters at midnight during a snowstorm to bring coats to his sentries. Instead of arresting deserters, he pursued them and persuaded them to return to their ranks. He bought food on credit for his starving troops, which later landed him in jail in Machias for failure to pay.

A poison pen campaign was launched against Ulmer, and after he got out of jail on bail he may have begun drinking heavily, Smith said.

“His voluminous correspondence is a litany of complaints,” Smith has written of Ulmer. “Well intentioned but ungifted as a commander, Ulmer’s command devolved into a shambles. In July, 1813 the U.S. Army relieved him of command,” and actually arrested him on charges relating to his poor command.

He later was cleared of almost all charges and traveled to Washington and dined with President James Madison and first lady Dolley.

In June 1814, he returned to Ducktrap. By September, Smith said, “the war comes to him.” Faced with more rampant smuggling, including by his own brother, Ulmer recruited a secret army which included Noah Miller Jr. of Northport.

Shortly after joining Ulmer, Miller encountered two suspicious men and arrested what turned out to be two British spies. Then, taking a rowboat out into the bay, Miller and some of his neighbors encountered a British sloop lost in the fog near the northern tip of Islesboro. By telling the skipper he was a pilot and would guide the vessel to Castine, Miller was able to seize the boat and its cargo, which later was auctioned for $60,000.

When the British wanted Miller hanged as a pirate since he was not acting as part of the U.S. military, Miller went to the Customs House in Belfast and had an agent commission him as a customs official, backdating the document to the day before the seizure. The helpful customs agent received $15,000 from the auction, as did Miller. His neighbors received just $1,000 each, which would prompt them years later to petition Congress for more equitable compensation, Smith said.

Smith said the war affected the course of Maine’s history. The cavalier attitude Massachusetts officials had about the British occupying much of eastern Maine probably spurred the statehood movement, he said. Maine became a state in 1820 and Ulmer became one of the first state senators.

Smith’s research drew on Ulmer’s letters and other documents, which were gathered up as part of a libel lawsuit Ulmer brought against those who wrote against him in Eastport. The letters are in the Maine State Museum Archives in Augusta.

Smith is the author of several books on Maine in the early republic, including “Borderland Smuggling and Battle for the Bay,” which explores naval warfare in the Gulf of Maine during the War of 1812.

“Maine’s small communities have stories to tell that are every bit as fascinating as those found in big cities. Life, death, treason, patriotism — the full range of the human experience can be found anywhere in Maine,” he said. It is just harder to find, especially the sort of stories of smugglers, spies, and traitors that interest me.”