It sounds like the best course of action is to just have an attorney present if a situation like this happens again. You knew you were being detained, no matter what the authorities said. As far as I know, there are no provisions anywhere that forbid you from having a lawyer present when and wherever you want.
I often see "have an attorney present" arguments, but they make me wonder - can you really afford to have an attorney on retainer if you're not independently wealthy? Or is it as simple as calling a plumber and asking them to come over?
Should I shop for an attorney and keep their contact information with me just in case I might need one?
Will the attorney be willing to come over at a moment's notice if I've never used their services before?
I suspect it is like any market. Some will be there within the hour, some will need ramp-up time. However, regardless of the attorney, I would suspect that any criminal defense lawyer would be able to effectively navigate the particular situation at hand. If it were me, I would tell them they can arrest me and charge me, or let me on my way. I would be shocked if the results of this finicky machine are admissible in court (given that polygraph results are not). Does anyone know whether or not that is the case?