After finishing a morning visit in Senegal that highlighted food-security initiatives. President Obama later Friday heads to South Africa, a nation transfixed on the ailing icon Nelson Mandela.

The White House planned the trip long before Mandela’s health took a turn for the worse, and they wanted Obama to showcase the country’s democratic reforms and encourage U.S. businesses to invest in the largest economy on the continent and the 28th largest in the world.

The first black U.S. president’s first trip to South Africa during his presidency carries with it an undeniable poignancy, but it comes at a difficult time for the country – when all eyes will be on their own first black president, the ailing and beloved former leader Nelson Mandela, who turns 95 next month.

The icon of the anti-apartheid movement has been in the hospital 20 days with a lung infection, and although his health has stabilized over the last few days, he is still on life support and in critical condition.

With Mandela’s life hanging in the balance, Obama’s plans are in flux as he and his aides try to strike the appropriate balance in paying homage to man fondly known by his countrymen as Madiba, a personal hero of Obama’s, and moving forward with the original itinerary.

“When we’re there we’ll gauge the situation,” Obama told reporters traveling to South Africa with him on Air Force One Friday. “I think the main message we’ll want to deliver , if not directly to him, to his family, is simply our profound gratitude for his leadership all these years and that the thoughts and prayers of the American people are with him, his family, and his country.”

“In that sense, the sentiment of Americans is universally shared around the world,” he added.

Instead of overshadowing the trip, White House aides said Mandela’s failing health would provide an opportunity for Obama to devote a major portion of his time in Africa to upholding his life as an example to follow.

“The president will be speaking to the legacy of Nelson Mandela and that will be a significant pat of our time in South Africa,” said deputy national security advisor Ben Rhodes before Obama left Washington for Africa. “The president will treasure any opportunity he has to celebrate that legacy.”

Obama’s Sunday visit to Mandela’s former jail cell on Robben Island off of Capetown where the South Africa leader spent 18 of the 27 years in prison before the fall of apartheid, will take on extra “profundity,” Rhodes added. In Dakar, Senegal Thursday Obama acknowledged that the world is focused on Mandela right now. “If and when he passes from this place, one thing I think we’ll all know is that his legacy is one that will linger on through the ages,” Obama said.

The two only met once during a brief gathering in Washington when Obama was a senator, and aides say he will be in constant touch with Mandela’s family while in-country to determine the best way to pay tribute to him.

“We’ll see what the situation is when we land,” Obama said. “I don’t need a photo-op, and the last thing I want to do is to be in any way obtrusive at a time when the family is concerned about Nelson Mandela’s condition,” he said. “…Right now, our main concern is with his wellbeing, his comfort, and with the family’s well being and comfort,” he continued.

During his press conference Thursday, Obama said Mandela’s anti-apartheid movement inspired his first act of political activism, a pivotal life moment Obama recalled in his forward to Mandela’s book, “Conversations with Myself.” “His sacrifice was so great that it called upon people everywhere to do what they could on behalf of human progress,” he said. “In the most modest of ways, I was one of those people who tried to answer his call.” Since retiring from public life, Mandela has spent his time campaigning for several of his charities, fighting the scourge of HIV-AIDS and working to alleviate poverty and hunger.

President George W. Bush made fighting AIDS in Africa a major priority, dedicating $5 billion, an historic initiative that is credited with saving tens of millions of lives. Although less high-profile, Obama has tried to continue that humanitarian legacy, launching his own anti-hunger campaign in 2010. Feed the Future is a $3.5 billion program aimed at helping third-world countries fight hunger and poor nutrition by developing local agriculture sectors.

During a food-security event in Senegal, Obama said the program has helped move 12 million children out of poverty. At booths set up in the back of the hotel where Obama was staying, the president spent Friday morning meeting with farmers, agricultural innovators and entrepreneurs who are developing new methods and fortified food technologies used throughout West Africa. Farmers at the event showed the president fortified sweet potatoes and new technology that allows them to thresh rice millet at a much faster pace.

While looking at some plants at one booth set up the event, Obama joked: “We call those black-eyed peas.” At a rice-milling booth, Anna Gaye demonstrated the old way of milling rice, pounding a long wooden tool into rice in a large pot. She slammed the tool down with great force — and noise — as Obama watched.

Now she has a machine that does the job much more efficiently. “So this means you can take this straight to market because you’re doing it much faster,” Obama said. After touring the marketplace, Obama spoke for a few minutes, touting the success of the program and the effort to lift 50 million people from poverty within a decade. “I’m confident we’re on our way,” he said.

In Africa incomes are rising, poverty is declining, but too many people still are hungry, he said. Obama said he has made food security a priority, and by starting with small farmers, “it’s not just a few who are benefiting from development, but everybody’s benefiting.”

The administration has leveraged both private and public funds, he said, and “as a consequence, we’re getting much better bang for our buck.”

“We know this works.”