dscratchgpio refactored with all main code at end