Alan Burt, also known as Alan Allport, then walked across Lemon Quay in Truro with his penis in full display during the incident that took place on June 25 last year.
The 70-year-old was before Truro Crown Court for sentencing on Friday, having previously pleaded guilty to outraging public decency, criminal damage and possession of cannabis.
The court was told that Burt, from Laburnum Close in Falmouth, had been sat on a bench at Lemon Quay at around 3pm that day.
The area was said to be busy at that time, with lots of people around including children. There was also a market going on at the time, with stalls.
Prosecutor Katie Churcher said: “The defendant was sat with his right hand down his trousers and masturbating.
“Some people saw him then get up and walk along Lemon Quay with his penis in full view of everyone.”
He was arrested and during a search police found cannabis in his pocket.
While in the cell he was given a Bible and a document listing the police procedure, both of which he damaged, leading to the charge of criminal damage.
In interview he denied the exposure, but admitted having cannabis on him, which he said he used for medicinal purposes, for his bipolar disorder. This, it was said, had contributed to the incident.
He admitted damaging the Bible and other literature, saying he was angry about being in custody.
Judge Robert Linford sentenced Burt to a 24-month community order, which included a condition to complete rehabilitation activities.