Flushing Arduino

This isn't your problem,

  error=0;
if((error==1)||(error==2)||(error==3))

but why bother?

Please use code tags when posting code.
And indentation, I really like good indentation.