def play(): GPIO.output(api.PROGRAM_BUZZER_ID, True) time.sleep(0.3) GPIO.output(api.PROGRAM_BUZZER_ID, False) GPIO.output(api.RED_LED_ID, False) GPIO.output(api.GREEN_LED_ID, True) f = open("instructions.json", "r") json_dict = json.loads(f.read()) f.close() instructions = api.json_dict_to_instruction_list(json_dict) instruction_counter = 0 while instruction_counter < len(instructions.main_list): instruction_id = instructions.main_list[instruction_counter] print instruction_id, instruction_counter if instruction_id == api.GOTO_START: if GPIO.input(api.PROGRAM_SWITCH_ID): break instruction_counter = 0 continue elif instruction_id == api.DONE: break interrupt = api.do_instruction(instruction_id) if interrupt == api.GO_BUTTON_INTERRUPT: # Restart Program instruction_counter = 0 continue elif interrupt == api.SWITCH_STATE_INTERRUPT: # Switch state break elif interrupt == api.LEFT_BUMPER_INTERRUPT and instructions.left_bumper is not None: bumper(instructions.left_bumper) elif interrupt == api.RIGHT_BUMPER_INTERRUPT and instructions.right_bumper is not None: bumper(instructions.right_bumper) else: instruction_counter += 1 while True: if (GPIO.input(api.GO_BUTTON_ID)) or (GPIO.input(api.PROGRAM_SWITCH_ID)): break
__author__ = 'ben' import api import InstructionList import json instructions = InstructionList.InstructionList() instructions.append_instruction(api.MOVE_FORWARD) instructions.append_instruction(api.LEFT_BUMPER_START) instructions.append_instruction(api.MOVE_BACKWARDS) instructions.append_instruction(api.PIVOT_RIGHT) instructions.append_instruction(api.LEFT_BUMPER_END) instructions.append_instruction(api.BEEP) instructions.append_instruction(api.RIGHT_BUMPER_START) instructions.append_instruction(api.DONE) instructions.append_instruction(api.RIGHT_BUMPER_END) instructions.append_instruction(api.GOTO_START) f = open('test_json.json', 'w') json_string = api.instruction_list_to_json(instructions) f.write(json_string) f.close() api.json_dict_to_instruction_list(json.loads(json_string))