A drugged-up man startled motorists by hanging onto railings and exposing himself on Friday evening near a busy Nottinghamshire town centre.
The incident took place at 5.25pm on May 17 and was described in court where 31-year-old David Parfitt admitted the offence after being shown CCTV footage of his behaviour.
Nottingham magistrates ordered six months of drug treatment for Parfitt of Colston Road, Bulwell. He must pay £170 costs.
The court heard that traffic was at a standstill on Main Street, Bulwell.
A woman and her 10-year-old daughter were in a car in a queue when the woman driver spotted a man.
Sanjay Jerath, prosecuting, said: "As they approached a town centre zebra crossing, she saw a male holding the railings and facing the traffic. His boxer shorts had ridden up."
In a statement to police officers, the woman driver said: "As I passed the crossing, I was so shocked at what I had seen, I could not stop looking back."
She said that her daughter was left crying and confused, adding: "It was a long time before she understood what had happened."
Bill Soughton, mitigating, told the three women JPs: "I have seen the CCTV and don't think you will want to see it.
"He has a serious drug problem. He had smoked some spice which is not something he would normally do. If he is involved in drug use, it is usually mamba.
"In effect, this is drug induced. He is trying to address it but it is not an easy thing to do."
Mr Soughton said that Parfitt co-operated with probation officers in tackling a problem with Class A drugs, the most dangerous category.
He said that the exposure was not deliberate and that Parfitt was not performing a sex act at the time.
Parfitt had never done anything similar, said Mr Soughton, who added: "There is nothing sinister to do with this."
When asked for his plea to the charge of exposure, Parfitt told the magistrates: "I have seen the CCTV evidence. I plead guilty."